diff options
Diffstat (limited to '')
-rw-r--r-- | gitlint/tests/git/test_git.py | 45 |
1 files changed, 19 insertions, 26 deletions
diff --git a/gitlint/tests/git/test_git.py b/gitlint/tests/git/test_git.py index 1830119..7b9b7c6 100644 --- a/gitlint/tests/git/test_git.py +++ b/gitlint/tests/git/test_git.py @@ -1,12 +1,7 @@ # -*- coding: utf-8 -*- import os -try: - # python 2.x - from mock import patch -except ImportError: - # python 3.x - from unittest.mock import patch # pylint: disable=no-name-in-module, import-error +from unittest.mock import patch from gitlint.shell import ErrorReturnCode, CommandNotFound @@ -19,7 +14,7 @@ class GitTests(BaseTestCase): # Expected special_args passed to 'sh' expected_sh_special_args = { '_tty_out': False, - '_cwd': u"fåke/path" + '_cwd': "fåke/path" } @patch('gitlint.git.sh') @@ -28,7 +23,7 @@ class GitTests(BaseTestCase): 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.assertRaisesMessage(GitNotInstalledError, expected_msg): - GitContext.from_local_repository(u"fåke/path") + GitContext.from_local_repository("fåke/path") # assert that commit message was read using git command sh.git.assert_called_once_with("log", "-1", "--pretty=%H", **self.expected_sh_special_args) @@ -39,8 +34,8 @@ 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.assertRaisesMessage(GitContextError, u"fåke/path is not a git repository."): - GitContext.from_local_repository(u"fåke/path") + with self.assertRaisesMessage(GitContextError, "fåke/path is not a git repository."): + GitContext.from_local_repository("fåke/path") # assert that commit message was read using git command sh.git.assert_called_once_with("log", "-1", "--pretty=%H", **self.expected_sh_special_args) @@ -49,9 +44,9 @@ class GitTests(BaseTestCase): err = b"fatal: Random git error" 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) + expected_msg = f"An error occurred while executing 'git log -1 --pretty=%H': {err}" with self.assertRaisesMessage(GitContextError, expected_msg): - GitContext.from_local_repository(u"fåke/path") + GitContext.from_local_repository("fåke/path") # assert that commit message was read using git command sh.git.assert_called_once_with("log", "-1", "--pretty=%H", **self.expected_sh_special_args) @@ -63,9 +58,9 @@ 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." + expected_msg = "Current branch has no commits. Gitlint requires at least one commit to function." with self.assertRaisesMessage(GitContextError, expected_msg): - GitContext.from_local_repository(u"fåke/path") + GitContext.from_local_repository("fåke/path") # assert that commit message was read using git command sh.git.assert_called_once_with("log", "-1", "--pretty=%H", **self.expected_sh_special_args) @@ -78,12 +73,12 @@ class GitTests(BaseTestCase): b"'git <command> [<revision>...] -- [<file>...]'") sh.git.side_effect = [ - u"#\n", # git config --get core.commentchar + "#\n", # git config --get core.commentchar ErrorReturnCode("rev-parse --abbrev-ref HEAD", b"", err) ] with self.assertRaisesMessage(GitContextError, expected_msg): - context = GitContext.from_commit_msg(u"test") + context = GitContext.from_commit_msg("test") context.current_branch # assert that commit message was read using git command @@ -95,21 +90,19 @@ class GitTests(BaseTestCase): self.assertEqual(git_commentchar(), "#") git.return_value.exit_code = 0 - git.return_value.__str__ = lambda _: u"ä" - git.return_value.__unicode__ = lambda _: u"ä" - self.assertEqual(git_commentchar(), u"ä") + git.return_value = "ä" + self.assertEqual(git_commentchar(), "ä") git.return_value = ';\n' - self.assertEqual(git_commentchar(os.path.join(u"/föo", u"bar")), ';') + self.assertEqual(git_commentchar(os.path.join("/föo", "bar")), ';') git.assert_called_with("config", "--get", "core.commentchar", _ok_code=[0, 1], - _cwd=os.path.join(u"/föo", u"bar")) + _cwd=os.path.join("/föo", "bar")) @patch("gitlint.git._git") def test_git_hooks_dir(self, git): - hooks_dir = os.path.join(u"föo", ".git", "hooks") - git.return_value.__str__ = lambda _: hooks_dir + "\n" - git.return_value.__unicode__ = lambda _: hooks_dir + "\n" - self.assertEqual(git_hooks_dir(u"/blä"), os.path.abspath(os.path.join(u"/blä", hooks_dir))) + hooks_dir = os.path.join("föo", ".git", "hooks") + git.return_value = hooks_dir + "\n" + self.assertEqual(git_hooks_dir("/blä"), os.path.abspath(os.path.join("/blä", hooks_dir))) - git.assert_called_once_with("rev-parse", "--git-path", "hooks", _cwd=u"/blä") + git.assert_called_once_with("rev-parse", "--git-path", "hooks", _cwd="/blä") |