How to use the testtools.matchers.Not 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 / remote_build / test_repo.py View on Github external
def test_reset(self):
        repo = Repo(self._dir.path)
        repo.add("foo")
        repo.commit()
        path = os.path.join(self._dir.path, "foo")
        self.assertThat(path, FileExists())
        self._dir.unlink("foo")
        self.assertThat(path, Not(FileExists()))
        repo.reset()
        self.assertThat(path, FileExists())
github snapcore / snapcraft / tests / integration / plugins / test_cmake_plugin.py View on Github external
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
        self.assertThat(output, Not(Contains("The CXX compiler identification")))
        self.assertThat(
            output, Contains("Building CXX object CMakeFiles/foo.dir/foo.cpp.o")
        )
        self.assertThat(
            output,
            Not(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("new foo\n"))
github praekeltfoundation / seaworthy / seaworthy / tests-testtools / test_testtools.py View on Github external
]),
        ])

        # This passes if the MatchesPsTree matcher matches.
        assert_that(pst, MatchesPsTree('root', 'tini -- app', children=[
            MatchesPsTree('root', 'app --arg', children=[
                MatchesPsTree('appuser', 'app --child1'),
                MatchesPsTree('appuser', 'app --child2'),
            ]),
            MatchesPsTree('root', 'app2 --arg', children=[
                MatchesPsTree('root', 'app2 --child'),
            ]),
        ]))

        # This passes if the MatchesPsTree matcher does not match.
        assert_that(pst, Not(MatchesPsTree('root', 'tini -- app', children=[
            MatchesPsTree('root', 'app --arg', children=[
                MatchesPsTree('appuser', 'app --child1'),
            ]),
            MatchesPsTree('root', 'app2 --arg', children=[
                MatchesPsTree('root', 'app2 --child'),
                MatchesPsTree('appuser', 'app --child2'),
            ]),
github snapcore / snapcraft / integration_tests / test_clean_stage_step.py View on Github external
def test_clean_stage_step_single_part(self):
        self.assert_files_exist()

        self.run_snapcraft(['clean', 'part1', '--step=stage'])
        self.assertThat(os.path.join(self.stage_bindir, 'file1'),
                        Not(FileExists()))
        self.assertThat(os.path.join(self.stage_bindir, 'file2'), FileExists())
        self.assertThat(os.path.join(self.snap_bindir, 'file1'),
                        Not(FileExists()))
        self.assertThat(os.path.join(self.snap_bindir, 'file2'), FileExists())
        self.assertThat(self.parts_dir, DirExists())

        # Now try to prime again
        self.run_snapcraft('prime')
        self.assert_files_exist()
github snapcore / snapcraft / tests / unit / project_loader / test_environment.py View on Github external
part2:
                plugin: nil
                after: [part1]
                build-environment:
                  - BAZ: QUX
        """
        )
        project_config = self.make_snapcraft_project(snapcraft_yaml)
        part1 = project_config.parts.get_part("part1")
        part2 = project_config.parts.get_part("part2")
        self.assertThat(
            project_config.parts.build_env_for_part(part1), Contains('FOO="BAR"')
        )
        self.assertThat(
            project_config.parts.build_env_for_part(part2), Not(Contains('FOO="BAR"'))
        )
        self.assertThat(
            project_config.parts.build_env_for_part(part2), Contains('BAZ="QUX"')
        )
github snapcore / snapcraft / integration_tests / test_clean_build_step.py View on Github external
def test_clean_build_step_single_part(self):
        self.assert_files_exist()

        self.run_snapcraft(['clean', 'part1', '--step=build'])
        self.assertThat(os.path.join(self.stage_bindir, 'file1'),
                        Not(FileExists()))
        self.assertThat(os.path.join(self.stage_bindir, 'file2'), FileExists())
        self.assertThat(os.path.join(self.snap_bindir, 'file1'),
                        Not(FileExists()))
        self.assertThat(os.path.join(self.snap_bindir, 'file2'), FileExists())

        self.assertThat(self.parts['part1']['builddir'], Not(DirExists()))
        self.assertThat(self.parts['part1']['installdir'], Not(DirExists()))
        self.assertThat(self.parts['part1']['sourcedir'], DirExists())

        self.assertThat(
            os.path.join(self.parts['part2']['builddir'], 'file2'),
            FileExists())
        self.assertThat(
            os.path.join(self.parts['part2']['bindir'], 'file2'),
            FileExists())
github snapcore / snapcraft / tests / integration / plugins / test_godeps_plugin.py View on Github external
def test_stage_with_go_packages(self):
        if self.set_gobin:
            gobin = "gobin"
            self.useFixture(fixtures.EnvironmentVariable("GOBIN", gobin))

        self.run_snapcraft("stage", "godeps-with-go-packages")

        binary = os.path.join(self.stage_dir, "bin", "only-main")
        self.assertThat(binary, FileExists())
        self.assertThat(
            os.path.join(self.stage_dir, "bin", "bcrypt"), Not(FileExists())
        )

        self._assert_bcrypt_output(binary=binary)
github snapcore / snapcraft / tests / unit / commands / test_register.py View on Github external
def test_register_name_to_specific_store_successfully(self):
        result = self.run_command(
            ["register", "test-snap", "--store", "my-brand"], input="y\n"
        )

        self.assertThat(result.exit_code, Equals(0))
        self.assertThat(result.output, Contains("Registering test-snap"))
        self.assertThat(
            result.output,
            Contains("Congrats! You are now the publisher of 'test-snap'."),
        )
        self.assertThat(
            result.output,
            Not(Contains("Congratulations! You're now the publisher for 'test-snap'.")),
        )
        self.fake_store_register.mock.assert_called_once_with(
            "test-snap", is_private=False, series="16", store_id="my-brand"
        )
github snapcore / snapcraft / tests / integration / general / test_scriptlets.py View on Github external
self.assertThat(os.path.join(self.stage_dir, "after-prime"), Not(FileExists()))

        self.assertThat(os.path.join(self.prime_dir, "file"), FileExists())
        self.assertThat(os.path.join(self.prime_dir, "before-prime"), FileExists())
        self.assertThat(os.path.join(self.prime_dir, "after-prime"), FileExists())

        # Also assert that, while file2 was installed and staged, it wasn't
        # primed
        self.assertThat(
            os.path.join(
                self.parts_dir, "override-prime-do-nothing", "install", "file2"
            ),
            FileExists(),
        )
        self.assertThat(os.path.join(self.stage_dir, "file2"), FileExists())
        self.assertThat(os.path.join(self.prime_dir, "file2"), Not(FileExists()))
github testing-cabal / testtools / testtools / testcase.py View on Github external
def assertIsNot(self, expected, observed, message=''):
        """Assert that 'expected' is not 'observed'."""
        matcher = Not(Is(expected))
        self.assertThat(observed, matcher, message)