How to use the testtools.matchers.FileContains function in testtools

To help you get started, we’ve selected a few testtools examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github snapcore / snapcraft / tests / unit / test_mangling.py View on Github external
file_path = _create_file(
            "file",
            textwrap.dedent(
                """\
            #!/usr/bin/env python3.5

            '''
            This is a test
            =======================
        """
            ),
        )
        mangling.rewrite_python_shebangs(os.path.dirname(file_path))
        self.assertThat(
            file_path,
            FileContains(
                textwrap.dedent(
                    """\
            #!/usr/bin/env python3.5
github snapcore / snapcraft / integration_tests / test_prime.py View on Github external
def test_prime_with_non_ascii_desktop_file(self):
        # Originally, in this test we forced LC_ALL=C. However, now that we
        # are using the click python library we can't do it because it fails
        # to run any command when the system language is ascii.
        # --20170518 - elopio
        self.run_snapcraft('prime', 'desktop-with-non-ascii')

        desktop_path = os.path.join(
            self.prime_dir, 'meta', 'gui', 'test-app.desktop')

        self.expectThat(
            desktop_path, FileContains(matcher=Contains('non ascíí')))
github snapcore / snapcraft / integration_tests / test_environment.py View on Github external
def test_environment(self):
        self.run_snapcraft('stage', 'snapcraft-environment')

        part_install_dir = os.path.join(self.path,
                                        self.parts_dir, 'env', 'install')

        test_name = os.path.join(self.stage_dir, 'test_name')
        self.assertThat(test_name, FileContains('test-environment'))

        test_version = os.path.join(self.stage_dir, 'test_version')
        self.assertThat(test_version, FileContains('0.1'))

        test_stage = os.path.join(self.stage_dir, 'test_stage')
        self.assertThat(
            test_stage, FileContains(os.path.join(self.path, self.stage_dir)))

        test_part_install = os.path.join(
            self.path, self.stage_dir, 'test_part_install')
        self.assertThat(test_part_install, FileContains(part_install_dir))
github snapcore / snapcraft / tests / integration / store / test_store_sign_build.py View on Github external
name = self.get_unique_name()
        version = self.get_unique_version()
        self.copy_project_to_cwd(self.project)
        self.update_name_and_version(name, version)
        self.run_snapcraft("snap")
        snap_path = "{}_{}_{}.snap".format(name, version, "all")
        self.assertThat(snap_path, FileExists())
        self.register(name)

        status = self.sign_build(snap_path, local=True)
        self.assertThat(status, Equals(0))

        snap_build_path = "{}-build".format(snap_path)
        self.assertThat(snap_build_path, FileExists())
        self.assertThat(
            snap_build_path, FileContains(matcher=Contains("type: snap-build"))
        )
github snapcore / snapcraft / tests / unit / repo / test_snaps.py View on Github external
self.fake_snapd.snaps_result = [
            {
                "id": "fake-snap-id",
                "name": "fake-snap",
                "channel": "stable",
                "revision": "x1",
            }
        ]

        snap_pkg = snaps.SnapPackage("fake-snap/strict/stable")
        snap_pkg.local_download(
            snap_path="fake-snap.snap", assertion_path="fake-snap.assert"
        )

        self.assertThat("fake-snap.snap", FileExists())
        self.assertThat("fake-snap.assert", FileContains(""))
        fake_get_assertion.mock.assert_not_called()
github snapcore / snapcraft / tests / unit / repo / test_base.py View on Github external
exec_prefix=${{prefix}}
            libdir=${{prefix}}/lib
            includedir=${{prefix}}/include

            Name: granite
            Description: elementary's Application Framework
            Version: 0.4
            Libs: -L${{libdir}} -lgranite
            Cflags: -I${{includedir}}/granite
            Requires: cairo gee-0.8 glib-2.0 gio-unix-2.0 gobject-2.0
            """.format(
                self.tempdir
            )
        )

        self.assertThat(pc_file, FileContains(expected_pc_file_content))
github snapcore / snapcraft / tests / unit / meta / test_command.py View on Github external
def test_command_relative_command_found_in_slash(self):
        cmd = command.Command(app_name="foo", command_name="command", command="sh")

        cmd.prime_command(
            can_use_wrapper=True, massage_command=True, prime_dir=self.path
        )
        wrapper_path = cmd.write_wrapper(prime_dir=self.path)

        self.expectThat(cmd.command, Equals("command-foo.wrapper"))
        self.assertThat(wrapper_path, FileExists())
        self.assertThat(wrapper_path, FileContains('#!/bin/sh\nexec /bin/sh "$@"\n'))
        self.assertThat(
            self.fake_logger.output.strip(),
            Equals(
                "The command 'sh' was not found in the prime directory, it has "
                "been changed to '/bin/sh'."
github snapcore / snapcraft / tests / unit / meta / test_desktop.py View on Github external
def test_generate_desktop_file(self):
        d = DesktopFile(
            snap_name=self.snap_name,
            app_name=self.app_name,
            filename=self.desktop_file_path,
            prime_dir=self.path,
        )
        try:
            d.write(icon_path=self.icon_path, gui_dir=".")
        except AttributeError:
            d.write(gui_dir=".")

        self.assertThat(self.expected_desktop_file, FileExists())
        self.assertThat(
            self.expected_desktop_file,
            FileContains(
                dedent(
                    """\
            [Desktop Entry]
            Exec=foo
            Icon={}

        """.format(
                        self.expected_icon
                    )
github snapcore / snapcraft / tests / unit / pluginhandler / test_runner.py View on Github external
part_properties={"override-build": "echo $PATH > path"},
            sourcedir="sourcedir",
            builddir="builddir",
            stagedir="stagedir",
            primedir="primedir",
            builtin_functions={},
        )

        runner.build()

        expected_path_segment = "/snap/snapcraft/current/bin/scriptlet-bin"

        self.assertThat(os.path.join("builddir", "path"), FileExists())
        self.assertThat(
            os.path.join("builddir", "path"),
            FileContains(matcher=Contains(expected_path_segment)),
        )
github snapcore / snapcraft / tests / integration / general / test_environment.py View on Github external
def test_environment(self):
        self.run_snapcraft("stage", "snapcraft-environment")

        part_install_dir = os.path.join(self.path, self.parts_dir, "env", "install")

        test_name = os.path.join(self.stage_dir, "test_name")
        self.assertThat(test_name, FileContains("test-environment"))

        test_version = os.path.join(self.stage_dir, "test_version")
        self.assertThat(test_version, FileContains("0.1"))

        test_stage = os.path.join(self.stage_dir, "test_stage")
        self.assertThat(
            test_stage, FileContains(os.path.join(self.path, self.stage_dir))
        )

        test_part_install = os.path.join(self.path, self.stage_dir, "test_part_install")
        self.assertThat(test_part_install, FileContains(part_install_dir))