summaryrefslogtreecommitdiffstats
path: root/tests/repository_test.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2023-03-19 10:19:03 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2023-03-19 10:19:03 +0000
commitccce8747ac9170ce98d535ef527caa8867e5eef4 (patch)
tree6271d025d1f560e64d494c7a609daf2ba3e0f048 /tests/repository_test.py
parentAdding upstream version 3.1.1. (diff)
downloadpre-commit-ccce8747ac9170ce98d535ef527caa8867e5eef4.tar.xz
pre-commit-ccce8747ac9170ce98d535ef527caa8867e5eef4.zip
Adding upstream version 3.2.0.upstream/3.2.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/repository_test.py')
-rw-r--r--tests/repository_test.py87
1 files changed, 32 insertions, 55 deletions
diff --git a/tests/repository_test.py b/tests/repository_test.py
index 9e5d9d6..b8dde99 100644
--- a/tests/repository_test.py
+++ b/tests/repository_test.py
@@ -1,7 +1,9 @@
from __future__ import annotations
import os.path
+import shlex
import shutil
+import sys
from typing import Any
from unittest import mock
@@ -16,6 +18,7 @@ from pre_commit.clientlib import CONFIG_SCHEMA
from pre_commit.clientlib import load_manifest
from pre_commit.hook import Hook
from pre_commit.languages import python
+from pre_commit.languages import system
from pre_commit.prefix import Prefix
from pre_commit.repository import _hook_installed
from pre_commit.repository import all_hooks
@@ -79,51 +82,6 @@ def _test_hook_repo(
assert out == expected
-def test_python_hook(tempdir_factory, store):
- _test_hook_repo(
- tempdir_factory, store, 'python_hooks_repo',
- 'foo', [os.devnull],
- f'[{os.devnull!r}]\nHello World\n'.encode(),
- )
-
-
-def test_python_hook_default_version(tempdir_factory, store):
- # make sure that this continues to work for platforms where default
- # language detection does not work
- with mock.patch.object(
- python,
- 'get_default_version',
- return_value=C.DEFAULT,
- ):
- test_python_hook(tempdir_factory, store)
-
-
-def test_python_hook_args_with_spaces(tempdir_factory, store):
- _test_hook_repo(
- tempdir_factory, store, 'python_hooks_repo',
- 'foo',
- [],
- b"['i have spaces', 'and\"\\'quotes', '$and !this']\n"
- b'Hello World\n',
- config_kwargs={
- 'hooks': [{
- 'id': 'foo',
- 'args': ['i have spaces', 'and"\'quotes', '$and !this'],
- }],
- },
- )
-
-
-def test_python_hook_weird_setup_cfg(in_git_dir, tempdir_factory, store):
- in_git_dir.join('setup.cfg').write('[install]\ninstall_scripts=/usr/sbin')
-
- _test_hook_repo(
- tempdir_factory, store, 'python_hooks_repo',
- 'foo', [os.devnull],
- f'[{os.devnull!r}]\nHello World\n'.encode(),
- )
-
-
def test_python_venv_deprecation(store, caplog):
config = {
'repo': 'local',
@@ -198,7 +156,7 @@ def test_intermixed_stdout_stderr(tempdir_factory, store):
)
-@pytest.mark.xfail(os.name == 'nt', reason='ptys are posix-only')
+@pytest.mark.xfail(sys.platform == 'win32', reason='ptys are posix-only')
def test_output_isatty(tempdir_factory, store):
_test_hook_repo(
tempdir_factory, store, 'stdout_stderr_repo',
@@ -430,7 +388,7 @@ def test_local_python_repo(store, local_python_config):
def test_default_language_version(store, local_python_config):
config: dict[str, Any] = {
'default_language_version': {'python': 'fake'},
- 'default_stages': ['commit'],
+ 'default_stages': ['pre-commit'],
'repos': [local_python_config],
}
@@ -447,18 +405,18 @@ def test_default_language_version(store, local_python_config):
def test_default_stages(store, local_python_config):
config: dict[str, Any] = {
'default_language_version': {'python': C.DEFAULT},
- 'default_stages': ['commit'],
+ 'default_stages': ['pre-commit'],
'repos': [local_python_config],
}
# `stages` was not set, should default
hook, = all_hooks(config, store)
- assert hook.stages == ['commit']
+ assert hook.stages == ['pre-commit']
# `stages` is set, should not default
- config['repos'][0]['hooks'][0]['stages'] = ['push']
+ config['repos'][0]['hooks'][0]['stages'] = ['pre-push']
hook, = all_hooks(config, store)
- assert hook.stages == ['push']
+ assert hook.stages == ['pre-push']
def test_hook_id_not_present(tempdir_factory, store, caplog):
@@ -526,11 +484,19 @@ def test_manifest_hooks(tempdir_factory, store):
name='Bash hook',
pass_filenames=True,
require_serial=False,
- stages=(
- 'commit', 'merge-commit', 'prepare-commit-msg', 'commit-msg',
- 'post-commit', 'manual', 'post-checkout', 'push', 'post-merge',
+ stages=[
+ 'commit-msg',
+ 'post-checkout',
+ 'post-commit',
+ 'post-merge',
'post-rewrite',
- ),
+ 'pre-commit',
+ 'pre-merge-commit',
+ 'pre-push',
+ 'pre-rebase',
+ 'prepare-commit-msg',
+ 'manual',
+ ],
types=['file'],
types_or=[],
verbose=False,
@@ -582,3 +548,14 @@ def test_non_installable_hook_error_for_additional_dependencies(store, caplog):
'using language `system` which does not install an environment. '
'Perhaps you meant to use a specific language?'
)
+
+
+def test_args_with_spaces_and_quotes(tmp_path):
+ ret = run_language(
+ tmp_path, system,
+ f"{shlex.quote(sys.executable)} -c 'import sys; print(sys.argv[1:])'",
+ ('i have spaces', 'and"\'quotes', '$and !this'),
+ )
+
+ expected = b"['i have spaces', 'and\"\\'quotes', '$and !this']\n"
+ assert ret == (0, expected)