コード例 #1
0
    def discover_fixtures(self, files):
        with patch('simple_test.fixtures.FIXTURES',
                   autospec=Path) as fixtures_dir:
            fixtures_dir.glob.return_value = files

            fixtures = discover_fixtures()
            fixtures_dir.glob.assert_called_with('**/*')
            return fixtures
コード例 #2
0
 def test_fixtures_are_snake_case(self):
     for fixture in discover_fixtures():
         for part in fixture.relative_sim_file_path.with_suffix('').parts:
             self.assertRegex(
                 part,
                 r'^[a-z0-9]+(_[a-z0-9]+)*$',
                 msg="fixture files should be snake case: {}".format(
                     fixture.relative_sim_file_path))
コード例 #3
0
    def test_fixtures_are_snake_case(self):
        non_snake_case = []

        for fixture in discover_fixtures():
            for part in fixture.relative_sim_file_path.with_suffix('').parts:
                if not re.match(r'^[a-z]+(_[a-z0-9]+)*$', part):
                    non_snake_case.append(fixture.relative_sim_file_path)

        if non_snake_case:
            self.fail("Fixture names must be snake case:\n\n{}".format(
                '\n'.join("\t{}".format(n) for n in non_snake_case)))
コード例 #4
0
    def test_no_duplicate_sim_files(self):
        sim_file_contents = {}

        for fixture in discover_fixtures():
            with fixture.sim_file_path.open() as f:
                contents = f.read()

                if contents in sim_file_contents:
                    self.fail("identical sim files {} and {}".format(
                        fixture.relative_sim_file_path,
                        sim_file_contents[contents]))

                sim_file_contents[contents] = fixture.relative_sim_file_path
コード例 #5
0
    def test_tests_pass_for_dummy_compiler(self):
        # unittest discover will pick up this base class, so we skip it when it
        # is run to prevent any errors from uninitialized properties
        if type(self) == PhaseTestBase:  # pylint: disable=C0123
            return

        with FakeCompilerContext() as fake_compiler:
            for fixture in discover_fixtures():
                if fixture.phase_name == self.phase_name:  # noqa  # pylint: disable=E1101
                    self.assertGoodFakeCompilerPasses(fake_compiler, fixture)

                    for for_stdin in (False, True):
                        self.assertBadStdoutFakeCompilerFails(
                            fake_compiler, fixture, for_stdin)
                        self.assertBadStderrFakeCompilerFails(
                            fake_compiler, fixture, for_stdin)
コード例 #6
0
    def __init_subclass__(cls, phase_name: str) -> None:
        # NOTE: See above, the metaclass hackey to add PEP487 support to python
        #       does not provide a super().__init_subclass__()
        # super().__init_subclass__()

        # Add the test_{fixture.name} methods for each fixture discovered
        for fixture in discover_fixtures():
            if fixture.phase_name == phase_name:
                test_method = _create_test_method(fixture)
                method_name = "test_{}".format(fixture.name)
                test_method.__name__ = method_name

                assert not hasattr(cls, method_name), \
                    "fixture name would replace existing test method: {}" \
                    .format(method_name)

                setattr(cls, method_name, test_method)
コード例 #7
0
    def test_no_duplicate_sim_files(self):
        sim_file_contents = {}
        sim_files = set()
        duplicates = []

        for fixture in discover_fixtures():
            if fixture.sim_file_path not in sim_files:
                with fixture.sim_file_path.open() as f:
                    contents = f.read()

                    if contents in sim_file_contents:
                        duplicates.append((fixture.relative_sim_file_path,
                                           sim_file_contents[contents]))

                    sim_file_contents[contents] = \
                        fixture.relative_sim_file_path
                    sim_files.add(fixture.sim_file_path)

        if duplicates:
            self.fail(
                "Identical sim files:\n\n{}\n\nPlease merge them!".format(
                    '\n'.join("\t{} and {}".format(a, b)
                              for a, b in duplicates)))