some more integration test fixes

This commit is contained in:
Bernat Gabor 2017-10-27 14:55:52 +01:00
parent 3593c76757
commit 8c0817391f
No known key found for this signature in database
GPG key ID: 25F70E3BB8B17899
2 changed files with 43 additions and 28 deletions

View file

@ -42,6 +42,16 @@ skipif_cant_run_swift = pytest.mark.skipif(
reason='swift isn\'t installed or can\'t be found',
)
skipif_cant_run_go = pytest.mark.skipif(
parse_shebang.find_executable('go') is None,
reason='go isn\'t installed or can\'t be found',
)
skipif_cant_run_bash = pytest.mark.skipif(
parse_shebang.find_executable('bash') is None,
reason='bash isn\'t installed or can\'t be found',
)
xfailif_windows_no_ruby = pytest.mark.xfail(
os.name == 'nt',
reason='Ruby support not yet implemented on windows.',

View file

@ -29,7 +29,9 @@ from testing.fixtures import make_config_from_repo
from testing.fixtures import make_repo
from testing.fixtures import modify_manifest
from testing.util import get_resource_path
from testing.util import skipif_cant_run_bash
from testing.util import skipif_cant_run_docker
from testing.util import skipif_cant_run_go
from testing.util import skipif_cant_run_swift
from testing.util import skipif_slowtests_false
from testing.util import xfailif_no_pcre_support
@ -105,14 +107,14 @@ def test_python_hook_weird_setup_cfg(tempdir_factory, store, test_hook_repo):
setup_cfg.write('[install]\ninstall_scripts=/usr/sbin\n')
test_hook_repo(
tempdir_factory, store, 'python_hooks_repo',
'python_hooks_repo',
'foo', [os.devnull],
b"['" + five.to_bytes(os.devnull) + b"']\nHello World\n",
)
@pytest.mark.integration
def test_switch_language_versions_doesnt_clobber(tempdir_factory, store):
def test_switch_language_versions_doesnt_clobber(tempdir_factory, store, setup_git):
# We're using the python3 repo because it prints the python version
path = make_repo(tempdir_factory, 'python3_hooks_repo')
@ -271,7 +273,7 @@ def test_swift_hook(test_hook_repo):
'swift-hooks-repo', [], b'Hello, world!\n',
)
@skipif_cant_run_go
@pytest.mark.integration
def test_golang_hook(test_hook_repo):
test_hook_repo(
@ -418,26 +420,26 @@ def _norm_pwd(path):
@pytest.mark.integration
def test_cwd_of_hook(tempdir_factory, store):
def test_cwd_of_hook(tempdir_factory, test_hook_repo):
# Note: this doubles as a test for `system` hooks
path = git_dir(tempdir_factory)
with cwd(path):
_test_hook_repo(
tempdir_factory, store, 'prints_cwd_repo',
test_hook_repo(
'prints_cwd_repo',
'prints_cwd', ['-L'], _norm_pwd(path) + b'\n',
)
@skipif_cant_run_bash
@pytest.mark.integration
def test_lots_of_files(tempdir_factory, store):
_test_hook_repo(
tempdir_factory, store, 'script_hooks_repo',
def test_lots_of_files(test_hook_repo):
test_hook_repo(
'script_hooks_repo',
'bash_hook', ['/dev/null'] * 15000, mock.ANY,
)
@pytest.mark.integration
def test_venvs(tempdir_factory, store):
def test_venvs(tempdir_factory, store, setup_git):
path = make_repo(tempdir_factory, 'python_hooks_repo')
config = make_config_from_repo(path)
repo = Repository.create(config, store)
@ -446,7 +448,7 @@ def test_venvs(tempdir_factory, store):
@pytest.mark.integration
def test_additional_dependencies(tempdir_factory, store):
def test_additional_dependencies(tempdir_factory, store, setup_git):
path = make_repo(tempdir_factory, 'python_hooks_repo')
config = make_config_from_repo(path)
config['hooks'][0]['additional_dependencies'] = ['pep8']
@ -457,7 +459,7 @@ def test_additional_dependencies(tempdir_factory, store):
@pytest.mark.integration
def test_additional_dependencies_duplicated(
tempdir_factory, store, log_warning_mock,
tempdir_factory, store, log_warning_mock, setup_git
):
path = make_repo(tempdir_factory, 'ruby_hooks_repo')
config = make_config_from_repo(path)
@ -469,7 +471,7 @@ def test_additional_dependencies_duplicated(
@pytest.mark.integration
def test_additional_python_dependencies_installed(tempdir_factory, store):
def test_additional_python_dependencies_installed(tempdir_factory, store, setup_git):
path = make_repo(tempdir_factory, 'python_hooks_repo')
config = make_config_from_repo(path)
config['hooks'][0]['additional_dependencies'] = ['mccabe']
@ -481,7 +483,7 @@ def test_additional_python_dependencies_installed(tempdir_factory, store):
@pytest.mark.integration
def test_additional_dependencies_roll_forward(tempdir_factory, store):
def test_additional_dependencies_roll_forward(tempdir_factory, store, setup_git):
path = make_repo(tempdir_factory, 'python_hooks_repo')
config = make_config_from_repo(path)
# Run the repo once without additional_dependencies
@ -531,10 +533,10 @@ def test_additional_node_dependencies_installed(
output = cmd_output('npm', 'ls')[1]
assert 'lodash' in output
@skipif_cant_run_go
@pytest.mark.integration
def test_additional_golang_dependencies_installed(
tempdir_factory, store,
tempdir_factory, store, setup_git
):
path = make_repo(tempdir_factory, 'golang_hooks_repo')
config = make_config_from_repo(path)
@ -551,7 +553,7 @@ def test_additional_golang_dependencies_installed(
assert 'hello' in binaries
def test_reinstall(tempdir_factory, store, log_info_mock):
def test_reinstall(tempdir_factory, store, log_info_mock, setup_git):
path = make_repo(tempdir_factory, 'python_hooks_repo')
config = make_config_from_repo(path)
repo = Repository.create(config, store)
@ -568,7 +570,7 @@ def test_reinstall(tempdir_factory, store, log_info_mock):
assert log_info_mock.call_count == 0
def test_control_c_control_c_on_install(tempdir_factory, store):
def test_control_c_control_c_on_install(tempdir_factory, store, setup_git):
"""Regression test for #186."""
path = make_repo(tempdir_factory, 'python_hooks_repo')
config = make_config_from_repo(path)
@ -600,7 +602,7 @@ def test_control_c_control_c_on_install(tempdir_factory, store):
assert retv == 0
def test_invalidated_virtualenv(tempdir_factory, store):
def test_invalidated_virtualenv(tempdir_factory, store, setup_git):
# A cached virtualenv may become invalidated if the system python upgrades
# This should not cause every hook in that virtualenv to fail.
path = make_repo(tempdir_factory, 'python_hooks_repo')
@ -614,7 +616,10 @@ def test_invalidated_virtualenv(tempdir_factory, store):
paths = [
os.path.join(libdir, p) for p in ('site.py', 'site.pyc', '__pycache__')
]
cmd_output('rm', '-rf', *paths)
for path in paths:
if os.path.exists(path):
os.rmdir(path)
# pre-commit should rebuild the virtualenv and it should be runnable
repo = Repository.create(config, store)
@ -624,7 +629,7 @@ def test_invalidated_virtualenv(tempdir_factory, store):
@pytest.mark.integration
def test_really_long_file_paths(tempdir_factory, store):
def test_really_long_file_paths(tempdir_factory, store, setup_git):
base_path = tempdir_factory.get()
really_long_path = os.path.join(base_path, 'really_long' * 10)
cmd_output('git', 'init', really_long_path)
@ -638,7 +643,7 @@ def test_really_long_file_paths(tempdir_factory, store):
@pytest.mark.integration
def test_config_overrides_repo_specifics(tempdir_factory, store):
def test_config_overrides_repo_specifics(tempdir_factory, store, setup_git):
path = make_repo(tempdir_factory, 'script_hooks_repo')
config = make_config_from_repo(path)
@ -658,7 +663,7 @@ def _create_repo_with_tags(tempdir_factory, src, tag):
@pytest.mark.integration
def test_tags_on_repositories(in_tmpdir, tempdir_factory, store):
def test_tags_on_repositories(in_tmpdir, tempdir_factory, store, setup_git):
tag = 'v1.1'
git_dir_1 = _create_repo_with_tags(tempdir_factory, 'prints_cwd_repo', tag)
git_dir_2 = _create_repo_with_tags(
@ -705,7 +710,7 @@ def test_local_python_repo(store):
assert _norm_out(ret[1]) == b"['filename']\nHello World\n"
def test_hook_id_not_present(tempdir_factory, store, fake_log_handler):
def test_hook_id_not_present(tempdir_factory, store, fake_log_handler, setup_git):
path = make_repo(tempdir_factory, 'script_hooks_repo')
config = make_config_from_repo(path)
config['hooks'][0]['id'] = 'i-dont-exist'
@ -719,7 +724,7 @@ def test_hook_id_not_present(tempdir_factory, store, fake_log_handler):
)
def test_too_new_version(tempdir_factory, store, fake_log_handler):
def test_too_new_version(tempdir_factory, store, fake_log_handler, setup_git):
path = make_repo(tempdir_factory, 'script_hooks_repo')
with modify_manifest(path) as manifest:
manifest[0]['minimum_pre_commit_version'] = '999.0.0'
@ -737,7 +742,7 @@ def test_too_new_version(tempdir_factory, store, fake_log_handler):
@pytest.mark.parametrize('version', ('0.1.0', C.VERSION))
def test_versions_ok(tempdir_factory, store, version):
def test_versions_ok(tempdir_factory, store, version, setup_git):
path = make_repo(tempdir_factory, 'script_hooks_repo')
with modify_manifest(path) as manifest:
manifest[0]['minimum_pre_commit_version'] = version
@ -746,7 +751,7 @@ def test_versions_ok(tempdir_factory, store, version):
Repository.create(config, store).require_installed()
def test_manifest_hooks(tempdir_factory, store):
def test_manifest_hooks(tempdir_factory, store, setup_git):
path = make_repo(tempdir_factory, 'script_hooks_repo')
config = make_config_from_repo(path)
repo = Repository.create(config, store)