def test_given_test_file_when_test_type_has_two_types_in_common_to_file_then_most_weighted_type_should_be_returned(
            self, mock_walk, mock_filenamematcher, mock_filecontentcontains,
            mock_test_matcher):
        mock_walk.return_value = [('/tests', (), ('test_file', ))]
        mock_filenamematcher.return_value = [
            MatcherResult('/tests/test_file', ['Test', 'Abc'],
                          MatcherResultType.file)
        ]
        mock_filecontentcontains.return_value = [
            MatcherResult('/tests/test_file', ['Abc', 'Test'],
                          MatcherResultType.file)
        ]
        mock_test_matcher.return_value = [
            MatcherResult('test_case', ['Test', 'Abc'], MatcherResultType.test)
        ]

        child_config_mock = MagicMock()
        child_config_mock.name = 'Test'
        child_config_mock.weight = 2

        parent_config_mock = MagicMock()
        parent_config_mock.name = 'Abc'
        parent_config_mock.path = '/'
        parent_config_mock.get_type_names.return_value = ['Abc', 'Test']
        parent_config_mock.get_type_by_name.side_effect = get_type_side_effect
        parent_config_mock.weight = 1

        tests = TestDiscovery(parent_config_mock).discover_tests()
        self.assertEqual(1, len(tests))
        self.assertEqual('/tests/test_file', tests[0].file_name)
        self.assertEqual('test_case', tests[0].description)
        self.assertEqual('Test', tests[0].type)
    def test_given_test_file_when_test_type_has_one_type_in_common_to_file_types_then_tests_should_be_returned(
            self, mock_walk, mock_filenamematcher, mock_filecontentcontains,
            mock_test_matcher):
        mock_walk.return_value = [('/tests', (), ('test_file', ))]
        mock_filenamematcher.return_value = [
            MatcherResult('/tests/test_file', ['Test', 'Abc'],
                          MatcherResultType.file)
        ]
        mock_filecontentcontains.return_value = [
            MatcherResult('/tests/test_file', ['Def', 'Test'],
                          MatcherResultType.file)
        ]
        mock_test_matcher.return_value = [
            MatcherResult('test_case', ['Test', 'OtherTest'],
                          MatcherResultType.test)
        ]

        test_config = MagicMock()
        test_config.name = 'Test'
        test_config.path = '/'
        tests = TestDiscovery(test_config).discover_tests()
        self.assertEqual(1, len(tests))
        self.assertEqual('/tests/test_file', tests[0].file_name)
        self.assertEqual('test_case', tests[0].description)
        self.assertEqual('Test', tests[0].type)
    def test_given_test_file_that_does_not_have_tests_then_no_tests_should_be_returned(
            self, mock_walk, mock_filenamematcher, mock_filecontentcontains,
            mock_test_matcher):
        mock_walk.return_value = [('/tests', (), ('test_file', ))]
        mock_filenamematcher.return_value = [
            MatcherResult('/tests/test_file', ['Test'], MatcherResultType.file)
        ]
        mock_filecontentcontains.return_value = [
            MatcherResult('/tests/test_file', ['Test'], MatcherResultType.file)
        ]
        mock_test_matcher.return_value = []

        test_config = MagicMock()
        test_config.name = 'Test'
        test_config.path = '/'
        tests = TestDiscovery(test_config).discover_tests()
        self.assertEqual([], tests)
Example #4
0
 def matches(self, file_path: str) -> [MatcherResult]:
     config_names = self.test_config.get_type_names()
     matched_types = []
     result = []
     for config_name in config_names:
         test_config = self.test_config.get_type_by_name(config_name)
         if not test_config.file_name_regex:
             matched_types.append(test_config.name)
         else:
             if re.match(test_config.file_name_regex, file_path):
                 matched_types.append(test_config.name)
     if matched_types:
         result = [
             MatcherResult(file_path, matched_types, MatcherResultType.file)
         ]
     return result
Example #5
0
 def matches(self, file_path) -> [MatcherResult]:
     matched_types = []
     result = []
     for test_name in self.test_config.get_type_names():
         curr_test_config = self.test_config.get_type_by_name(test_name)
         if curr_test_config.file_content_contains:
             with open(file_path) as file:
                 for line in file:
                     if curr_test_config.file_content_contains in line.strip(
                     ):
                         matched_types.append(test_name)
                         break
             file.close()
         else:
             matched_types.append(test_name)
     if matched_types:
         result = [
             MatcherResult(file_path, matched_types, MatcherResultType.file)
         ]
     return result
Example #6
0
    def __build_results(types_by_test_name) -> [MatcherResult]:
        results = []
        for test_name in types_by_test_name.keys():
            results.append(MatcherResult(test_name, types_by_test_name[test_name], MatcherResultType.test))

        return results