mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-19 09:04:41 +04:00
git grep -l tmpdir_factory | xargs sed -i 's/tmpdir_factory/tempdir_factory/g'
This commit is contained in:
parent
5791d84236
commit
1dfcf10036
14 changed files with 199 additions and 199 deletions
|
|
@ -50,8 +50,8 @@ def test_is_previous_pre_commit(in_tmpdir):
|
|||
assert is_previous_pre_commit('foo')
|
||||
|
||||
|
||||
def test_install_pre_commit(tmpdir_factory):
|
||||
path = git_dir(tmpdir_factory)
|
||||
def test_install_pre_commit(tempdir_factory):
|
||||
path = git_dir(tempdir_factory)
|
||||
runner = Runner(path)
|
||||
ret = install(runner)
|
||||
assert ret == 0
|
||||
|
|
@ -80,8 +80,8 @@ def test_install_pre_commit(tmpdir_factory):
|
|||
assert pre_push_contents == expected_contents
|
||||
|
||||
|
||||
def test_install_hooks_directory_not_present(tmpdir_factory):
|
||||
path = git_dir(tmpdir_factory)
|
||||
def test_install_hooks_directory_not_present(tempdir_factory):
|
||||
path = git_dir(tempdir_factory)
|
||||
# Simulate some git clients which don't make .git/hooks #234
|
||||
shutil.rmtree(os.path.join(path, '.git', 'hooks'))
|
||||
runner = Runner(path)
|
||||
|
|
@ -90,23 +90,23 @@ def test_install_hooks_directory_not_present(tmpdir_factory):
|
|||
|
||||
|
||||
@xfailif_no_symlink
|
||||
def test_install_hooks_dead_symlink(tmpdir_factory):
|
||||
path = git_dir(tmpdir_factory)
|
||||
def test_install_hooks_dead_symlink(tempdir_factory):
|
||||
path = git_dir(tempdir_factory)
|
||||
os.symlink('/fake/baz', os.path.join(path, '.git', 'hooks', 'pre-commit'))
|
||||
runner = Runner(path)
|
||||
install(runner)
|
||||
assert os.path.exists(runner.pre_commit_path)
|
||||
|
||||
|
||||
def test_uninstall_does_not_blow_up_when_not_there(tmpdir_factory):
|
||||
path = git_dir(tmpdir_factory)
|
||||
def test_uninstall_does_not_blow_up_when_not_there(tempdir_factory):
|
||||
path = git_dir(tempdir_factory)
|
||||
runner = Runner(path)
|
||||
ret = uninstall(runner)
|
||||
assert ret == 0
|
||||
|
||||
|
||||
def test_uninstall(tmpdir_factory):
|
||||
path = git_dir(tmpdir_factory)
|
||||
def test_uninstall(tempdir_factory):
|
||||
path = git_dir(tempdir_factory)
|
||||
runner = Runner(path)
|
||||
assert not os.path.exists(runner.pre_commit_path)
|
||||
install(runner)
|
||||
|
|
@ -116,7 +116,7 @@ def test_uninstall(tmpdir_factory):
|
|||
|
||||
|
||||
def _get_commit_output(
|
||||
tmpdir_factory,
|
||||
tempdir_factory,
|
||||
touch_file='foo',
|
||||
home=None,
|
||||
env_base=os.environ,
|
||||
|
|
@ -124,7 +124,7 @@ def _get_commit_output(
|
|||
cmd_output('touch', touch_file)
|
||||
cmd_output('git', 'add', touch_file)
|
||||
# Don't want to write to home directory
|
||||
home = home or tmpdir_factory.get()
|
||||
home = home or tempdir_factory.get()
|
||||
env = dict(env_base, PRE_COMMIT_HOME=home)
|
||||
return cmd_output(
|
||||
'git', 'commit', '-m', 'Commit!', '--allow-empty',
|
||||
|
|
@ -154,36 +154,36 @@ NORMAL_PRE_COMMIT_RUN = re.compile(
|
|||
)
|
||||
|
||||
|
||||
def test_install_pre_commit_and_run(tmpdir_factory):
|
||||
path = make_consuming_repo(tmpdir_factory, 'script_hooks_repo')
|
||||
def test_install_pre_commit_and_run(tempdir_factory):
|
||||
path = make_consuming_repo(tempdir_factory, 'script_hooks_repo')
|
||||
with cwd(path):
|
||||
assert install(Runner(path)) == 0
|
||||
|
||||
ret, output = _get_commit_output(tmpdir_factory)
|
||||
ret, output = _get_commit_output(tempdir_factory)
|
||||
assert ret == 0
|
||||
assert NORMAL_PRE_COMMIT_RUN.match(output)
|
||||
|
||||
|
||||
def test_install_idempotent(tmpdir_factory):
|
||||
path = make_consuming_repo(tmpdir_factory, 'script_hooks_repo')
|
||||
def test_install_idempotent(tempdir_factory):
|
||||
path = make_consuming_repo(tempdir_factory, 'script_hooks_repo')
|
||||
with cwd(path):
|
||||
assert install(Runner(path)) == 0
|
||||
assert install(Runner(path)) == 0
|
||||
|
||||
ret, output = _get_commit_output(tmpdir_factory)
|
||||
ret, output = _get_commit_output(tempdir_factory)
|
||||
assert ret == 0
|
||||
assert NORMAL_PRE_COMMIT_RUN.match(output)
|
||||
|
||||
|
||||
def test_environment_not_sourced(tmpdir_factory):
|
||||
path = make_consuming_repo(tmpdir_factory, 'script_hooks_repo')
|
||||
def test_environment_not_sourced(tempdir_factory):
|
||||
path = make_consuming_repo(tempdir_factory, 'script_hooks_repo')
|
||||
with cwd(path):
|
||||
# Patch the executable to simulate rming virtualenv
|
||||
with mock.patch.object(sys, 'executable', '/bin/false'):
|
||||
assert install(Runner(path)) == 0
|
||||
|
||||
# Use a specific homedir to ignore --user installs
|
||||
homedir = tmpdir_factory.get()
|
||||
homedir = tempdir_factory.get()
|
||||
# Need this so we can call git commit without sploding
|
||||
with io.open(os.path.join(homedir, '.gitconfig'), 'w') as gitconfig:
|
||||
gitconfig.write(
|
||||
|
|
@ -215,12 +215,12 @@ FAILING_PRE_COMMIT_RUN = re.compile(
|
|||
)
|
||||
|
||||
|
||||
def test_failing_hooks_returns_nonzero(tmpdir_factory):
|
||||
path = make_consuming_repo(tmpdir_factory, 'failing_hook_repo')
|
||||
def test_failing_hooks_returns_nonzero(tempdir_factory):
|
||||
path = make_consuming_repo(tempdir_factory, 'failing_hook_repo')
|
||||
with cwd(path):
|
||||
assert install(Runner(path)) == 0
|
||||
|
||||
ret, output = _get_commit_output(tmpdir_factory)
|
||||
ret, output = _get_commit_output(tempdir_factory)
|
||||
assert ret == 1
|
||||
assert FAILING_PRE_COMMIT_RUN.match(output)
|
||||
|
||||
|
|
@ -233,8 +233,8 @@ EXISTING_COMMIT_RUN = re.compile(
|
|||
)
|
||||
|
||||
|
||||
def test_install_existing_hooks_no_overwrite(tmpdir_factory):
|
||||
path = make_consuming_repo(tmpdir_factory, 'script_hooks_repo')
|
||||
def test_install_existing_hooks_no_overwrite(tempdir_factory):
|
||||
path = make_consuming_repo(tempdir_factory, 'script_hooks_repo')
|
||||
with cwd(path):
|
||||
runner = Runner(path)
|
||||
|
||||
|
|
@ -244,7 +244,7 @@ def test_install_existing_hooks_no_overwrite(tmpdir_factory):
|
|||
make_executable(runner.pre_commit_path)
|
||||
|
||||
# Make sure we installed the "old" hook correctly
|
||||
ret, output = _get_commit_output(tmpdir_factory, touch_file='baz')
|
||||
ret, output = _get_commit_output(tempdir_factory, touch_file='baz')
|
||||
assert ret == 0
|
||||
assert EXISTING_COMMIT_RUN.match(output)
|
||||
|
||||
|
|
@ -252,14 +252,14 @@ def test_install_existing_hooks_no_overwrite(tmpdir_factory):
|
|||
assert install(runner) == 0
|
||||
|
||||
# We should run both the legacy and pre-commit hooks
|
||||
ret, output = _get_commit_output(tmpdir_factory)
|
||||
ret, output = _get_commit_output(tempdir_factory)
|
||||
assert ret == 0
|
||||
assert output.startswith('legacy hook\n')
|
||||
assert NORMAL_PRE_COMMIT_RUN.match(output[len('legacy hook\n'):])
|
||||
|
||||
|
||||
def test_install_existing_hook_no_overwrite_idempotent(tmpdir_factory):
|
||||
path = make_consuming_repo(tmpdir_factory, 'script_hooks_repo')
|
||||
def test_install_existing_hook_no_overwrite_idempotent(tempdir_factory):
|
||||
path = make_consuming_repo(tempdir_factory, 'script_hooks_repo')
|
||||
with cwd(path):
|
||||
runner = Runner(path)
|
||||
|
||||
|
|
@ -273,7 +273,7 @@ def test_install_existing_hook_no_overwrite_idempotent(tmpdir_factory):
|
|||
assert install(runner) == 0
|
||||
|
||||
# We should run both the legacy and pre-commit hooks
|
||||
ret, output = _get_commit_output(tmpdir_factory)
|
||||
ret, output = _get_commit_output(tempdir_factory)
|
||||
assert ret == 0
|
||||
assert output.startswith('legacy hook\n')
|
||||
assert NORMAL_PRE_COMMIT_RUN.match(output[len('legacy hook\n'):])
|
||||
|
|
@ -286,8 +286,8 @@ FAIL_OLD_HOOK = re.compile(
|
|||
)
|
||||
|
||||
|
||||
def test_failing_existing_hook_returns_1(tmpdir_factory):
|
||||
path = make_consuming_repo(tmpdir_factory, 'script_hooks_repo')
|
||||
def test_failing_existing_hook_returns_1(tempdir_factory):
|
||||
path = make_consuming_repo(tempdir_factory, 'script_hooks_repo')
|
||||
with cwd(path):
|
||||
runner = Runner(path)
|
||||
|
||||
|
|
@ -299,23 +299,23 @@ def test_failing_existing_hook_returns_1(tmpdir_factory):
|
|||
assert install(runner) == 0
|
||||
|
||||
# We should get a failure from the legacy hook
|
||||
ret, output = _get_commit_output(tmpdir_factory)
|
||||
ret, output = _get_commit_output(tempdir_factory)
|
||||
assert ret == 1
|
||||
assert FAIL_OLD_HOOK.match(output)
|
||||
|
||||
|
||||
def test_install_overwrite_no_existing_hooks(tmpdir_factory):
|
||||
path = make_consuming_repo(tmpdir_factory, 'script_hooks_repo')
|
||||
def test_install_overwrite_no_existing_hooks(tempdir_factory):
|
||||
path = make_consuming_repo(tempdir_factory, 'script_hooks_repo')
|
||||
with cwd(path):
|
||||
assert install(Runner(path), overwrite=True) == 0
|
||||
|
||||
ret, output = _get_commit_output(tmpdir_factory)
|
||||
ret, output = _get_commit_output(tempdir_factory)
|
||||
assert ret == 0
|
||||
assert NORMAL_PRE_COMMIT_RUN.match(output)
|
||||
|
||||
|
||||
def test_install_overwrite(tmpdir_factory):
|
||||
path = make_consuming_repo(tmpdir_factory, 'script_hooks_repo')
|
||||
def test_install_overwrite(tempdir_factory):
|
||||
path = make_consuming_repo(tempdir_factory, 'script_hooks_repo')
|
||||
with cwd(path):
|
||||
runner = Runner(path)
|
||||
|
||||
|
|
@ -326,13 +326,13 @@ def test_install_overwrite(tmpdir_factory):
|
|||
|
||||
assert install(runner, overwrite=True) == 0
|
||||
|
||||
ret, output = _get_commit_output(tmpdir_factory)
|
||||
ret, output = _get_commit_output(tempdir_factory)
|
||||
assert ret == 0
|
||||
assert NORMAL_PRE_COMMIT_RUN.match(output)
|
||||
|
||||
|
||||
def test_uninstall_restores_legacy_hooks(tmpdir_factory):
|
||||
path = make_consuming_repo(tmpdir_factory, 'script_hooks_repo')
|
||||
def test_uninstall_restores_legacy_hooks(tempdir_factory):
|
||||
path = make_consuming_repo(tempdir_factory, 'script_hooks_repo')
|
||||
with cwd(path):
|
||||
runner = Runner(path)
|
||||
|
||||
|
|
@ -346,13 +346,13 @@ def test_uninstall_restores_legacy_hooks(tmpdir_factory):
|
|||
assert uninstall(runner) == 0
|
||||
|
||||
# Make sure we installed the "old" hook correctly
|
||||
ret, output = _get_commit_output(tmpdir_factory, touch_file='baz')
|
||||
ret, output = _get_commit_output(tempdir_factory, touch_file='baz')
|
||||
assert ret == 0
|
||||
assert EXISTING_COMMIT_RUN.match(output)
|
||||
|
||||
|
||||
def test_replace_old_commit_script(tmpdir_factory):
|
||||
path = make_consuming_repo(tmpdir_factory, 'script_hooks_repo')
|
||||
def test_replace_old_commit_script(tempdir_factory):
|
||||
path = make_consuming_repo(tempdir_factory, 'script_hooks_repo')
|
||||
with cwd(path):
|
||||
runner = Runner(path)
|
||||
|
||||
|
|
@ -371,13 +371,13 @@ def test_replace_old_commit_script(tmpdir_factory):
|
|||
# Install normally
|
||||
assert install(runner) == 0
|
||||
|
||||
ret, output = _get_commit_output(tmpdir_factory)
|
||||
ret, output = _get_commit_output(tempdir_factory)
|
||||
assert ret == 0
|
||||
assert NORMAL_PRE_COMMIT_RUN.match(output)
|
||||
|
||||
|
||||
def test_uninstall_doesnt_remove_not_our_hooks(tmpdir_factory):
|
||||
path = git_dir(tmpdir_factory)
|
||||
def test_uninstall_doesnt_remove_not_our_hooks(tempdir_factory):
|
||||
path = git_dir(tempdir_factory)
|
||||
with cwd(path):
|
||||
runner = Runner(path)
|
||||
with io.open(runner.pre_commit_path, 'w') as pre_commit_file:
|
||||
|
|
@ -398,28 +398,28 @@ PRE_INSTALLED = re.compile(
|
|||
|
||||
|
||||
def test_installs_hooks_with_hooks_True(
|
||||
tmpdir_factory,
|
||||
tempdir_factory,
|
||||
mock_out_store_directory,
|
||||
):
|
||||
path = make_consuming_repo(tmpdir_factory, 'script_hooks_repo')
|
||||
path = make_consuming_repo(tempdir_factory, 'script_hooks_repo')
|
||||
with cwd(path):
|
||||
install(Runner(path), hooks=True)
|
||||
ret, output = _get_commit_output(
|
||||
tmpdir_factory, home=mock_out_store_directory,
|
||||
tempdir_factory, home=mock_out_store_directory,
|
||||
)
|
||||
|
||||
assert ret == 0
|
||||
assert PRE_INSTALLED.match(output)
|
||||
|
||||
|
||||
def test_installed_from_venv(tmpdir_factory):
|
||||
path = make_consuming_repo(tmpdir_factory, 'script_hooks_repo')
|
||||
def test_installed_from_venv(tempdir_factory):
|
||||
path = make_consuming_repo(tempdir_factory, 'script_hooks_repo')
|
||||
with cwd(path):
|
||||
install(Runner(path))
|
||||
# No environment so pre-commit is not on the path when running!
|
||||
# Should still pick up the python from when we installed
|
||||
ret, output = _get_commit_output(
|
||||
tmpdir_factory,
|
||||
tempdir_factory,
|
||||
env_base={
|
||||
'HOME': os.path.expanduser('~'),
|
||||
'TERM': os.environ.get('TERM', ''),
|
||||
|
|
@ -431,9 +431,9 @@ def test_installed_from_venv(tmpdir_factory):
|
|||
assert NORMAL_PRE_COMMIT_RUN.match(output)
|
||||
|
||||
|
||||
def _get_push_output(tmpdir_factory):
|
||||
def _get_push_output(tempdir_factory):
|
||||
# Don't want to write to home directory
|
||||
home = tmpdir_factory.get()
|
||||
home = tempdir_factory.get()
|
||||
env = dict(os.environ, PRE_COMMIT_HOME=home)
|
||||
return cmd_output(
|
||||
'git', 'push', 'origin', 'HEAD:new_branch',
|
||||
|
|
@ -444,31 +444,31 @@ def _get_push_output(tmpdir_factory):
|
|||
)[:2]
|
||||
|
||||
|
||||
def test_pre_push_integration_failing(tmpdir_factory):
|
||||
upstream = make_consuming_repo(tmpdir_factory, 'failing_hook_repo')
|
||||
path = tmpdir_factory.get()
|
||||
def test_pre_push_integration_failing(tempdir_factory):
|
||||
upstream = make_consuming_repo(tempdir_factory, 'failing_hook_repo')
|
||||
path = tempdir_factory.get()
|
||||
cmd_output('git', 'clone', upstream, path)
|
||||
with cwd(path):
|
||||
install(Runner(path), hook_type='pre-push')
|
||||
# commit succeeds because pre-commit is only installed for pre-push
|
||||
assert _get_commit_output(tmpdir_factory)[0] == 0
|
||||
assert _get_commit_output(tempdir_factory)[0] == 0
|
||||
|
||||
retc, output = _get_push_output(tmpdir_factory)
|
||||
retc, output = _get_push_output(tempdir_factory)
|
||||
assert retc == 1
|
||||
assert 'Failing hook' in output
|
||||
assert 'Failed' in output
|
||||
assert 'hookid: failing_hook' in output
|
||||
|
||||
|
||||
def test_pre_push_integration_accepted(tmpdir_factory):
|
||||
upstream = make_consuming_repo(tmpdir_factory, 'script_hooks_repo')
|
||||
path = tmpdir_factory.get()
|
||||
def test_pre_push_integration_accepted(tempdir_factory):
|
||||
upstream = make_consuming_repo(tempdir_factory, 'script_hooks_repo')
|
||||
path = tempdir_factory.get()
|
||||
cmd_output('git', 'clone', upstream, path)
|
||||
with cwd(path):
|
||||
install(Runner(path), hook_type='pre-push')
|
||||
assert _get_commit_output(tmpdir_factory)[0] == 0
|
||||
assert _get_commit_output(tempdir_factory)[0] == 0
|
||||
|
||||
retc, output = _get_push_output(tmpdir_factory)
|
||||
retc, output = _get_push_output(tempdir_factory)
|
||||
assert retc == 0
|
||||
assert 'Bash hook' in output
|
||||
assert 'Passed' in output
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue