mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-04-16 02:21:46 +04:00
also avoid git users config usage for integration tests
This commit is contained in:
parent
5b472b30eb
commit
3593c76757
1 changed files with 82 additions and 84 deletions
|
|
@ -41,50 +41,49 @@ def _norm_out(b):
|
||||||
return b.replace(b'\r\n', b'\n')
|
return b.replace(b'\r\n', b'\n')
|
||||||
|
|
||||||
|
|
||||||
def _test_hook_repo(
|
@pytest.fixture(name='test_hook_repo')
|
||||||
tempdir_factory,
|
def test_hook_repo_fixture(tempdir_factory, store, setup_git):
|
||||||
store,
|
def do(repo_path,
|
||||||
repo_path,
|
hook_id,
|
||||||
hook_id,
|
args,
|
||||||
args,
|
expected,
|
||||||
expected,
|
expected_return_code=0,
|
||||||
expected_return_code=0,
|
config_kwargs=None):
|
||||||
config_kwargs=None,
|
path = make_repo(tempdir_factory, repo_path)
|
||||||
):
|
config = make_config_from_repo(path, **(config_kwargs or {}))
|
||||||
path = make_repo(tempdir_factory, repo_path)
|
repo = Repository.create(config, store)
|
||||||
config = make_config_from_repo(path, **(config_kwargs or {}))
|
|
||||||
repo = Repository.create(config, store)
|
hook_dict, = [hook for repo_hook_id, hook in repo.hooks if repo_hook_id == hook_id]
|
||||||
hook_dict, = [
|
ret = repo.run_hook(hook_dict, args)
|
||||||
hook for repo_hook_id, hook in repo.hooks if repo_hook_id == hook_id
|
assert ret[0] == expected_return_code
|
||||||
]
|
assert _norm_out(ret[1]) == expected
|
||||||
ret = repo.run_hook(hook_dict, args)
|
|
||||||
assert ret[0] == expected_return_code
|
return do
|
||||||
assert _norm_out(ret[1]) == expected
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.integration
|
@pytest.mark.integration
|
||||||
def test_python_hook(tempdir_factory, store):
|
def test_python_hook(test_hook_repo):
|
||||||
_test_hook_repo(
|
test_hook_repo(
|
||||||
tempdir_factory, store, 'python_hooks_repo',
|
'python_hooks_repo',
|
||||||
'foo', [os.devnull],
|
'foo', [os.devnull],
|
||||||
b"['" + five.to_bytes(os.devnull) + b"']\nHello World\n",
|
b"['" + five.to_bytes(os.devnull) + b"']\nHello World\n",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.integration
|
@pytest.mark.integration
|
||||||
def test_python_hook_default_version(tempdir_factory, store):
|
def test_python_hook_default_version(test_hook_repo):
|
||||||
# make sure that this continues to work for platforms where default
|
# make sure that this continues to work for platforms where default
|
||||||
# language detection does not work
|
# language detection does not work
|
||||||
with mock.patch.object(
|
with mock.patch.object(
|
||||||
python, 'get_default_version', return_value='default',
|
python, 'get_default_version', return_value='default',
|
||||||
):
|
):
|
||||||
test_python_hook(tempdir_factory, store)
|
test_python_hook(test_hook_repo)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.integration
|
@pytest.mark.integration
|
||||||
def test_python_hook_args_with_spaces(tempdir_factory, store):
|
def test_python_hook_args_with_spaces(test_hook_repo):
|
||||||
_test_hook_repo(
|
test_hook_repo(
|
||||||
tempdir_factory, store, 'python_hooks_repo',
|
'python_hooks_repo',
|
||||||
'foo',
|
'foo',
|
||||||
[],
|
[],
|
||||||
b"['i have spaces', 'and\"\\'quotes', '$and !this']\n"
|
b"['i have spaces', 'and\"\\'quotes', '$and !this']\n"
|
||||||
|
|
@ -99,13 +98,13 @@ def test_python_hook_args_with_spaces(tempdir_factory, store):
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.integration
|
@pytest.mark.integration
|
||||||
def test_python_hook_weird_setup_cfg(tempdir_factory, store):
|
def test_python_hook_weird_setup_cfg(tempdir_factory, store, test_hook_repo):
|
||||||
path = git_dir(tempdir_factory)
|
path = git_dir(tempdir_factory)
|
||||||
with cwd(path):
|
with cwd(path):
|
||||||
with io.open('setup.cfg', 'w') as setup_cfg:
|
with io.open('setup.cfg', 'w') as setup_cfg:
|
||||||
setup_cfg.write('[install]\ninstall_scripts=/usr/sbin\n')
|
setup_cfg.write('[install]\ninstall_scripts=/usr/sbin\n')
|
||||||
|
|
||||||
_test_hook_repo(
|
test_hook_repo(
|
||||||
tempdir_factory, store, 'python_hooks_repo',
|
tempdir_factory, store, 'python_hooks_repo',
|
||||||
'foo', [os.devnull],
|
'foo', [os.devnull],
|
||||||
b"['" + five.to_bytes(os.devnull) + b"']\nHello World\n",
|
b"['" + five.to_bytes(os.devnull) + b"']\nHello World\n",
|
||||||
|
|
@ -136,9 +135,9 @@ def test_switch_language_versions_doesnt_clobber(tempdir_factory, store):
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.integration
|
@pytest.mark.integration
|
||||||
def test_versioned_python_hook(tempdir_factory, store):
|
def test_versioned_python_hook(test_hook_repo):
|
||||||
_test_hook_repo(
|
test_hook_repo(
|
||||||
tempdir_factory, store, 'python3_hooks_repo',
|
'python3_hooks_repo',
|
||||||
'python3-hook',
|
'python3-hook',
|
||||||
[os.devnull],
|
[os.devnull],
|
||||||
b"3.5\n['" + five.to_bytes(os.devnull) + b"']\nHello World\n",
|
b"3.5\n['" + five.to_bytes(os.devnull) + b"']\nHello World\n",
|
||||||
|
|
@ -148,9 +147,9 @@ def test_versioned_python_hook(tempdir_factory, store):
|
||||||
@skipif_slowtests_false
|
@skipif_slowtests_false
|
||||||
@skipif_cant_run_docker
|
@skipif_cant_run_docker
|
||||||
@pytest.mark.integration
|
@pytest.mark.integration
|
||||||
def test_run_a_docker_hook(tempdir_factory, store):
|
def test_run_a_docker_hook(test_hook_repo):
|
||||||
_test_hook_repo(
|
test_hook_repo(
|
||||||
tempdir_factory, store, 'docker_hooks_repo',
|
'docker_hooks_repo',
|
||||||
'docker-hook',
|
'docker-hook',
|
||||||
['Hello World from docker'], b'Hello World from docker\n',
|
['Hello World from docker'], b'Hello World from docker\n',
|
||||||
)
|
)
|
||||||
|
|
@ -159,9 +158,9 @@ def test_run_a_docker_hook(tempdir_factory, store):
|
||||||
@skipif_slowtests_false
|
@skipif_slowtests_false
|
||||||
@skipif_cant_run_docker
|
@skipif_cant_run_docker
|
||||||
@pytest.mark.integration
|
@pytest.mark.integration
|
||||||
def test_run_a_docker_hook_with_entry_args(tempdir_factory, store):
|
def test_run_a_docker_hook_with_entry_args(test_hook_repo):
|
||||||
_test_hook_repo(
|
test_hook_repo(
|
||||||
tempdir_factory, store, 'docker_hooks_repo',
|
'docker_hooks_repo',
|
||||||
'docker-hook-arg',
|
'docker-hook-arg',
|
||||||
['Hello World from docker'], b'Hello World from docker',
|
['Hello World from docker'], b'Hello World from docker',
|
||||||
)
|
)
|
||||||
|
|
@ -170,9 +169,9 @@ def test_run_a_docker_hook_with_entry_args(tempdir_factory, store):
|
||||||
@skipif_slowtests_false
|
@skipif_slowtests_false
|
||||||
@skipif_cant_run_docker
|
@skipif_cant_run_docker
|
||||||
@pytest.mark.integration
|
@pytest.mark.integration
|
||||||
def test_run_a_failing_docker_hook(tempdir_factory, store):
|
def test_run_a_failing_docker_hook(test_hook_repo):
|
||||||
_test_hook_repo(
|
test_hook_repo(
|
||||||
tempdir_factory, store, 'docker_hooks_repo',
|
'docker_hooks_repo',
|
||||||
'docker-hook-failing',
|
'docker-hook-failing',
|
||||||
['Hello World from docker'], b'',
|
['Hello World from docker'], b'',
|
||||||
expected_return_code=1,
|
expected_return_code=1,
|
||||||
|
|
@ -183,9 +182,9 @@ def test_run_a_failing_docker_hook(tempdir_factory, store):
|
||||||
@skipif_cant_run_docker
|
@skipif_cant_run_docker
|
||||||
@pytest.mark.integration
|
@pytest.mark.integration
|
||||||
@pytest.mark.parametrize('hook_id', ('echo-entrypoint', 'echo-cmd'))
|
@pytest.mark.parametrize('hook_id', ('echo-entrypoint', 'echo-cmd'))
|
||||||
def test_run_a_docker_image_hook(tempdir_factory, store, hook_id):
|
def test_run_a_docker_image_hook(test_hook_repo, hook_id):
|
||||||
_test_hook_repo(
|
test_hook_repo(
|
||||||
tempdir_factory, store, 'docker_image_hooks_repo',
|
'docker_image_hooks_repo',
|
||||||
hook_id,
|
hook_id,
|
||||||
['Hello World from docker'], b'Hello World from docker\n',
|
['Hello World from docker'], b'Hello World from docker\n',
|
||||||
)
|
)
|
||||||
|
|
@ -194,9 +193,9 @@ def test_run_a_docker_image_hook(tempdir_factory, store, hook_id):
|
||||||
@skipif_slowtests_false
|
@skipif_slowtests_false
|
||||||
@xfailif_windows_no_node
|
@xfailif_windows_no_node
|
||||||
@pytest.mark.integration
|
@pytest.mark.integration
|
||||||
def test_run_a_node_hook(tempdir_factory, store):
|
def test_run_a_node_hook(test_hook_repo):
|
||||||
_test_hook_repo(
|
test_hook_repo(
|
||||||
tempdir_factory, store, 'node_hooks_repo',
|
'node_hooks_repo',
|
||||||
'foo', ['/dev/null'], b'Hello World\n',
|
'foo', ['/dev/null'], b'Hello World\n',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -204,9 +203,9 @@ def test_run_a_node_hook(tempdir_factory, store):
|
||||||
@skipif_slowtests_false
|
@skipif_slowtests_false
|
||||||
@xfailif_windows_no_node
|
@xfailif_windows_no_node
|
||||||
@pytest.mark.integration
|
@pytest.mark.integration
|
||||||
def test_run_versioned_node_hook(tempdir_factory, store):
|
def test_run_versioned_node_hook(test_hook_repo):
|
||||||
_test_hook_repo(
|
test_hook_repo(
|
||||||
tempdir_factory, store, 'node_0_11_8_hooks_repo',
|
'node_0_11_8_hooks_repo',
|
||||||
'node-11-8-hook', ['/dev/null'], b'v0.11.8\nHello World\n',
|
'node-11-8-hook', ['/dev/null'], b'v0.11.8\nHello World\n',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -214,9 +213,9 @@ def test_run_versioned_node_hook(tempdir_factory, store):
|
||||||
@skipif_slowtests_false
|
@skipif_slowtests_false
|
||||||
@xfailif_windows_no_ruby
|
@xfailif_windows_no_ruby
|
||||||
@pytest.mark.integration
|
@pytest.mark.integration
|
||||||
def test_run_a_ruby_hook(tempdir_factory, store):
|
def test_run_a_ruby_hook(test_hook_repo):
|
||||||
_test_hook_repo(
|
test_hook_repo(
|
||||||
tempdir_factory, store, 'ruby_hooks_repo',
|
'ruby_hooks_repo',
|
||||||
'ruby_hook', ['/dev/null'], b'Hello world from a ruby hook\n',
|
'ruby_hook', ['/dev/null'], b'Hello world from a ruby hook\n',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -224,9 +223,9 @@ def test_run_a_ruby_hook(tempdir_factory, store):
|
||||||
@skipif_slowtests_false
|
@skipif_slowtests_false
|
||||||
@xfailif_windows_no_ruby
|
@xfailif_windows_no_ruby
|
||||||
@pytest.mark.integration
|
@pytest.mark.integration
|
||||||
def test_run_versioned_ruby_hook(tempdir_factory, store):
|
def test_run_versioned_ruby_hook(test_hook_repo):
|
||||||
_test_hook_repo(
|
test_hook_repo(
|
||||||
tempdir_factory, store, 'ruby_versioned_hooks_repo',
|
'ruby_versioned_hooks_repo',
|
||||||
'ruby_hook',
|
'ruby_hook',
|
||||||
['/dev/null'],
|
['/dev/null'],
|
||||||
b'2.1.5\nHello world from a ruby hook\n',
|
b'2.1.5\nHello world from a ruby hook\n',
|
||||||
|
|
@ -237,9 +236,8 @@ def test_run_versioned_ruby_hook(tempdir_factory, store):
|
||||||
@xfailif_windows_no_ruby
|
@xfailif_windows_no_ruby
|
||||||
@pytest.mark.integration
|
@pytest.mark.integration
|
||||||
def test_run_ruby_hook_with_disable_shared_gems(
|
def test_run_ruby_hook_with_disable_shared_gems(
|
||||||
tempdir_factory,
|
test_hook_repo,
|
||||||
store,
|
tmpdir
|
||||||
tmpdir,
|
|
||||||
):
|
):
|
||||||
"""Make sure a Gemfile in the project doesn't interfere."""
|
"""Make sure a Gemfile in the project doesn't interfere."""
|
||||||
tmpdir.join('Gemfile').write('gem "lol_hai"')
|
tmpdir.join('Gemfile').write('gem "lol_hai"')
|
||||||
|
|
@ -249,8 +247,8 @@ def test_run_ruby_hook_with_disable_shared_gems(
|
||||||
'BUNDLE_PATH: vendor/gem\n',
|
'BUNDLE_PATH: vendor/gem\n',
|
||||||
)
|
)
|
||||||
with cwd(tmpdir.strpath):
|
with cwd(tmpdir.strpath):
|
||||||
_test_hook_repo(
|
test_hook_repo(
|
||||||
tempdir_factory, store, 'ruby_versioned_hooks_repo',
|
'ruby_versioned_hooks_repo',
|
||||||
'ruby_hook',
|
'ruby_hook',
|
||||||
['/dev/null'],
|
['/dev/null'],
|
||||||
b'2.1.5\nHello world from a ruby hook\n',
|
b'2.1.5\nHello world from a ruby hook\n',
|
||||||
|
|
@ -258,34 +256,34 @@ def test_run_ruby_hook_with_disable_shared_gems(
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.integration
|
@pytest.mark.integration
|
||||||
def test_system_hook_with_spaces(tempdir_factory, store):
|
def test_system_hook_with_spaces(test_hook_repo):
|
||||||
_test_hook_repo(
|
test_hook_repo(
|
||||||
tempdir_factory, store, 'system_hook_with_spaces_repo',
|
'system_hook_with_spaces_repo',
|
||||||
'system-hook-with-spaces', ['/dev/null'], b'Hello World\n',
|
'system-hook-with-spaces', ['/dev/null'], b'Hello World\n',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@skipif_cant_run_swift
|
@skipif_cant_run_swift
|
||||||
@pytest.mark.integration
|
@pytest.mark.integration
|
||||||
def test_swift_hook(tempdir_factory, store):
|
def test_swift_hook(test_hook_repo):
|
||||||
_test_hook_repo(
|
test_hook_repo(
|
||||||
tempdir_factory, store, 'swift_hooks_repo',
|
'swift_hooks_repo',
|
||||||
'swift-hooks-repo', [], b'Hello, world!\n',
|
'swift-hooks-repo', [], b'Hello, world!\n',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.integration
|
@pytest.mark.integration
|
||||||
def test_golang_hook(tempdir_factory, store):
|
def test_golang_hook(test_hook_repo):
|
||||||
_test_hook_repo(
|
test_hook_repo(
|
||||||
tempdir_factory, store, 'golang_hooks_repo',
|
'golang_hooks_repo',
|
||||||
'golang-hook', [], b'hello world\n',
|
'golang-hook', [], b'hello world\n',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.integration
|
@pytest.mark.integration
|
||||||
def test_missing_executable(tempdir_factory, store):
|
def test_missing_executable(test_hook_repo):
|
||||||
_test_hook_repo(
|
test_hook_repo(
|
||||||
tempdir_factory, store, 'not_found_exe',
|
'not_found_exe',
|
||||||
'not-found-exe', ['/dev/null'],
|
'not-found-exe', ['/dev/null'],
|
||||||
b'Executable `i-dont-exist-lol` not found',
|
b'Executable `i-dont-exist-lol` not found',
|
||||||
expected_return_code=1,
|
expected_return_code=1,
|
||||||
|
|
@ -293,17 +291,17 @@ def test_missing_executable(tempdir_factory, store):
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.integration
|
@pytest.mark.integration
|
||||||
def test_run_a_script_hook(tempdir_factory, store):
|
def test_run_a_script_hook(test_hook_repo):
|
||||||
_test_hook_repo(
|
test_hook_repo(
|
||||||
tempdir_factory, store, 'script_hooks_repo',
|
'script_hooks_repo',
|
||||||
'bash_hook', ['bar'], b'bar\nHello World\n',
|
'bash_hook', ['bar'], b'bar\nHello World\n',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.integration
|
@pytest.mark.integration
|
||||||
def test_run_hook_with_spaced_args(tempdir_factory, store):
|
def test_run_hook_with_spaced_args(test_hook_repo):
|
||||||
_test_hook_repo(
|
test_hook_repo(
|
||||||
tempdir_factory, store, 'arg_per_line_hooks_repo',
|
'arg_per_line_hooks_repo',
|
||||||
'arg-per-line',
|
'arg-per-line',
|
||||||
['foo bar', 'baz'],
|
['foo bar', 'baz'],
|
||||||
b'arg: hello\narg: world\narg: foo bar\narg: baz\n',
|
b'arg: hello\narg: world\narg: foo bar\narg: baz\n',
|
||||||
|
|
@ -311,9 +309,9 @@ def test_run_hook_with_spaced_args(tempdir_factory, store):
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.integration
|
@pytest.mark.integration
|
||||||
def test_run_hook_with_curly_braced_arguments(tempdir_factory, store):
|
def test_run_hook_with_curly_braced_arguments(test_hook_repo):
|
||||||
_test_hook_repo(
|
test_hook_repo(
|
||||||
tempdir_factory, store, 'arg_per_line_hooks_repo',
|
'arg_per_line_hooks_repo',
|
||||||
'arg-per-line',
|
'arg-per-line',
|
||||||
[],
|
[],
|
||||||
b"arg: hi {1}\narg: I'm {a} problem\n",
|
b"arg: hi {1}\narg: I'm {a} problem\n",
|
||||||
|
|
@ -585,10 +583,10 @@ def test_control_c_control_c_on_install(tempdir_factory, store):
|
||||||
# raise as well.
|
# raise as well.
|
||||||
with pytest.raises(MyKeyboardInterrupt):
|
with pytest.raises(MyKeyboardInterrupt):
|
||||||
with mock.patch.object(
|
with mock.patch.object(
|
||||||
helpers, 'run_setup_cmd', side_effect=MyKeyboardInterrupt,
|
helpers, 'run_setup_cmd', side_effect=MyKeyboardInterrupt,
|
||||||
):
|
):
|
||||||
with mock.patch.object(
|
with mock.patch.object(
|
||||||
shutil, 'rmtree', side_effect=MyKeyboardInterrupt,
|
shutil, 'rmtree', side_effect=MyKeyboardInterrupt,
|
||||||
):
|
):
|
||||||
repo.run_hook(hook, [])
|
repo.run_hook(hook, [])
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue