From 5f208e04c159791e668031a7fa83f98724ec8d24 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Tue, 3 Nov 2020 07:07:45 +0100 Subject: Adding upstream version 0.14.0. Signed-off-by: Daniel Baumann --- gitlint/tests/git/test_git.py | 10 ++++----- gitlint/tests/git/test_git_commit.py | 40 ++++++++++++++++++++++++++++++++++-- 2 files changed, 43 insertions(+), 7 deletions(-) (limited to 'gitlint/tests/git') diff --git a/gitlint/tests/git/test_git.py b/gitlint/tests/git/test_git.py index 297b10c..1830119 100644 --- a/gitlint/tests/git/test_git.py +++ b/gitlint/tests/git/test_git.py @@ -27,7 +27,7 @@ class GitTests(BaseTestCase): sh.git.side_effect = CommandNotFound("git") expected_msg = "'git' command not found. You need to install git to use gitlint on a local repository. " + \ "See https://git-scm.com/book/en/v2/Getting-Started-Installing-Git on how to install git." - with self.assertRaisesRegex(GitNotInstalledError, expected_msg): + with self.assertRaisesMessage(GitNotInstalledError, expected_msg): GitContext.from_local_repository(u"fåke/path") # assert that commit message was read using git command @@ -39,7 +39,7 @@ class GitTests(BaseTestCase): err = b"fatal: Not a git repository (or any of the parent directories): .git" sh.git.side_effect = ErrorReturnCode("git log -1 --pretty=%H", b"", err) - with self.assertRaisesRegex(GitContextError, u"fåke/path is not a git repository."): + with self.assertRaisesMessage(GitContextError, u"fåke/path is not a git repository."): GitContext.from_local_repository(u"fåke/path") # assert that commit message was read using git command @@ -50,7 +50,7 @@ class GitTests(BaseTestCase): sh.git.side_effect = ErrorReturnCode("git log -1 --pretty=%H", b"", err) expected_msg = u"An error occurred while executing 'git log -1 --pretty=%H': {0}".format(err) - with self.assertRaisesRegex(GitContextError, expected_msg): + with self.assertRaisesMessage(GitContextError, expected_msg): GitContext.from_local_repository(u"fåke/path") # assert that commit message was read using git command @@ -64,7 +64,7 @@ class GitTests(BaseTestCase): sh.git.side_effect = ErrorReturnCode("git log -1 --pretty=%H", b"", err) expected_msg = u"Current branch has no commits. Gitlint requires at least one commit to function." - with self.assertRaisesRegex(GitContextError, expected_msg): + with self.assertRaisesMessage(GitContextError, expected_msg): GitContext.from_local_repository(u"fåke/path") # assert that commit message was read using git command @@ -82,7 +82,7 @@ class GitTests(BaseTestCase): ErrorReturnCode("rev-parse --abbrev-ref HEAD", b"", err) ] - with self.assertRaisesRegex(GitContextError, expected_msg): + with self.assertRaisesMessage(GitContextError, expected_msg): context = GitContext.from_commit_msg(u"test") context.current_branch diff --git a/gitlint/tests/git/test_git_commit.py b/gitlint/tests/git/test_git_commit.py index dc83ccb..5f87a8e 100644 --- a/gitlint/tests/git/test_git_commit.py +++ b/gitlint/tests/git/test_git_commit.py @@ -14,7 +14,9 @@ except ImportError: from unittest.mock import patch, call # pylint: disable=no-name-in-module, import-error from gitlint.tests.base import BaseTestCase -from gitlint.git import GitContext, GitCommit, LocalGitCommit, StagedLocalGitCommit, GitCommitMessage +from gitlint.git import GitContext, GitCommit, GitContextError, LocalGitCommit, StagedLocalGitCommit, GitCommitMessage +from gitlint.shell import ErrorReturnCode +from gitlint.utils import ustr class GitCommitTests(BaseTestCase): @@ -479,12 +481,46 @@ class GitCommitTests(BaseTestCase): self.assertListEqual(last_commit.changed_files, ["file1.txt", u"påth/to/file2.txt"]) self.assertListEqual(sh.git.mock_calls, expected_calls[0:5]) + @patch('gitlint.git.sh') + def test_staged_commit_with_missing_username(self, sh): + # StagedLocalGitCommit() + + sh.git.side_effect = [ + u"#", # git config --get core.commentchar + ErrorReturnCode('git config --get user.name', b"", b""), + ] + + expected_msg = "Missing git configuration: please set user.name" + with self.assertRaisesMessage(GitContextError, expected_msg): + ctx = GitContext.from_staged_commit(u"Foōbar 123\n\ncömmit-body\n", u"fåke/path") + [ustr(commit) for commit in ctx.commits] + + @patch('gitlint.git.sh') + def test_staged_commit_with_missing_email(self, sh): + # StagedLocalGitCommit() + + sh.git.side_effect = [ + u"#", # git config --get core.commentchar + u"test åuthor\n", # git config --get user.name + ErrorReturnCode('git config --get user.name', b"", b""), + ] + + expected_msg = "Missing git configuration: please set user.email" + with self.assertRaisesMessage(GitContextError, expected_msg): + ctx = GitContext.from_staged_commit(u"Foōbar 123\n\ncömmit-body\n", u"fåke/path") + [ustr(commit) for commit in ctx.commits] + 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}) - def test_gitcommit_equality(self): + @patch("gitlint.git._git") + 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 = u"foöbar" + # Test simple equality case now = datetime.datetime.utcnow() context1 = GitContext() -- cgit v1.2.3