Merging upstream version 2.19.0.
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
3a31212338
commit
596669cb31
53 changed files with 392 additions and 131 deletions
|
@ -122,8 +122,8 @@ def test_validate_config_old_list_format_ok(tmpdir, cap_out):
|
|||
f = tmpdir.join('cfg.yaml')
|
||||
f.write('- {repo: meta, hooks: [{id: identity}]}')
|
||||
assert not validate_config_main((f.strpath,))
|
||||
start = '[WARNING] normalizing pre-commit configuration to a top-level map'
|
||||
assert cap_out.get().startswith(start)
|
||||
msg = '[WARNING] normalizing pre-commit configuration to a top-level map'
|
||||
assert msg in cap_out.get()
|
||||
|
||||
|
||||
def test_validate_warn_on_unknown_keys_at_repo_level(tmpdir, caplog):
|
||||
|
@ -139,6 +139,12 @@ def test_validate_warn_on_unknown_keys_at_repo_level(tmpdir, caplog):
|
|||
ret_val = validate_config_main((f.strpath,))
|
||||
assert not ret_val
|
||||
assert caplog.record_tuples == [
|
||||
(
|
||||
'pre_commit',
|
||||
logging.WARNING,
|
||||
'pre-commit-validate-config is deprecated -- '
|
||||
'use `pre-commit validate-config` instead.',
|
||||
),
|
||||
(
|
||||
'pre_commit',
|
||||
logging.WARNING,
|
||||
|
@ -162,6 +168,12 @@ def test_validate_warn_on_unknown_keys_at_top_level(tmpdir, caplog):
|
|||
ret_val = validate_config_main((f.strpath,))
|
||||
assert not ret_val
|
||||
assert caplog.record_tuples == [
|
||||
(
|
||||
'pre_commit',
|
||||
logging.WARNING,
|
||||
'pre-commit-validate-config is deprecated -- '
|
||||
'use `pre-commit validate-config` instead.',
|
||||
),
|
||||
(
|
||||
'pre_commit',
|
||||
logging.WARNING,
|
||||
|
|
|
@ -242,6 +242,18 @@ def test_run_ns_pre_push_new_branch_existing_rev(push_example):
|
|||
assert ns is None
|
||||
|
||||
|
||||
def test_run_ns_pre_push_ref_with_whitespace(push_example):
|
||||
src, src_head, clone, _ = push_example
|
||||
|
||||
with cwd(clone):
|
||||
args = ('origin', src)
|
||||
line = f'HEAD^{{/ }} {src_head} refs/heads/b2 {hook_impl.Z40}\n'
|
||||
stdin = line.encode()
|
||||
ns = hook_impl._run_ns('pre-push', False, args, stdin)
|
||||
|
||||
assert ns is None
|
||||
|
||||
|
||||
def test_pushing_orphan_branch(push_example):
|
||||
src, src_head, clone, _ = push_example
|
||||
|
||||
|
|
|
@ -67,8 +67,8 @@ def test_basic_get_default_version():
|
|||
assert helpers.basic_get_default_version() == C.DEFAULT
|
||||
|
||||
|
||||
def test_basic_healthy():
|
||||
assert helpers.basic_healthy(Prefix('.'), 'default') is True
|
||||
def test_basic_health_check():
|
||||
assert helpers.basic_health_check(Prefix('.'), 'default') is None
|
||||
|
||||
|
||||
def test_failed_setup_command_does_not_unicode_error():
|
||||
|
|
|
@ -62,7 +62,7 @@ def test_healthy_system_node(tmpdir):
|
|||
|
||||
prefix = Prefix(str(tmpdir))
|
||||
node.install_environment(prefix, 'system', ())
|
||||
assert node.healthy(prefix, 'system')
|
||||
assert node.health_check(prefix, 'system') is None
|
||||
|
||||
|
||||
@xfailif_windows # pragma: win32 no cover
|
||||
|
@ -78,10 +78,11 @@ def test_unhealthy_if_system_node_goes_missing(tmpdir):
|
|||
with envcontext.envcontext((path,)):
|
||||
prefix = Prefix(str(prefix_dir))
|
||||
node.install_environment(prefix, 'system', ())
|
||||
assert node.healthy(prefix, 'system')
|
||||
assert node.health_check(prefix, 'system') is None
|
||||
|
||||
node_bin.remove()
|
||||
assert not node.healthy(prefix, 'system')
|
||||
ret = node.health_check(prefix, 'system')
|
||||
assert ret == '`node --version` returned 127'
|
||||
|
||||
|
||||
@xfailif_windows # pragma: win32 no cover
|
||||
|
@ -101,7 +102,7 @@ def test_installs_without_links_outside_env(tmpdir):
|
|||
|
||||
prefix = Prefix(str(tmpdir))
|
||||
node.install_environment(prefix, 'system', ())
|
||||
assert node.healthy(prefix, 'system')
|
||||
assert node.health_check(prefix, 'system') is None
|
||||
|
||||
# this directory shouldn't exist, make sure we succeed without it existing
|
||||
cmd_output('rm', '-rf', str(tmpdir.join('node_modules')))
|
||||
|
|
|
@ -93,11 +93,11 @@ def test_healthy_default_creator(python_dir):
|
|||
python.install_environment(prefix, C.DEFAULT, ())
|
||||
|
||||
# should be healthy right after creation
|
||||
assert python.healthy(prefix, C.DEFAULT) is True
|
||||
assert python.health_check(prefix, C.DEFAULT) is None
|
||||
|
||||
# even if a `types.py` file exists, should still be healthy
|
||||
tmpdir.join('types.py').ensure()
|
||||
assert python.healthy(prefix, C.DEFAULT) is True
|
||||
assert python.health_check(prefix, C.DEFAULT) is None
|
||||
|
||||
|
||||
def test_healthy_venv_creator(python_dir):
|
||||
|
@ -107,7 +107,7 @@ def test_healthy_venv_creator(python_dir):
|
|||
with envcontext((('VIRTUALENV_CREATOR', 'venv'),)):
|
||||
python.install_environment(prefix, C.DEFAULT, ())
|
||||
|
||||
assert python.healthy(prefix, C.DEFAULT) is True
|
||||
assert python.health_check(prefix, C.DEFAULT) is None
|
||||
|
||||
|
||||
def test_unhealthy_python_goes_missing(python_dir):
|
||||
|
@ -119,7 +119,12 @@ def test_unhealthy_python_goes_missing(python_dir):
|
|||
py_exe = prefix.path(python.bin_dir('py_env-default'), exe_name)
|
||||
os.remove(py_exe)
|
||||
|
||||
assert python.healthy(prefix, C.DEFAULT) is False
|
||||
ret = python.health_check(prefix, C.DEFAULT)
|
||||
assert ret == (
|
||||
f'virtualenv python version did not match created version:\n'
|
||||
f'- actual version: <<error retrieving version from {py_exe}>>\n'
|
||||
f'- expected version: {python._version_info(sys.executable)}\n'
|
||||
)
|
||||
|
||||
|
||||
def test_unhealthy_with_version_change(python_dir):
|
||||
|
@ -127,10 +132,15 @@ def test_unhealthy_with_version_change(python_dir):
|
|||
|
||||
python.install_environment(prefix, C.DEFAULT, ())
|
||||
|
||||
with open(prefix.path('py_env-default/pyvenv.cfg'), 'w') as f:
|
||||
with open(prefix.path('py_env-default/pyvenv.cfg'), 'a+') as f:
|
||||
f.write('version_info = 1.2.3\n')
|
||||
|
||||
assert python.healthy(prefix, C.DEFAULT) is False
|
||||
ret = python.health_check(prefix, C.DEFAULT)
|
||||
assert ret == (
|
||||
f'virtualenv python version did not match created version:\n'
|
||||
f'- actual version: {python._version_info(sys.executable)}\n'
|
||||
f'- expected version: 1.2.3\n'
|
||||
)
|
||||
|
||||
|
||||
def test_unhealthy_system_version_changes(python_dir):
|
||||
|
@ -141,7 +151,12 @@ def test_unhealthy_system_version_changes(python_dir):
|
|||
with open(prefix.path('py_env-default/pyvenv.cfg'), 'a') as f:
|
||||
f.write('base-executable = /does/not/exist\n')
|
||||
|
||||
assert python.healthy(prefix, C.DEFAULT) is False
|
||||
ret = python.health_check(prefix, C.DEFAULT)
|
||||
assert ret == (
|
||||
f'base executable python version does not match created version:\n'
|
||||
f'- base-executable version: <<error retrieving version from /does/not/exist>>\n' # noqa: E501
|
||||
f'- expected version: {python._version_info(sys.executable)}\n'
|
||||
)
|
||||
|
||||
|
||||
def test_unhealthy_old_virtualenv(python_dir):
|
||||
|
@ -152,7 +167,21 @@ def test_unhealthy_old_virtualenv(python_dir):
|
|||
# simulate "old" virtualenv by deleting this file
|
||||
os.remove(prefix.path('py_env-default/pyvenv.cfg'))
|
||||
|
||||
assert python.healthy(prefix, C.DEFAULT) is False
|
||||
ret = python.health_check(prefix, C.DEFAULT)
|
||||
assert ret == 'pyvenv.cfg does not exist (old virtualenv?)'
|
||||
|
||||
|
||||
def test_unhealthy_unexpected_pyvenv(python_dir):
|
||||
prefix, tmpdir = python_dir
|
||||
|
||||
python.install_environment(prefix, C.DEFAULT, ())
|
||||
|
||||
# simulate a buggy environment build (I don't think this is possible)
|
||||
with open(prefix.path('py_env-default/pyvenv.cfg'), 'w'):
|
||||
pass
|
||||
|
||||
ret = python.health_check(prefix, C.DEFAULT)
|
||||
assert ret == "created virtualenv's pyvenv.cfg is missing `version_info`"
|
||||
|
||||
|
||||
def test_unhealthy_then_replaced(python_dir):
|
||||
|
@ -170,9 +199,14 @@ def test_unhealthy_then_replaced(python_dir):
|
|||
make_executable(py_exe)
|
||||
|
||||
# should be unhealthy due to version mismatch
|
||||
assert python.healthy(prefix, C.DEFAULT) is False
|
||||
ret = python.health_check(prefix, C.DEFAULT)
|
||||
assert ret == (
|
||||
f'virtualenv python version did not match created version:\n'
|
||||
f'- actual version: 1.2.3\n'
|
||||
f'- expected version: {python._version_info(sys.executable)}\n'
|
||||
)
|
||||
|
||||
# now put the exe back and it should be healthy again
|
||||
os.replace(f'{py_exe}.tmp', py_exe)
|
||||
|
||||
assert python.healthy(prefix, C.DEFAULT) is True
|
||||
assert python.health_check(prefix, C.DEFAULT) is None
|
||||
|
|
|
@ -79,6 +79,7 @@ def test_adjust_args_try_repo_repo_relative(in_git_dir):
|
|||
FNS = (
|
||||
'autoupdate', 'clean', 'gc', 'hook_impl', 'install', 'install_hooks',
|
||||
'migrate_config', 'run', 'sample_config', 'uninstall',
|
||||
'validate_config', 'validate_manifest',
|
||||
)
|
||||
CMDS = tuple(fn.replace('_', '-') for fn in FNS)
|
||||
|
||||
|
|
|
@ -173,6 +173,7 @@ def test_python_venv(tempdir_factory, store):
|
|||
)
|
||||
|
||||
|
||||
@xfailif_windows # pragma: win32 no cover # no python 2 in GHA
|
||||
def test_switch_language_versions_doesnt_clobber(tempdir_factory, store):
|
||||
# We're using the python3 repo because it prints the python version
|
||||
path = make_repo(tempdir_factory, 'python3_hooks_repo')
|
||||
|
@ -667,7 +668,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 = ['golang.org/x/example/hello']
|
||||
deps = ['golang.org/x/example/hello@latest']
|
||||
config['hooks'][0]['additional_dependencies'] = deps
|
||||
hook = _get_hook(config, store, 'golang-hook')
|
||||
binaries = os.listdir(
|
||||
|
@ -688,7 +689,7 @@ def test_local_golang_additional_dependencies(store):
|
|||
'name': 'hello',
|
||||
'entry': 'hello',
|
||||
'language': 'golang',
|
||||
'additional_dependencies': ['golang.org/x/example/hello'],
|
||||
'additional_dependencies': ['golang.org/x/example/hello@latest'],
|
||||
}],
|
||||
}
|
||||
hook = _get_hook(config, store, 'hello')
|
||||
|
@ -892,6 +893,7 @@ def test_local_python_repo(store, local_python_config):
|
|||
assert _norm_out(out) == b"3\n['filename']\nHello World\n"
|
||||
|
||||
|
||||
@xfailif_windows # pragma: win32 no cover # no python2 in GHA
|
||||
def test_local_python_repo_python2(store, local_python_config):
|
||||
local_python_config['hooks'][0]['language_version'] = 'python2'
|
||||
hook = _get_hook(local_python_config, store, 'python3-hook')
|
||||
|
@ -1042,6 +1044,7 @@ def test_local_perl_additional_dependencies(store):
|
|||
(
|
||||
'dotnet_hooks_csproj_repo',
|
||||
'dotnet_hooks_sln_repo',
|
||||
'dotnet_hooks_combo_repo',
|
||||
),
|
||||
)
|
||||
def test_dotnet_hook(tempdir_factory, store, repo):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue