Esempio n. 1
0
    def test_file_not_in_since_rev(self, mock_get_files, ):
        mock_get_files.return_value = (set(['in_since_and_until', 'not_in_since']), set([]))

        # Mock up arg namespace
        self.guilt.args = Mock()
        self.guilt.args.since = 'since'
        self.guilt.args.until = 'until'

        self.guilt.trees['since'] = ['in_since_and_until']
        self.guilt.trees['until'] = ['in_since_and_until', 'not_in_since']

        def mock_blame_logic(blame):
            if 'not_in_since' == blame.versioned_file.repo_path:
                if 'since' == blame.versioned_file.git_revision:
                    blame.exists = False
                elif 'until' == blame.versioned_file.git_revision:
                    blame.exists = True
                    blame.bucket['Alice'] += 20
                    blame.bucket['Bob'] += 5
            elif 'in_since_and_until' == blame.versioned_file.repo_path:
                blame.exists = True
                if 'since' == blame.versioned_file.git_revision:
                    blame.bucket['Alice'] += 12
                    blame.bucket['Bob'] += 8
                    blame.bucket['Dave'] += 4
                elif 'until' == blame.versioned_file.git_revision:
                    blame.exists = True
                    blame.bucket['Alice'] += 18
                    blame.bucket['Bob'] += 2
                    blame.bucket['Carol'] += 2

        # FIXME This monkey patching is ugly and should be handled through Mock
        old_process = guilt_module.TextBlameTicket.process
        try:
            guilt_module.TextBlameTicket.process = mock_blame_logic

            self.guilt.map_blames()
            self.assertEquals({'Alice': 12, 'Bob': 8, 'Dave': 4}, self.guilt.loc_ownership_since)
            self.assertEquals({'Alice': 38, 'Bob': 7, 'Carol': 2}, self.guilt.loc_ownership_until)

            self.guilt.reduce_blames()

            # Alice's share of the collective guilt has increased from 12 LOCs in
            # the since rev to 38 LOCs
            # Bob's share of the collective guilt has decreased from 8 to 7 LOCs
            # (spread across different files)
            # Carol's share of the collective guilt has increased from 0 in the
            # since rev to 2 LOCs
            expected_guilt = [
                    guilt_module.Delta('Alice', 12, 38),
                    guilt_module.Delta('Bob', 8, 7),
                    guilt_module.Delta('Carol', 0, 2),
                    guilt_module.Delta('Dave', 4, 0)
                ]
            expected_guilt.sort()

            self.assertEquals(expected_guilt, self.guilt.loc_deltas)
        finally:
            guilt_module.TextBlameTicket.process = old_process
Esempio n. 2
0
    def test_repr(self):
        a = guilt_module.Delta('Alpha', 0, 4)
        b = guilt_module.Delta('Beta', 16, 10)
        c = guilt_module.Delta('Gamma', 8, 8)

        self.assertEquals("<Delta \"Alpha\": 4 (0->4)>", repr(a))
        self.assertEquals("<Delta \"Beta\": -6 (16->10)>", repr(b))
        self.assertEquals("<Delta \"Gamma\": 0 (8->8)>", repr(c))
Esempio n. 3
0
    def test_eq(self):
        a = guilt_module.Delta('Alpha', 4, 0)
        b = guilt_module.Delta('Beta', 6, 0)
        self.assertFalse(a == b)
        self.assertTrue(a != b)

        b = guilt_module.Delta('Alpha', 6, 0)
        self.assertFalse(a == b)
        self.assertTrue(a != b)

        b = guilt_module.Delta('Alpha', 4, 0)
        self.assertTrue(a == b)
        self.assertTrue(a <= b)
        self.assertTrue(a >= b)
        self.assertFalse(a != b)
Esempio n. 4
0
    def test_reduce_locs(self):
        self.guilt.loc_ownership_since = {'Alice': 5, 'Bob': 3, 'Carol': 4}
        self.guilt.loc_ownership_until = {'Alice': 6, 'Bob': 6, 'Carol': 2, 'Dave': 1, 'Ellen': 2}

        expected_deltas = [
                guilt_module.Delta(until=6, since=3, author='Bob'),
                guilt_module.Delta(until=2, since=0, author='Ellen'),
                guilt_module.Delta(until=6, since=5, author='Alice'),
                guilt_module.Delta(until=1, since=0, author='Dave'),
                guilt_module.Delta(until=2, since=4, author='Carol'),
                ]

        self.guilt.reduce_blames()

        self.assertEquals(
            expected_deltas,
            self.guilt.loc_deltas
        )
Esempio n. 5
0
    def test_comparison(self):
        a = guilt_module.Delta('Alpha', 4, 0)

        # a > b because a is guiltier than b
        b = guilt_module.Delta('Beta', 6, 0)

        # Test __lt__ and __le__
        self.assertTrue(a < b)
        self.assertTrue(a <= b)
        self.assertFalse(b < a)
        self.assertFalse(b <= a)

        # Test __gt__ and __ge__
        self.assertFalse(a > b)
        self.assertFalse(a >= b)
        self.assertTrue(b > a)
        self.assertTrue(b >= a)

        # a and b are equally guilt_moduley, but a comes before b in a lexicographic
        # sort
        b = guilt_module.Delta('Beta', 4, 0)

        # Test __lt__ and __le__
        self.assertTrue(a < b)
        self.assertTrue(a <= b)
        self.assertFalse(b < a)
        self.assertFalse(b <= a)

        # Test __gt__ and __ge__
        self.assertFalse(a > b)
        self.assertFalse(a >= b)
        self.assertTrue(b > a)
        self.assertTrue(b >= a)

        b = guilt_module.Delta('Aardvark', 4, 0)
        self.assertFalse(a < b)
        self.assertFalse(a <= b)

        self.assertTrue(a > b)
        self.assertTrue(a >= b)
Esempio n. 6
0
    def setUp(self):
        # Mock stdout.fileno()
        self._stdout_patch = patch('git_guilt.guilt.sys.stdout')
        self.mocked_stdout = self._stdout_patch.start()
        self.mocked_stdout.return_value = Mock(
            fileno=Mock(return_value=1),
        )

        # Mock os.isatty
        self._isatty_patch = patch('git_guilt.guilt.os.isatty')
        self.mocked_isatty = self._isatty_patch.start()
        self.mocked_isatty.return_value = False

        self.bin_delta_list = [
            guilt_module.BinaryDelta(u'short', 30, 45),
            guilt_module.BinaryDelta(u'Very Long Name', 10, 7)
        ]
        self.text_delta_list = [
            guilt_module.Delta(u'short', 30, 45),
            guilt_module.Delta(u'Very Long Name', 10, 7)
        ]
        self.formatter = guilt_module.Formatter(self.bin_delta_list, self.text_delta_list)
Esempio n. 7
0
 def set_byte_deltas():
     self.guilt.loc_deltas=[guilt_module.Delta('foo', 45, 25)]
     self.guilt.byte_deltas=[guilt_module.BinaryDelta('bar', 5, 78)]
Esempio n. 8
0
    def test_map_binary_blames(self, mock_get_delta):

        mock_get_delta.return_value = set([]), set(['foo.bin', 'libbar.so.1.8.7'])

        self.guilt.args = Mock(since='HEAD~4', until='HEAD~1')
        self.guilt.trees['HEAD~4'] = ['foo.bin', 'libbar.so.1.8.7']
        self.guilt.trees['HEAD~1'] = ['foo.bin', 'libbar.so.1.8.7']


        def mock_blame_logic(blame):
            if 'foo.bin' == blame.versioned_file.repo_path:
                if 'HEAD~4' == blame.versioned_file.git_revision:
                    blame.bucket['Alice'] += 20
                    blame.bucket['Bob'] += 5
                elif 'HEAD~1' == blame.versioned_file.git_revision:
                    blame.bucket['Carol'] += 2

            elif 'libbar.so.1.8.7' == blame.versioned_file.repo_path:
                if 'HEAD~4' == blame.versioned_file.git_revision:
                    blame.bucket['Alice'] += 12
                elif 'HEAD~1' == blame.versioned_file.git_revision:
                    blame.bucket['Alice'] += 18

        # FIXME This monkey patching is ugly and should be handled through Mock
        old_process = guilt_module.BinaryBlameTicket.process
        try:
            guilt_module.BinaryBlameTicket.process = mock_blame_logic

            self.guilt.map_blames()

            # Assert the set of blame "jobs" generated by PyGuilt.map_blames()
            self.assertEquals(4, len(self.guilt.blame_jobs))
            self.assertEquals(
                [
                    guilt_module.BinaryBlameTicket(self.guilt.runner, self.guilt.byte_ownership_since, guilt_module.VersionedFile('foo.bin', 'HEAD~4'), Mock()),
                    guilt_module.BinaryBlameTicket(self.guilt.runner, self.guilt.byte_ownership_until, guilt_module.VersionedFile('foo.bin', 'HEAD~1'), Mock()),
                    guilt_module.BinaryBlameTicket(self.guilt.runner, self.guilt.byte_ownership_since, guilt_module.VersionedFile('libbar.so.1.8.7', 'HEAD~4'), Mock()),
                    guilt_module.BinaryBlameTicket(self.guilt.runner, self.guilt.byte_ownership_until, guilt_module.VersionedFile('libbar.so.1.8.7', 'HEAD~1'), Mock()),
                ],
                self.guilt.blame_jobs
            )

            # Assert the ownership buckets
            self.assertEquals({}, self.guilt.loc_ownership_since)
            self.assertEquals({}, self.guilt.loc_ownership_until)
            self.assertEquals({'Alice': 32, 'Bob': 5}, self.guilt.byte_ownership_since)
            self.assertEquals({'Alice': 18, 'Carol': 2}, self.guilt.byte_ownership_until)

            self.guilt.reduce_blames()

            # Alice's share of the collective guilt has decreased from 32 to 18
            # bytes
            # Bob's share of the collective guilt has been wiped clean!
            # Carol's share has increased from nothing to 2
            expected_guilt = [
                    guilt_module.Delta('Alice', 32, 18),
                    guilt_module.Delta('Bob', 5, 0),
                    guilt_module.Delta('Carol', 0, 2)
                ]
            expected_guilt.sort()
            self.assertEquals(expected_guilt, self.guilt.byte_deltas)
            self.assertEquals([], self.guilt.loc_deltas)

        finally:
            guilt_module.BinaryBlameTicket.process = old_process