Ejemplo n.º 1
0
    def test_gitcommit_equality(self):
        # Test simple equality case
        now = datetime.datetime.utcnow()
        context1 = GitContext()
        commit_message1 = GitCommitMessage(u"tëst\n\nfoo", u"tëst\n\nfoo",
                                           u"tēst", ["", u"föo"])
        commit1 = GitCommit(context1, commit_message1, now, u"Jöhn Smith",
                            u"jö[email protected]", None, True, [u"föo/bar"])
        context1.commits = [commit1]

        context2 = GitContext()
        commit_message2 = GitCommitMessage(u"tëst\n\nfoo", u"tëst\n\nfoo",
                                           u"tēst", ["", u"föo"])
        commit2 = GitCommit(context1, commit_message1, now, u"Jöhn Smith",
                            u"jö[email protected]", None, True, [u"föo/bar"])
        context2.commits = [commit2]

        self.assertEqual(context1, context2)
        self.assertEqual(commit_message1, commit_message2)
        self.assertEqual(commit1, commit2)

        # Check that objects are inequal when changing a single attribute
        for attr in [
                'message', 'author_name', 'author_email', 'parents',
                'is_merge_commit', 'changed_files'
        ]:
            prev_val = getattr(commit1, attr)
            setattr(commit1, attr, u"föo")
            self.assertNotEqual(commit1, commit2)
            setattr(commit1, attr, prev_val)
            self.assertEqual(commit1, commit2)
Ejemplo n.º 2
0
 def test_gitcommitmessage_equality(self):
     commit_message1 = GitCommitMessage(GitContext(), u"tëst\n\nfoo",
                                        u"tëst\n\nfoo", u"tēst",
                                        ["", u"föo"])
     attrs = ['original', 'full', 'title', 'body']
     self.object_equality_test(commit_message1, attrs,
                               {"context": commit_message1.context})
Ejemplo n.º 3
0
    def test_commit_msg_custom_commentchar(self, patched):
        patched.return_value = "ä"
        context = GitContext()
        message = GitCommitMessage.from_full_message(context, "Tïtle\n\nBödy 1\näCömment\nBody 2")

        self.assertEqual(message.title, "Tïtle")
        self.assertEqual(message.body, ["", "Bödy 1", "Body 2"])
        self.assertEqual(message.full, "Tïtle\n\nBödy 1\nBody 2")
        self.assertEqual(message.original, "Tïtle\n\nBödy 1\näCömment\nBody 2")
Ejemplo n.º 4
0
    def test_commit_msg_custom_commentchar(self):
        with patch.object(GitCommitMessage, 'COMMENT_CHAR', new_callable=PropertyMock) as comment_char_mock:
            comment_char_mock.return_value = u"ä"
            message = GitCommitMessage.from_full_message(u"Tïtle\n\nBödy 1\näCömment\nBody 2")

            self.assertEqual(message.title, u"Tïtle")
            self.assertEqual(message.body, ["", u"Bödy 1", "Body 2"])
            self.assertEqual(message.full, u"Tïtle\n\nBödy 1\nBody 2")
            self.assertEqual(message.original, u"Tïtle\n\nBödy 1\näCömment\nBody 2")
Ejemplo n.º 5
0
    def test_gitcommit_equality(self, git):
        # git will be called to setup the context (commentchar and current_branch), just return the same value
        # This only matters to test gitcontext equality, not gitcommit equality
        git.return_value = "foöbar"

        # Test simple equality case
        now = datetime.datetime.utcnow()
        context1 = GitContext()
        commit_message1 = GitCommitMessage(context1, "tëst\n\nfoo", "tëst\n\nfoo", "tēst", ["", "föo"])
        commit1 = GitCommit(context1, commit_message1, "shä", now, "Jöhn Smith", "jö[email protected]", None,
                            ["föo/bar"], ["brånch1", "brånch2"])
        context1.commits = [commit1]

        context2 = GitContext()
        commit_message2 = GitCommitMessage(context2, "tëst\n\nfoo", "tëst\n\nfoo", "tēst", ["", "föo"])
        commit2 = GitCommit(context2, commit_message1, "shä", now, "Jöhn Smith", "jö[email protected]", None,
                            ["föo/bar"], ["brånch1", "brånch2"])
        context2.commits = [commit2]

        self.assertEqual(context1, context2)
        self.assertEqual(commit_message1, commit_message2)
        self.assertEqual(commit1, commit2)

        # Check that objects are unequal when changing a single attribute
        kwargs = {'message': commit1.message, 'sha': commit1.sha, 'date': commit1.date,
                  'author_name': commit1.author_name, 'author_email': commit1.author_email, 'parents': commit1.parents,
                  'changed_files': commit1.changed_files, 'branches': commit1.branches}

        self.object_equality_test(commit1, kwargs.keys(), {"context": commit1.context})

        # Check that the is_* attributes that are affected by the commit message affect equality
        special_messages = {'is_merge_commit': "Merge: foöbar", 'is_fixup_commit': "fixup! foöbar",
                            'is_squash_commit': "squash! foöbar", 'is_revert_commit': "Revert: foöbar"}
        for key in special_messages:
            kwargs_copy = copy.deepcopy(kwargs)
            clone1 = GitCommit(context=commit1.context, **kwargs_copy)
            clone1.message = GitCommitMessage.from_full_message(context1, special_messages[key])
            self.assertTrue(getattr(clone1, key))

            clone2 = GitCommit(context=commit1.context, **kwargs_copy)
            clone2.message = GitCommitMessage.from_full_message(context1, "foöbar")
            self.assertNotEqual(clone1, clone2)