Exemplo 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)
Exemplo n.º 2
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)
Exemplo n.º 3
0
    def test_gitcontext_equality(self, sh):

        sh.git.side_effect = [
            u"û\n",  # context1: git config --get core.commentchar
            u"û\n",  # context2: git config --get core.commentchar
            u"my-brånch\n",  # context1: git rev-parse --abbrev-ref HEAD
            u"my-brånch\n",  # context2: git rev-parse --abbrev-ref HEAD
        ]

        context1 = GitContext(u"fåke/path")
        context1.commits = [
            u"fōo", u"bår"
        ]  # we don't need real commits to check for equality

        context2 = GitContext(u"fåke/path")
        context2.commits = [u"fōo", u"bår"]
        self.assertEqual(context1, context2)

        # INEQUALITY
        # Different commits
        context2.commits = [u"hür", u"dür"]
        self.assertNotEqual(context1, context2)

        # Different repository_path
        context2.commits = context1.commits
        context2.repository_path = u"ōther/path"
        self.assertNotEqual(context1, context2)

        # Different comment_char
        context3 = GitContext(u"fåke/path")
        context3.commits = [u"fōo", u"bår"]
        sh.git.side_effect = ([
            u"ç\n",  # context3: git config --get core.commentchar
            u"my-brånch\n"  # context3: git rev-parse --abbrev-ref HEAD
        ])
        self.assertNotEqual(context1, context3)

        # Different current_branch
        context4 = GitContext(u"fåke/path")
        context4.commits = [u"fōo", u"bår"]
        sh.git.side_effect = ([
            u"û\n",  # context4: git config --get core.commentchar
            u"different-brånch\n"  # context4: git rev-parse --abbrev-ref HEAD
        ])
        self.assertNotEqual(context1, context4)