summaryrefslogtreecommitdiffstats
path: root/tests/repository_test.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/repository_test.py')
-rw-r--r--tests/repository_test.py65
1 files changed, 56 insertions, 9 deletions
diff --git a/tests/repository_test.py b/tests/repository_test.py
index d513cb7..8540db3 100644
--- a/tests/repository_test.py
+++ b/tests/repository_test.py
@@ -569,7 +569,7 @@ def test_additional_golang_dependencies_installed(
path = make_repo(tempdir_factory, 'golang_hooks_repo')
config = make_config_from_repo(path)
# A small go package
- deps = ['github.com/golang/example/hello']
+ deps = ['golang.org/x/example/hello']
config['hooks'][0]['additional_dependencies'] = deps
hook = _get_hook(config, store, 'golang-hook')
binaries = os.listdir(
@@ -590,7 +590,7 @@ def test_local_golang_additional_dependencies(store):
'name': 'hello',
'entry': 'hello',
'language': 'golang',
- 'additional_dependencies': ['github.com/golang/example/hello'],
+ 'additional_dependencies': ['golang.org/x/example/hello'],
}],
}
hook = _get_hook(config, store, 'hello')
@@ -640,7 +640,7 @@ def test_fail_hooks(store):
)
-def test_unknown_keys(store, fake_log_handler):
+def test_unknown_keys(store, caplog):
config = {
'repo': 'local',
'hooks': [{
@@ -653,8 +653,8 @@ def test_unknown_keys(store, fake_log_handler):
}],
}
_get_hook(config, store, 'too-much')
- expected = 'Unexpected key(s) present on local => too-much: foo, hello'
- assert fake_log_handler.handle.call_args[0][0].msg == expected
+ msg, = caplog.messages
+ assert msg == 'Unexpected key(s) present on local => too-much: foo, hello'
def test_reinstall(tempdir_factory, store, log_info_mock):
@@ -832,27 +832,28 @@ def test_default_stages(store, local_python_config):
assert hook.stages == ['push']
-def test_hook_id_not_present(tempdir_factory, store, fake_log_handler):
+def test_hook_id_not_present(tempdir_factory, store, caplog):
path = make_repo(tempdir_factory, 'script_hooks_repo')
config = make_config_from_repo(path)
config['hooks'][0]['id'] = 'i-dont-exist'
with pytest.raises(SystemExit):
_get_hook(config, store, 'i-dont-exist')
- assert fake_log_handler.handle.call_args[0][0].msg == (
+ _, msg = caplog.messages
+ assert msg == (
f'`i-dont-exist` is not present in repository file://{path}. '
f'Typo? Perhaps it is introduced in a newer version? '
f'Often `pre-commit autoupdate` fixes this.'
)
-def test_too_new_version(tempdir_factory, store, fake_log_handler):
+def test_too_new_version(tempdir_factory, store, caplog):
path = make_repo(tempdir_factory, 'script_hooks_repo')
with modify_manifest(path) as manifest:
manifest[0]['minimum_pre_commit_version'] = '999.0.0'
config = make_config_from_repo(path)
with pytest.raises(SystemExit):
_get_hook(config, store, 'bash_hook')
- msg = fake_log_handler.handle.call_args[0][0].msg
+ _, msg = caplog.messages
pattern = re_assert.Matches(
r'^The hook `bash_hook` requires pre-commit version 999\.0\.0 but '
r'version \d+\.\d+\.\d+ is installed. '
@@ -942,3 +943,49 @@ def test_dotnet_hook(tempdir_factory, store, repo):
tempdir_factory, store, repo,
'dotnet example hook', [], b'Hello from dotnet!\n',
)
+
+
+def test_non_installable_hook_error_for_language_version(store, caplog):
+ config = {
+ 'repo': 'local',
+ 'hooks': [{
+ 'id': 'system-hook',
+ 'name': 'system-hook',
+ 'language': 'system',
+ 'entry': 'python3 -c "import sys; print(sys.version)"',
+ 'language_version': 'python3.10',
+ }],
+ }
+ with pytest.raises(SystemExit) as excinfo:
+ _get_hook(config, store, 'system-hook')
+ assert excinfo.value.code == 1
+
+ msg, = caplog.messages
+ assert msg == (
+ 'The hook `system-hook` specifies `language_version` but is using '
+ 'language `system` which does not install an environment. '
+ 'Perhaps you meant to use a specific language?'
+ )
+
+
+def test_non_installable_hook_error_for_additional_dependencies(store, caplog):
+ config = {
+ 'repo': 'local',
+ 'hooks': [{
+ 'id': 'system-hook',
+ 'name': 'system-hook',
+ 'language': 'system',
+ 'entry': 'python3 -c "import sys; print(sys.version)"',
+ 'additional_dependencies': ['astpretty'],
+ }],
+ }
+ with pytest.raises(SystemExit) as excinfo:
+ _get_hook(config, store, 'system-hook')
+ assert excinfo.value.code == 1
+
+ msg, = caplog.messages
+ assert msg == (
+ 'The hook `system-hook` specifies `additional_dependencies` but is '
+ 'using language `system` which does not install an environment. '
+ 'Perhaps you meant to use a specific language?'
+ )