diff options
Diffstat (limited to '')
-rw-r--r-- | gitlint/tests/test_hooks.py | 35 |
1 files changed, 15 insertions, 20 deletions
diff --git a/gitlint/tests/test_hooks.py b/gitlint/tests/test_hooks.py index 62f55e5..0ce5040 100644 --- a/gitlint/tests/test_hooks.py +++ b/gitlint/tests/test_hooks.py @@ -2,12 +2,7 @@ import os -try: - # python 2.x - from mock import patch, ANY, mock_open -except ImportError: - # python 3.x - from unittest.mock import patch, ANY, mock_open # pylint: disable=no-name-in-module, import-error +from unittest.mock import patch, ANY, mock_open from gitlint.tests.base import BaseTestCase from gitlint.config import LintConfig @@ -19,7 +14,7 @@ class HookTests(BaseTestCase): @patch('gitlint.hooks.git_hooks_dir') def test_commit_msg_hook_path(self, git_hooks_dir): - git_hooks_dir.return_value = os.path.join(u"/föo", u"bar") + git_hooks_dir.return_value = os.path.join("/föo", "bar") lint_config = LintConfig() lint_config.target = self.SAMPLES_DIR expected_path = os.path.join(git_hooks_dir.return_value, COMMIT_MSG_HOOK_DST_PATH) @@ -37,8 +32,8 @@ class HookTests(BaseTestCase): @patch('gitlint.hooks.git_hooks_dir') def test_install_commit_msg_hook(git_hooks_dir, isdir, path_exists, copy, stat, chmod): lint_config = LintConfig() - lint_config.target = os.path.join(u"/hür", u"dur") - git_hooks_dir.return_value = os.path.join(u"/föo", u"bar", ".git", "hooks") + lint_config.target = os.path.join("/hür", "dur") + git_hooks_dir.return_value = os.path.join("/föo", "bar", ".git", "hooks") expected_dst = os.path.join(git_hooks_dir.return_value, COMMIT_MSG_HOOK_DST_PATH) GitHookInstaller.install_commit_msg_hook(lint_config) isdir.assert_called_with(git_hooks_dir.return_value) @@ -54,11 +49,11 @@ class HookTests(BaseTestCase): @patch('gitlint.hooks.git_hooks_dir') def test_install_commit_msg_hook_negative(self, git_hooks_dir, isdir, path_exists, copy): lint_config = LintConfig() - lint_config.target = os.path.join(u"/hür", u"dur") - git_hooks_dir.return_value = os.path.join(u"/föo", u"bar", ".git", "hooks") + lint_config.target = os.path.join("/hür", "dur") + git_hooks_dir.return_value = os.path.join("/föo", "bar", ".git", "hooks") # mock that current dir is not a git repo isdir.return_value = False - expected_msg = u"{0} is not a git repository.".format(lint_config.target) + expected_msg = f"{lint_config.target} is not a git repository." with self.assertRaisesMessage(GitHookInstallerError, expected_msg): GitHookInstaller.install_commit_msg_hook(lint_config) isdir.assert_called_with(git_hooks_dir.return_value) @@ -69,7 +64,7 @@ class HookTests(BaseTestCase): isdir.return_value = True path_exists.return_value = True expected_dst = os.path.join(git_hooks_dir.return_value, COMMIT_MSG_HOOK_DST_PATH) - expected_msg = u"There is already a commit-msg hook file present in {0}.\n".format(expected_dst) + \ + expected_msg = f"There is already a commit-msg hook file present in {expected_dst}.\n" + \ "gitlint currently does not support appending to an existing commit-msg file." with self.assertRaisesMessage(GitHookInstallerError, expected_msg): GitHookInstaller.install_commit_msg_hook(lint_config) @@ -81,8 +76,8 @@ class HookTests(BaseTestCase): @patch('gitlint.hooks.git_hooks_dir') def test_uninstall_commit_msg_hook(git_hooks_dir, isdir, path_exists, remove): lint_config = LintConfig() - git_hooks_dir.return_value = os.path.join(u"/föo", u"bar", ".git", "hooks") - lint_config.target = os.path.join(u"/hür", u"dur") + git_hooks_dir.return_value = os.path.join("/föo", "bar", ".git", "hooks") + lint_config.target = os.path.join("/hür", "dur") read_data = "#!/bin/sh\n" + GITLINT_HOOK_IDENTIFIER with patch('gitlint.hooks.io.open', mock_open(read_data=read_data), create=True): GitHookInstaller.uninstall_commit_msg_hook(lint_config) @@ -99,12 +94,12 @@ class HookTests(BaseTestCase): @patch('gitlint.hooks.git_hooks_dir') def test_uninstall_commit_msg_hook_negative(self, git_hooks_dir, isdir, path_exists, remove): lint_config = LintConfig() - lint_config.target = os.path.join(u"/hür", u"dur") - git_hooks_dir.return_value = os.path.join(u"/föo", u"bar", ".git", "hooks") + lint_config.target = os.path.join("/hür", "dur") + git_hooks_dir.return_value = os.path.join("/föo", "bar", ".git", "hooks") # mock that the current directory is not a git repo isdir.return_value = False - expected_msg = u"{0} is not a git repository.".format(lint_config.target) + expected_msg = f"{lint_config.target} is not a git repository." with self.assertRaisesMessage(GitHookInstallerError, expected_msg): GitHookInstaller.uninstall_commit_msg_hook(lint_config) isdir.assert_called_with(git_hooks_dir.return_value) @@ -115,7 +110,7 @@ class HookTests(BaseTestCase): isdir.return_value = True path_exists.return_value = False expected_dst = os.path.join(git_hooks_dir.return_value, COMMIT_MSG_HOOK_DST_PATH) - expected_msg = u"There is no commit-msg hook present in {0}.".format(expected_dst) + expected_msg = f"There is no commit-msg hook present in {expected_dst}." with self.assertRaisesMessage(GitHookInstallerError, expected_msg): GitHookInstaller.uninstall_commit_msg_hook(lint_config) isdir.assert_called_with(git_hooks_dir.return_value) @@ -127,7 +122,7 @@ class HookTests(BaseTestCase): path_exists.return_value = True read_data = "#!/bin/sh\nfoo" expected_dst = os.path.join(git_hooks_dir.return_value, COMMIT_MSG_HOOK_DST_PATH) - expected_msg = u"The commit-msg hook in {0} was not installed by gitlint ".format(expected_dst) + \ + expected_msg = f"The commit-msg hook in {expected_dst} was not installed by gitlint " + \ "(or it was modified).\nUninstallation of 3th party or modified gitlint hooks " + \ "is not supported." with patch('gitlint.hooks.io.open', mock_open(read_data=read_data), create=True): |