summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2022-01-21 19:59:12 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2022-01-21 19:59:19 +0000
commitf280995a847850327b1a156bfba2068966b1acec (patch)
tree88a9d713cfdba9d743dfead659531357af244b8b /tests
parentReleasing debian version 2.16.0-1. (diff)
downloadpre-commit-f280995a847850327b1a156bfba2068966b1acec.tar.xz
pre-commit-f280995a847850327b1a156bfba2068966b1acec.zip
Merging upstream version 2.17.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--tests/clientlib_test.py17
-rw-r--r--tests/commands/install_uninstall_test.py43
-rw-r--r--tests/error_handler_test.py1
-rw-r--r--tests/languages/conda_test.py38
-rw-r--r--tests/languages/helpers_test.py4
-rw-r--r--tests/repository_test.py27
6 files changed, 86 insertions, 44 deletions
diff --git a/tests/clientlib_test.py b/tests/clientlib_test.py
index 5427b1d..39a3716 100644
--- a/tests/clientlib_test.py
+++ b/tests/clientlib_test.py
@@ -265,6 +265,11 @@ def test_warn_mutable_rev_conditional():
r"pre-commit normalizes slashes in the 'files' field in hook "
r"'flake8' to forward slashes, so you can use / instead of [/\\]",
),
+ (
+ r'dir[\\/].*\.py',
+ r"pre-commit normalizes slashes in the 'files' field in hook "
+ r"'flake8' to forward slashes, so you can use / instead of [\\/]",
+ ),
),
)
def test_validate_optional_sensible_regex_at_hook(caplog, regex, warning):
@@ -295,6 +300,11 @@ def test_validate_optional_sensible_regex_at_hook(caplog, regex, warning):
r"pre-commit normalizes the slashes in the top-level 'files' "
r'field to forward slashes, so you can use / instead of [/\\]',
),
+ (
+ r'dir[\\/].*\.py',
+ r"pre-commit normalizes the slashes in the top-level 'files' "
+ r'field to forward slashes, so you can use / instead of [\\/]',
+ ),
),
)
def test_validate_optional_sensible_regex_at_top_level(caplog, regex, warning):
@@ -413,6 +423,13 @@ def test_migrate_to_sha_ok():
{'repo': 'meta', 'hooks': [{'id': 'identity', 'language': 'python'}]},
# name override must be string
{'repo': 'meta', 'hooks': [{'id': 'identity', 'name': False}]},
+ pytest.param(
+ {
+ 'repo': 'meta',
+ 'hooks': [{'id': 'identity', 'entry': 'echo hi'}],
+ },
+ id='cannot override entry for meta hooks',
+ ),
),
)
def test_meta_hook_invalid(config_repo):
diff --git a/tests/commands/install_uninstall_test.py b/tests/commands/install_uninstall_test.py
index 8339903..0b2e248 100644
--- a/tests/commands/install_uninstall_test.py
+++ b/tests/commands/install_uninstall_test.py
@@ -1,19 +1,15 @@
import os.path
import re
-import sys
-from unittest import mock
import re_assert
import pre_commit.constants as C
from pre_commit import git
-from pre_commit.commands import install_uninstall
from pre_commit.commands.install_uninstall import CURRENT_HASH
from pre_commit.commands.install_uninstall import install
from pre_commit.commands.install_uninstall import install_hooks
from pre_commit.commands.install_uninstall import is_our_script
from pre_commit.commands.install_uninstall import PRIOR_HASHES
-from pre_commit.commands.install_uninstall import shebang
from pre_commit.commands.install_uninstall import uninstall
from pre_commit.parse_shebang import find_executable
from pre_commit.util import cmd_output
@@ -43,43 +39,6 @@ def test_is_previous_pre_commit(tmpdir):
assert is_our_script(f.strpath)
-def patch_platform(platform):
- return mock.patch.object(sys, 'platform', platform)
-
-
-def patch_lookup_path(path):
- return mock.patch.object(install_uninstall, 'POSIX_SEARCH_PATH', path)
-
-
-def patch_sys_exe(exe):
- return mock.patch.object(install_uninstall, 'SYS_EXE', exe)
-
-
-def test_shebang_windows():
- with patch_platform('win32'), patch_sys_exe('python'):
- assert shebang() == '#!/usr/bin/env python'
-
-
-def test_shebang_windows_drop_ext():
- with patch_platform('win32'), patch_sys_exe('python.exe'):
- assert shebang() == '#!/usr/bin/env python'
-
-
-def test_shebang_posix_not_on_path():
- with patch_platform('posix'), patch_lookup_path(()):
- with patch_sys_exe('python3.6'):
- assert shebang() == '#!/usr/bin/env python3.6'
-
-
-def test_shebang_posix_on_path(tmpdir):
- exe = tmpdir.join(f'python{sys.version_info[0]}').ensure()
- make_executable(exe)
-
- with patch_platform('posix'), patch_lookup_path((tmpdir.strpath,)):
- with patch_sys_exe('python'):
- assert shebang() == f'#!/usr/bin/env python{sys.version_info[0]}'
-
-
def test_install_pre_commit(in_git_dir, store):
assert not install(C.CONFIG_FILE, store, hook_types=['pre-commit'])
assert os.access(in_git_dir.join('.git/hooks/pre-commit').strpath, os.X_OK)
@@ -336,7 +295,7 @@ EXISTING_COMMIT_RUN = re_assert.Matches(
def _write_legacy_hook(path):
os.makedirs(os.path.join(path, '.git/hooks'), exist_ok=True)
with open(os.path.join(path, '.git/hooks/pre-commit'), 'w') as f:
- f.write(f'{shebang()}\nprint("legacy hook")\n')
+ f.write('#!/usr/bin/env bash\necho legacy hook\n')
make_executable(f.name)
diff --git a/tests/error_handler_test.py b/tests/error_handler_test.py
index 6b0bb86..cb76dcf 100644
--- a/tests/error_handler_test.py
+++ b/tests/error_handler_test.py
@@ -122,6 +122,7 @@ def test_log_and_exit(cap_out, mock_store_dir):
r'\n'
r'```\n'
r'pre-commit version: \d+\.\d+\.\d+\n'
+ r'git --version: git version .+\n'
r'sys.version:\n'
r'( .*\n)*'
r'sys.executable: .*\n'
diff --git a/tests/languages/conda_test.py b/tests/languages/conda_test.py
new file mode 100644
index 0000000..6faa78f
--- /dev/null
+++ b/tests/languages/conda_test.py
@@ -0,0 +1,38 @@
+import pytest
+
+from pre_commit import envcontext
+from pre_commit.languages.conda import _conda_exe
+
+
+@pytest.mark.parametrize(
+ ('ctx', 'expected'),
+ (
+ pytest.param(
+ (
+ ('PRE_COMMIT_USE_MICROMAMBA', envcontext.UNSET),
+ ('PRE_COMMIT_USE_MAMBA', envcontext.UNSET),
+ ),
+ 'conda',
+ id='default',
+ ),
+ pytest.param(
+ (
+ ('PRE_COMMIT_USE_MICROMAMBA', '1'),
+ ('PRE_COMMIT_USE_MAMBA', ''),
+ ),
+ 'micromamba',
+ id='default',
+ ),
+ pytest.param(
+ (
+ ('PRE_COMMIT_USE_MICROMAMBA', ''),
+ ('PRE_COMMIT_USE_MAMBA', '1'),
+ ),
+ 'mamba',
+ id='default',
+ ),
+ ),
+)
+def test_conda_exe(ctx, expected):
+ with envcontext.envcontext(ctx):
+ assert _conda_exe() == expected
diff --git a/tests/languages/helpers_test.py b/tests/languages/helpers_test.py
index 669cd33..fd9b9a4 100644
--- a/tests/languages/helpers_test.py
+++ b/tests/languages/helpers_test.py
@@ -72,8 +72,8 @@ def test_basic_healthy():
def test_failed_setup_command_does_not_unicode_error():
script = (
'import sys\n'
- "getattr(sys.stderr, 'buffer', sys.stderr).write(b'\\x81\\xfe')\n"
- 'exit(1)\n'
+ "sys.stderr.buffer.write(b'\\x81\\xfe')\n"
+ 'raise SystemExit(1)\n'
)
# an assertion that this does not raise `UnicodeError`
diff --git a/tests/repository_test.py b/tests/repository_test.py
index 36268e1..8569ba9 100644
--- a/tests/repository_test.py
+++ b/tests/repository_test.py
@@ -34,6 +34,7 @@ from testing.util import cwd
from testing.util import get_resource_path
from testing.util import skipif_cant_run_coursier
from testing.util import skipif_cant_run_docker
+from testing.util import skipif_cant_run_lua
from testing.util import skipif_cant_run_swift
from testing.util import xfailif_windows
@@ -1128,3 +1129,29 @@ 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?'
)
+
+
+@skipif_cant_run_lua # pragma: win32 no cover
+def test_lua_hook(tempdir_factory, store):
+ _test_hook_repo(
+ tempdir_factory, store, 'lua_repo',
+ 'hello-world-lua', [], b'hello world\n',
+ )
+
+
+@skipif_cant_run_lua # pragma: win32 no cover
+def test_local_lua_additional_dependencies(store):
+ config = {
+ 'repo': 'local',
+ 'hooks': [{
+ 'id': 'local-lua',
+ 'name': 'local-lua',
+ 'entry': 'luacheck --version',
+ 'language': 'lua',
+ 'additional_dependencies': ['luacheck'],
+ }],
+ }
+ hook = _get_hook(config, store, 'local-lua')
+ ret, out = _hook_run(hook, (), color=False)
+ assert b'Luacheck' in out
+ assert ret == 0