Ejemplo n.º 1
0
    def test_parse__should_return_just_java_none_tagged_file(self):
        java_file = File('name.java', None, 20, 4)
        controller = FilesController(
            '', [java_file, File('name2.kt', None, 3, 1)], self.language)
        controller.parse(is_file_exists_true, get_tags_from_file_empty)

        self.assertEqual([java_file], controller.none_tagged_files)
Ejemplo n.º 2
0
    def test_add_test_files_to_files_in_tags__should_pair_correctly(self):
        tags = {
            'TAG_1':
            Tag([
                File(
                    'MedicalSampleSeriesQuantitySpentPerMedicalClientForProducer.java',
                    None, 0, 0),
                File(
                    'MedicalSampleSeriesQuantitySpentPerMedicalClientForProducerOnObjectParsed.kt',
                    None, 0, 0),
            ])
        }
        test_files = [
            File(
                'MedicalSampleSeriesQuantitySpentPerMedicalClientForProducerOnObjectParsedTest.groovy',
                None, 0, 0),
            File('HelloWorldTest.java', None, 0, 0)
        ]

        files_controller.match_test_files_to_files_in_tags(tags, test_files)

        files = tags['TAG_1'].files

        self.assertEqual(None, files[0].test_file)
        self.assertEqual(
            'MedicalSampleSeriesQuantitySpentPerMedicalClientForProducerOnObjectParsedTest.groovy',
            files[1].test_file.file_path)
Ejemplo n.º 3
0
    def test_parse__should_return_just_tagged_files(self):
        controller = FilesController(
            '',
            [File('name.java', None, 20, 4),
             File('name2.java', None, 3, 1)], self.language)
        controller.parse(is_file_exists_true, get_tags_from_file_not_empty)

        self.assertEqual(2, controller.tags.items().__len__())
Ejemplo n.º 4
0
    def test_parse__should_return_just_test_files(self):
        files = [
            File('HelloWorldTest.java', None, 20, 4),
            File('HelloWorld.java', None, 3, 1)
        ]
        controller = FilesController('', files, self.language)
        controller.parse(is_file_exists_true, get_tags_from_file_not_empty)

        self.assertEqual(1, controller.test_files.__len__())
Ejemplo n.º 5
0
    def test_sort_tags__should_sort_by_tags_count(self):
        controller = FilesController(
            '',
            [File('name.java', None, 20, 4),
             File('name2.java', None, 3, 1)], self.language)
        controller.tags = {
            'TAG_1': Tag([File]),
            'TAG_2': Tag([File, File, File])
        }
        sorted_tags = files_controller.sort(controller.tags, False)

        self.assertEqual('TAG_1', sorted_tags[0][0])
        self.assertEqual('TAG_2', sorted_tags[1][0])
Ejemplo n.º 6
0
    def test_put_tags_to_map__should_put_three_tags_to_map(self):
        actual = {}
        tags = ['TAG_1', 'TAG_2', 'TAG_3']
        files_controller.put_tags_to_map(actual, tags, File('', None, 5, 5))

        self.assertEquals(1, actual['TAG_1'].get_files_count())
        self.assertEquals(1, actual['TAG_2'].get_files_count())
        self.assertEquals(1, actual['TAG_3'].get_files_count())
Ejemplo n.º 7
0
    def test_add_tags_to_existing_map__should_not_add_same_file_to_existing_tag(
            self):
        # GIVEN
        existing_tag_key = 'TAG_1'
        existing_tag = Tag([File('file1.java', None, 0, 0)])
        # AND
        new_tags = {existing_tag_key: existing_tag}
        existing_tags = {
            existing_tag_key: Tag([File('file1.java', None, 0, 0)])
        }

        # WHEN
        files_controller.add_tags_to_existing_map(existing_tags, new_tags)

        # THEN
        self.assertEqual(existing_tag, existing_tags.get(existing_tag_key))
        self.assertEqual(1,
                         existing_tags.get(existing_tag_key).get_files_count())
Ejemplo n.º 8
0
 def test_get_file_lines_should_return_four_lines_for_file_without_last_empty_line(self):
     path = os.path.dirname(os.path.abspath(
         __file__)) + '/data/test_get_file_lines_should_return_four_lines_for_file_without_last_empty_line'
     f = open(path)
     file_content = mmap.mmap(f.fileno(), 0, access=mmap.ACCESS_READ)
     f = File('/foo/File', file_content, 1, 1)
     actual = f.lines
     expected = 4
     file_content.close()
     self.assertEqual(expected, actual)
Ejemplo n.º 9
0
    def test_get_files_from_diff_should_return_correct_array(self):
        diff = '4\t0\t.gitignore\n' \
               ' '
        file_mapper = FileMapper(diff)
        diffed_files = file_mapper.map_files('', get_file_content_mock)
        actual = diffed_files[0]
        expected = File('.gitignore', None, 4, 0)

        self.assertEqual(expected.file_path, actual.file_path)
        self.assertEqual(expected.deleted_lines, actual.deleted_lines)
        self.assertEqual(expected.added_lines, actual.added_lines)
Ejemplo n.º 10
0
    def test_put_tags_to_map__should_increment_values_for_keys(self):
        actual = {
            'TAG_1': Tag(['file']),
            'TAG_2': Tag(['file']),
            'TAG_3': Tag(['file'])
        }
        tags = ['TAG_1', 'TAG_2', 'TAG_3']
        files_controller.put_tags_to_map(actual, tags, File('', None, 5, 5))

        self.assertEquals(2, actual['TAG_1'].get_files_count())
        self.assertEquals(2, actual['TAG_2'].get_files_count())
        self.assertEquals(2, actual['TAG_3'].get_files_count())
Ejemplo n.º 11
0
    def test_add_tags_to_existing_map__should_add_file_to_existing_tag(self):
        # GIVEN
        existing_tag_key = 'TAG_1'
        new_tag_value = Tag([File('new_file1.java', None, 0, 0)])
        # AND
        new_tags = {existing_tag_key: new_tag_value}
        existing_tags = {
            existing_tag_key:
            Tag([
                File('file1.java', None, 0, 0),
                File('file2.java', None, 0, 0),
            ])
        }

        # WHEN
        files_controller.add_tags_to_existing_map(existing_tags, new_tags)

        # THEN
        self.assertEqual(new_tag_value.files[0],
                         existing_tags.get(existing_tag_key).files[-1])
        self.assertEqual(3,
                         existing_tags.get(existing_tag_key).get_files_count())
Ejemplo n.º 12
0
    def test_add_tags_to_existing_map__should_insert_new_tag(self):
        # GIVEN
        new_tag_key = 'TAG_3'
        new_tag_value = Tag([File('new_file1.java', None, 0, 0)])
        # AND
        new_tags = {new_tag_key: new_tag_value}
        existing_tags = {}

        # WHEN
        files_controller.add_tags_to_existing_map(existing_tags, new_tags)

        # THEN
        self.assertEqual(new_tag_value, existing_tags.get(new_tag_key))
Ejemplo n.º 13
0
    def map_files(self, project_path, fun_get_file_content):
        array = self.diff.split('\n')
        array.pop()

        files = []
        for line in array:
            args = line.split('\t')
            file_path = args[2]
            file_content = fun_get_file_content(project_path, file_path)
            added_lines = 0 if args[0] == '-' else int(args[0])
            deleted_lines = 0 if args[1] == '-' else int(args[1])
            files.append(File(file_path, file_content, added_lines, deleted_lines))

        return files
Ejemplo n.º 14
0
 def test_get_status_should_return_modified_state(self):
     f = File('/foo/File', None, 123, 5)
     f.lines = 200
     actual = f.get_status()
     expected = 'Modified'
     self.assertEqual(expected, actual)
Ejemplo n.º 15
0
 def test_get_file_lines_should_return_zero_for_empty_file(self):
     f = File('/foo/File', None, 20, 5)
     actual = f.lines
     expected = 0
     self.assertEqual(expected, actual)
Ejemplo n.º 16
0
 def test_get_added_files_percent_should_return_correct_value(self):
     f = File('/foo/File', None, 20, 5)
     f.lines = 200
     actual = f.get_added_files_percent()
     expected = 10.0
     self.assertEqual(expected, actual)
Ejemplo n.º 17
0
 def test_get_deleted_files_percent_should_return_zero_for_empty_file(self):
     actual = File('/foo/File', None, 20, 5).get_deleted_files_percent()
     expected = 0
     self.assertEqual(expected, actual)