How to use the testtools.matchers.Contains 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 / integration / plugins / test_cmake_plugin.py View on Github external
config_path = os.path.join(
            xdg.BaseDirectory.save_config_path("snapcraft"), "cli.cfg"
        )
        with open(config_path, "w") as f:
            f.write("[Lifecycle]\noutdated_step_action = clean")

        self.copy_project_to_cwd("cmake-with-lib")
        output = self.run_snapcraft("prime")

        # Assert that cmake actually configured and built from scratch
        self.assertThat(output, Contains("The CXX compiler identification"))
        self.assertThat(
            output, Contains("Building CXX object CMakeFiles/foo.dir/foo.cpp.o")
        )
        self.assertThat(
            output, Contains("Building CXX object CMakeFiles/usefoo.dir/main.cpp.o")
        )

        binary_output = self.get_output_ignoring_non_zero_exit(
            os.path.join(self.prime_dir, "bin", "usefoo")
        )
        self.assertThat(binary_output, Equals("foo\n"))

        # Modify the source code
        source_file_path = os.path.join("src", "foo.cpp")
        shutil.copy("new_foo.cpp", source_file_path)

        # Prime again. This should rebuild
        output = self.run_snapcraft("prime")

        # Assert that cmake did not start from scratch, and reused everything
        # it could
github snapcore / snapcraft / tests / unit / commands / test_push.py View on Github external
def test_push_without_login_must_ask(self):
        self.fake_store_push_precheck.mock.side_effect = [
            storeapi.errors.InvalidCredentialsError("error"),
            None,
        ]

        result = self.run_command(
            ["push", self.snap_file], input="\n\n\n\nuser@example.com\nsecret\n"
        )

        self.assertThat(
            result.output, Contains("You are required to login before continuing.")
        )
github snapcore / snapcraft / tests / integration / store / test_store_push_metadata.py View on Github external
def test_no_push_needed_first(self):
        self.addCleanup(self.logout)
        self.login()

        self.useFixture(
            fixtures.EnvironmentVariable("SNAPCRAFT_ENABLE_DEVELOPER_DEBUG", "yes")
        )

        # Build and register the snap
        name, snap_file_path = self._build_snap()
        self.register(name)

        # Now push the metadata
        output = self.run_snapcraft(["push-metadata", snap_file_path])
        expected = "Pushing metadata to the Store (force=False)"
        self.assertThat(output, Contains(expected))
        expected = "The metadata has been pushed"
        self.assertThat(output, Contains(expected))
github snapcore / snapcraft / tests / unit / commands / test_promote.py View on Github external
def test_promote_edge(self):
        result = self.run_command(
            [
                "promote",
                "test-snap",
                "--from-channel",
                "edge",
                "--to-channel",
                "candidate",
            ]
        )

        self.assertThat(result.exit_code, Equals(2))
        self.assertThat(
            result.output,
            Contains("'edge' is not a valid set value for --from-channel."),
        )
github snapcore / snapcraft / tests / integration / lifecycle / test_clean_stage_step.py View on Github external
def test_clean_stage_step(self):
        self.assert_files_exist()

        output = self.run_snapcraft(["clean", "--step=stage"], debug=False)
        self.assertThat(self.stage_dir, Not(DirExists()))
        self.assertThat(self.parts_dir, DirExists())

        # Assert that the priming and staging areas were removed wholesale, not
        # a part at a time (since we didn't specify any parts).
        self.assertThat(output, Contains("Cleaning up priming area"))
        self.assertThat(output, Contains("Cleaning up staging area"))
        self.expectThat(output, Not(Contains("part1")))
        self.expectThat(output, Not(Contains("part2")))

        # Now try to stage again
        self.run_snapcraft("stage")
        self.assert_files_exist()
github snapcore / snapcraft / tests / integration / lifecycle / test_clean_stage_step.py View on Github external
def test_clean_stage_step(self):
        self.assert_files_exist()

        output = self.run_snapcraft(["clean", "--step=stage"], debug=False)
        self.assertThat(self.stage_dir, Not(DirExists()))
        self.assertThat(self.parts_dir, DirExists())

        # Assert that the priming and staging areas were removed wholesale, not
        # a part at a time (since we didn't specify any parts).
        self.assertThat(output, Contains("Cleaning up priming area"))
        self.assertThat(output, Contains("Cleaning up staging area"))
        self.expectThat(output, Not(Contains("part1")))
        self.expectThat(output, Not(Contains("part2")))

        # Now try to stage again
        self.run_snapcraft("stage")
        self.assert_files_exist()
github snapcore / snapcraft / tests / integration / snapd / test_ament_snap.py View on Github external
def test_ament_support(self):
        self.useFixture(fixture_setup.WithoutSnapInstalled("ros2-example"))
        self.run_snapcraft(project_dir="ros2")
        self.install_snap()

        self.assertThat(
            subprocess.check_output(
                ["ros2-example.launch-project"],
                universal_newlines=True,
                stderr=subprocess.STDOUT,
            ),
            Contains("I heard: Hello world"),
        )
github snapcore / snapcraft / tests / integration / lifecycle / test_stage.py View on Github external
"Parts 'p1' and 'p2' have the following files, but with different "
            "contents:\n    bin/test\n"
        )
        self.assertThat(exception.output, Contains(expected_conflicts))

        expected_help = (
            "Snapcraft offers some capabilities to solve this by use "
            "of the following keywords:\n"
            "    - `filesets`\n"
            "    - `stage`\n"
            "    - `snap`\n"
            "    - `organize`\n\n"
            "To learn more about these part keywords, run "
            "`snapcraft help plugins`."
        )
        self.assertThat(exception.output, Contains(expected_help))
github snapcore / snapcraft / integration_tests / store / test_store_status.py View on Github external
snap_path = '{}_{}_{}.snap'.format(name, version, 'all')
        self.assertThat(snap_path, FileExists())
        self.register(name)
        self.assertThat(
            self.push(snap_path, release='candidate,beta'),
            Equals(0))

        output = self.run_snapcraft(['status', name])
        expected = '\n'.join((
            'Track    Arch    Channel    Version                           Revision',  # noqa
            'latest   all     stable     -                                 -',
            '                 candidate  {version}  1',
            '                 beta       {version}  1',
            '                 edge       ^                                 ^'
        )).format(version=version)
        self.assertThat(output, Contains(expected))
github snapcore / snapcraft / tests / integration / general / test_multiarch_stage_packages.py View on Github external
def test_bad_multiarch_stage_packages(self):
        exception = self.assertRaises(
            subprocess.CalledProcessError, self.run_snapcraft, "pull", "bad-arch"
        )

        self.assertThat(
            exception.output,
            Contains(
                "Failed to fetch stage packages: "
                "Error downloading packages for part 'my-part': The "