From f3b6c222fb11c96e2f8bbaa0622f46c8ec486874 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 19 Nov 2022 15:52:50 +0100 Subject: Merging upstream version 0.18.0. Signed-off-by: Daniel Baumann --- gitlint-core/gitlint/tests/test_hooks.py | 68 +++++++++++++++++--------------- 1 file changed, 37 insertions(+), 31 deletions(-) (limited to 'gitlint-core/gitlint/tests/test_hooks.py') diff --git a/gitlint-core/gitlint/tests/test_hooks.py b/gitlint-core/gitlint/tests/test_hooks.py index 0ce5040..f92b148 100644 --- a/gitlint-core/gitlint/tests/test_hooks.py +++ b/gitlint-core/gitlint/tests/test_hooks.py @@ -1,18 +1,20 @@ -# -*- coding: utf-8 -*- - import os from unittest.mock import patch, ANY, mock_open from gitlint.tests.base import BaseTestCase from gitlint.config import LintConfig -from gitlint.hooks import GitHookInstaller, GitHookInstallerError, COMMIT_MSG_HOOK_SRC_PATH, COMMIT_MSG_HOOK_DST_PATH, \ - GITLINT_HOOK_IDENTIFIER +from gitlint.hooks import ( + GitHookInstaller, + GitHookInstallerError, + COMMIT_MSG_HOOK_SRC_PATH, + COMMIT_MSG_HOOK_DST_PATH, + GITLINT_HOOK_IDENTIFIER, +) class HookTests(BaseTestCase): - - @patch('gitlint.hooks.git_hooks_dir') + @patch("gitlint.hooks.git_hooks_dir") def test_commit_msg_hook_path(self, git_hooks_dir): git_hooks_dir.return_value = os.path.join("/föo", "bar") lint_config = LintConfig() @@ -24,12 +26,12 @@ class HookTests(BaseTestCase): self.assertEqual(path, expected_path) @staticmethod - @patch('os.chmod') - @patch('os.stat') - @patch('gitlint.hooks.shutil.copy') - @patch('os.path.exists', return_value=False) - @patch('os.path.isdir', return_value=True) - @patch('gitlint.hooks.git_hooks_dir') + @patch("os.chmod") + @patch("os.stat") + @patch("gitlint.hooks.shutil.copy") + @patch("os.path.exists", return_value=False) + @patch("os.path.isdir", return_value=True) + @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("/hür", "dur") @@ -43,10 +45,10 @@ class HookTests(BaseTestCase): chmod.assert_called_once_with(expected_dst, ANY) git_hooks_dir.assert_called_with(lint_config.target) - @patch('gitlint.hooks.shutil.copy') - @patch('os.path.exists', return_value=False) - @patch('os.path.isdir', return_value=True) - @patch('gitlint.hooks.git_hooks_dir') + @patch("gitlint.hooks.shutil.copy") + @patch("os.path.exists", return_value=False) + @patch("os.path.isdir", return_value=True) + @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("/hür", "dur") @@ -64,22 +66,24 @@ 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 = 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." + 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) @staticmethod - @patch('os.remove') - @patch('os.path.exists', return_value=True) - @patch('os.path.isdir', return_value=True) - @patch('gitlint.hooks.git_hooks_dir') + @patch("os.remove") + @patch("os.path.exists", return_value=True) + @patch("os.path.isdir", return_value=True) + @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("/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): + with patch("builtins.open", mock_open(read_data=read_data), create=True): GitHookInstaller.uninstall_commit_msg_hook(lint_config) expected_dst = os.path.join(git_hooks_dir.return_value, COMMIT_MSG_HOOK_DST_PATH) @@ -88,10 +92,10 @@ class HookTests(BaseTestCase): remove.assert_called_with(expected_dst) git_hooks_dir.assert_called_with(lint_config.target) - @patch('os.remove') - @patch('os.path.exists', return_value=True) - @patch('os.path.isdir', return_value=True) - @patch('gitlint.hooks.git_hooks_dir') + @patch("os.remove") + @patch("os.path.exists", return_value=True) + @patch("os.path.isdir", return_value=True) + @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("/hür", "dur") @@ -122,10 +126,12 @@ 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 = 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): + 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("builtins.open", mock_open(read_data=read_data), create=True): with self.assertRaisesMessage(GitHookInstallerError, expected_msg): GitHookInstaller.uninstall_commit_msg_hook(lint_config) remove.assert_not_called() -- cgit v1.2.3