Пример #1
0
    def test_parse_test(self, sha, data):
        """
        Test the loading of specific commits.

        :param sha: The commit to load
        :param data: The data to check against
        """
        self.instance = Commit(sha)
        self.instance.load()

        msg = 'Test failed for commit with sha %s' % sha

        self.assertEqual(data['author'], self.instance.author.name, msg)
        self.assertEqual(data['commit'], self.instance.commit.name, msg)

        self.assertEqual(dp.parse(data['authorDate']),
                         self.instance.author_date, msg)
        self.assertEqual(dp.parse(data['commitDate']),
                         self.instance.commit_date, msg)

        self.assertEqual(data['title'], self.instance.title, msg)
        self.assertEqual(data['msg'], self.instance.message, msg)

        self.assertEqual(data['parents'],
                         list(map(lambda x: x.sha, self.instance.parents)),
                         msg)

        self.assertEqual(data['numFiles'], len(self.instance.changes().data))
Пример #2
0
 def test_lt_false(self):
     """
     Test if a newer commit is not less then the instance.
     :return:
     """
     self.assertFalse(
         self.instance < Commit('f3ccd0b70fe758b539c28319735d9a6489c0fb10'))
Пример #3
0
    def changes_from(self, from_commit, to_commit=None):
        """
        Get the diff of this file between two commits.
        By default this is between the HEAD and the specified commit.

        :type from_commit: Commit | str
        :param from_commit: The from commit of the diff
        :type to_commit: Commit | str
        :param to_commit: The to commit of the diff. Defaults to HEAD
        :rtype: FileDiff
        :return: The diff between the from and to commit
        """
        if isinstance(from_commit, str):
            from_commit = Commit.get_commit(from_commit)
        if to_commit is None:
            to_commit = Git.get_head()
        elif isinstance(to_commit, str):
            to_commit = Commit.get_commit(to_commit)

        assert from_commit < to_commit, 'The from commit should be older than the to commit'

        out = Git.call(['diff', from_commit, to_commit, self.relative_path])
        return FileDiff(self.name, out)
Пример #4
0
    def history(self):
        """
        Get the history of this file as a list of commits.
        These commits are stored new -> old.

        :rtype: List[Commit]
        :return: A list of all the commits that made changes to this file
        """
        lines = Git.call(['log', '--pretty=format:%H', self.path]).split('\n')

        res = [None] * len(lines)
        for i, sha in enumerate(lines):
            res[i] = Commit.get_commit(sha)
        return res
Пример #5
0
 def test_lt_true(self):
     """
     Test if an older commit is less than the instance.
     """
     self.assertTrue(
         self.instance < Commit('ede9c381daf318a87a58ed9607549132e150f145'))
Пример #6
0
 def setUp(self):
     """
     Create a fresh instance for each test case.
     """
     self.instance = Commit('9b423f8c38516ed33acfa907ae56ad3868741803')
Пример #7
0
class CommitTest(unittest.TestCase):
    """
    Test class for Commit.
    """
    @classmethod
    def setUpClass(cls):
        """
        Setup for the tests. Clone the repo and set the correct version.
        """
        Git.clone('test-clone/', 'https://github.com/ChielBruin/Gitcovery.git')
        cls.root = Git.checkout('ede9c381daf318a87a58ed9607549132e150f145')

    def setUp(self):
        """
        Create a fresh instance for each test case.
        """
        self.instance = Commit('9b423f8c38516ed33acfa907ae56ad3868741803')

    @parameterized.expand(load_params())
    def test_parse_test(self, sha, data):
        """
        Test the loading of specific commits.

        :param sha: The commit to load
        :param data: The data to check against
        """
        self.instance = Commit(sha)
        self.instance.load()

        msg = 'Test failed for commit with sha %s' % sha

        self.assertEqual(data['author'], self.instance.author.name, msg)
        self.assertEqual(data['commit'], self.instance.commit.name, msg)

        self.assertEqual(dp.parse(data['authorDate']),
                         self.instance.author_date, msg)
        self.assertEqual(dp.parse(data['commitDate']),
                         self.instance.commit_date, msg)

        self.assertEqual(data['title'], self.instance.title, msg)
        self.assertEqual(data['msg'], self.instance.message, msg)

        self.assertEqual(data['parents'],
                         list(map(lambda x: x.sha, self.instance.parents)),
                         msg)

        self.assertEqual(data['numFiles'], len(self.instance.changes().data))

    def test_unload(self):
        """
        Test the unload function.
        First loads, checks if the data is there, unloads and checks if the data is gone.
        """
        self.instance.load()
        self.assertIsNotNone(self.instance._author)
        self.instance.unload()
        self.assertIsNone(self.instance._author)

    def test_lt_invalid(self):
        """
        Test that comparing a Commit to a number gives an error.
        """
        with self.assertRaises(TypeError):
            self.instance < 12

    def test_lt_self(self):
        """
        Test if you are older than yourself.
        """
        self.assertFalse(self.instance < self.instance)

    def test_lt_true(self):
        """
        Test if an older commit is less than the instance.
        """
        self.assertTrue(
            self.instance < Commit('ede9c381daf318a87a58ed9607549132e150f145'))

    def test_lt_false(self):
        """
        Test if a newer commit is not less then the instance.
        :return:
        """
        self.assertFalse(
            self.instance < Commit('f3ccd0b70fe758b539c28319735d9a6489c0fb10'))

    def test_eq_invalid(self):
        """
        Test if a Commit is not equal to a string.
        """
        self.assertFalse(self.instance == '123')

    def test_eq_true(self):
        """
        Test that you are equal when the hash is equal.
        """
        self.assertTrue(self.instance == Commit(self.instance.sha))

    def test_eq_false(self):
        """
        Test that you are not equal when the hashes differ.
        """
        self.assertFalse(self.instance == Commit(
            'f3ccd0b70fe758b539c28319735d9a6489c0fb10'))
Пример #8
0
 def test_eq_false(self):
     """
     Test that you are not equal when the hashes differ.
     """
     self.assertFalse(self.instance == Commit(
         'f3ccd0b70fe758b539c28319735d9a6489c0fb10'))
Пример #9
0
 def test_eq_true(self):
     """
     Test that you are equal when the hash is equal.
     """
     self.assertTrue(self.instance == Commit(self.instance.sha))