mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-01-13 12:30:08 -06:00
git grep -l tmpdir_factory | xargs sed -i 's/tmpdir_factory/tempdir_factory/g'
This commit is contained in:
@@ -5,4 +5,4 @@ coverage
|
||||
flake8
|
||||
mock
|
||||
pylint<1.4
|
||||
pytest<2.8
|
||||
pytest
|
||||
|
||||
@@ -19,15 +19,15 @@ from testing.util import get_head_sha
|
||||
from testing.util import get_resource_path
|
||||
|
||||
|
||||
def git_dir(tmpdir_factory):
|
||||
path = tmpdir_factory.get()
|
||||
def git_dir(tempdir_factory):
|
||||
path = tempdir_factory.get()
|
||||
with cwd(path):
|
||||
cmd_output('git', 'init')
|
||||
return path
|
||||
|
||||
|
||||
def make_repo(tmpdir_factory, repo_source):
|
||||
path = git_dir(tmpdir_factory)
|
||||
def make_repo(tempdir_factory, repo_source):
|
||||
path = git_dir(tempdir_factory)
|
||||
copy_tree_to_path(get_resource_path(repo_source), path)
|
||||
with cwd(path):
|
||||
cmd_output('git', 'add', '.')
|
||||
@@ -83,8 +83,8 @@ def add_config_to_repo(git_path, config):
|
||||
return git_path
|
||||
|
||||
|
||||
def make_consuming_repo(tmpdir_factory, repo_source):
|
||||
path = make_repo(tmpdir_factory, repo_source)
|
||||
def make_consuming_repo(tempdir_factory, repo_source):
|
||||
path = make_repo(tempdir_factory, repo_source)
|
||||
config = make_config_from_repo(path)
|
||||
git_path = git_dir(tmpdir_factory)
|
||||
git_path = git_dir(tempdir_factory)
|
||||
return add_config_to_repo(git_path, config)
|
||||
|
||||
@@ -25,8 +25,8 @@ from testing.util import get_resource_path
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
def up_to_date_repo(tmpdir_factory):
|
||||
yield make_repo(tmpdir_factory, 'python_hooks_repo')
|
||||
def up_to_date_repo(tempdir_factory):
|
||||
yield make_repo(tempdir_factory, 'python_hooks_repo')
|
||||
|
||||
|
||||
def test_up_to_date_repo(up_to_date_repo, runner_with_mocked_store):
|
||||
@@ -53,8 +53,8 @@ def test_autoupdate_up_to_date_repo(
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
def out_of_date_repo(tmpdir_factory):
|
||||
path = make_repo(tmpdir_factory, 'python_hooks_repo')
|
||||
def out_of_date_repo(tempdir_factory):
|
||||
path = make_repo(tempdir_factory, 'python_hooks_repo')
|
||||
original_sha = get_head_sha(path)
|
||||
|
||||
# Make a commit
|
||||
@@ -97,8 +97,8 @@ def test_autoupdate_out_of_date_repo(
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
def hook_disappearing_repo(tmpdir_factory):
|
||||
path = make_repo(tmpdir_factory, 'python_hooks_repo')
|
||||
def hook_disappearing_repo(tempdir_factory):
|
||||
path = make_repo(tempdir_factory, 'python_hooks_repo')
|
||||
original_sha = get_head_sha(path)
|
||||
|
||||
with cwd(path):
|
||||
@@ -143,8 +143,8 @@ def test_autoupdate_hook_disappearing_repo(
|
||||
assert before == after
|
||||
|
||||
|
||||
def test_autoupdate_local_hooks(tmpdir_factory):
|
||||
git_path = git_dir(tmpdir_factory)
|
||||
def test_autoupdate_local_hooks(tempdir_factory):
|
||||
git_path = git_dir(tempdir_factory)
|
||||
config = config_with_local_hooks()
|
||||
path = add_config_to_repo(git_path, config)
|
||||
runner = Runner(path)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -27,15 +27,15 @@ from testing.fixtures import make_consuming_repo
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
def repo_with_passing_hook(tmpdir_factory):
|
||||
git_path = make_consuming_repo(tmpdir_factory, 'script_hooks_repo')
|
||||
def repo_with_passing_hook(tempdir_factory):
|
||||
git_path = make_consuming_repo(tempdir_factory, 'script_hooks_repo')
|
||||
with cwd(git_path):
|
||||
yield git_path
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
def repo_with_failing_hook(tmpdir_factory):
|
||||
git_path = make_consuming_repo(tmpdir_factory, 'failing_hook_repo')
|
||||
def repo_with_failing_hook(tempdir_factory):
|
||||
git_path = make_consuming_repo(tempdir_factory, 'failing_hook_repo')
|
||||
with cwd(git_path):
|
||||
yield git_path
|
||||
|
||||
@@ -111,8 +111,8 @@ def test_run_all_hooks_failing(
|
||||
)
|
||||
|
||||
|
||||
def test_arbitrary_bytes_hook(tmpdir_factory, mock_out_store_directory):
|
||||
git_path = make_consuming_repo(tmpdir_factory, 'arbitrary_bytes_repo')
|
||||
def test_arbitrary_bytes_hook(tempdir_factory, mock_out_store_directory):
|
||||
git_path = make_consuming_repo(tempdir_factory, 'arbitrary_bytes_repo')
|
||||
with cwd(git_path):
|
||||
_test_run(git_path, {}, (b'\xe2\x98\x83\xb2\n',), 1, True)
|
||||
|
||||
@@ -292,12 +292,12 @@ def test_multiple_hooks_same_id(
|
||||
|
||||
|
||||
def test_non_ascii_hook_id(
|
||||
repo_with_passing_hook, mock_out_store_directory, tmpdir_factory,
|
||||
repo_with_passing_hook, mock_out_store_directory, tempdir_factory,
|
||||
):
|
||||
with cwd(repo_with_passing_hook):
|
||||
install(Runner(repo_with_passing_hook))
|
||||
# Don't want to write to home directory
|
||||
env = dict(os.environ, PRE_COMMIT_HOME=tmpdir_factory.get())
|
||||
env = dict(os.environ, PRE_COMMIT_HOME=tempdir_factory.get())
|
||||
_, stdout, _ = cmd_output(
|
||||
sys.executable, '-m', 'pre_commit.main', 'run', '☃',
|
||||
env=env, retcode=None,
|
||||
@@ -308,7 +308,7 @@ def test_non_ascii_hook_id(
|
||||
|
||||
|
||||
def test_stdout_write_bug_py26(
|
||||
repo_with_failing_hook, mock_out_store_directory, tmpdir_factory,
|
||||
repo_with_failing_hook, mock_out_store_directory, tempdir_factory,
|
||||
):
|
||||
with cwd(repo_with_failing_hook):
|
||||
# Add bash hook on there again
|
||||
@@ -322,7 +322,7 @@ def test_stdout_write_bug_py26(
|
||||
install(Runner(repo_with_failing_hook))
|
||||
|
||||
# Don't want to write to home directory
|
||||
env = dict(os.environ, PRE_COMMIT_HOME=tmpdir_factory.get())
|
||||
env = dict(os.environ, PRE_COMMIT_HOME=tempdir_factory.get())
|
||||
# Have to use subprocess because pytest monkeypatches sys.stdout
|
||||
_, stdout, _ = cmd_output(
|
||||
'git', 'commit', '-m', 'Commit!',
|
||||
@@ -344,10 +344,10 @@ def test_get_changed_files():
|
||||
assert files == ['CHANGELOG.md', 'setup.py']
|
||||
|
||||
|
||||
def test_lots_of_files(mock_out_store_directory, tmpdir_factory):
|
||||
def test_lots_of_files(mock_out_store_directory, tempdir_factory):
|
||||
# windows xargs seems to have a bug, here's a regression test for
|
||||
# our workaround
|
||||
git_path = make_consuming_repo(tmpdir_factory, 'python_hooks_repo')
|
||||
git_path = make_consuming_repo(tempdir_factory, 'python_hooks_repo')
|
||||
with cwd(git_path):
|
||||
# Override files so we run against them
|
||||
with io.open('.pre-commit-config.yaml', 'a+') as config_file:
|
||||
@@ -362,7 +362,7 @@ def test_lots_of_files(mock_out_store_directory, tmpdir_factory):
|
||||
install(Runner(git_path))
|
||||
|
||||
# Don't want to write to home directory
|
||||
env = dict(os.environ, PRE_COMMIT_HOME=tmpdir_factory.get())
|
||||
env = dict(os.environ, PRE_COMMIT_HOME=tempdir_factory.get())
|
||||
cmd_output(
|
||||
'git', 'commit', '-m', 'Commit!',
|
||||
# git commit puts pre-commit to stderr
|
||||
|
||||
@@ -20,7 +20,7 @@ from testing.fixtures import make_consuming_repo
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
def tmpdir_factory(tmpdir):
|
||||
def tempdir_factory(tmpdir):
|
||||
class TmpdirFactory(object):
|
||||
def __init__(self):
|
||||
self.tmpdir_count = 0
|
||||
@@ -35,22 +35,22 @@ def tmpdir_factory(tmpdir):
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
def in_tmpdir(tmpdir_factory):
|
||||
path = tmpdir_factory.get()
|
||||
def in_tmpdir(tempdir_factory):
|
||||
path = tempdir_factory.get()
|
||||
with cwd(path):
|
||||
yield path
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
def in_merge_conflict(tmpdir_factory):
|
||||
path = make_consuming_repo(tmpdir_factory, 'script_hooks_repo')
|
||||
def in_merge_conflict(tempdir_factory):
|
||||
path = make_consuming_repo(tempdir_factory, 'script_hooks_repo')
|
||||
with cwd(path):
|
||||
cmd_output('touch', 'dummy')
|
||||
cmd_output('git', 'add', 'dummy')
|
||||
cmd_output('git', 'add', C.CONFIG_FILE)
|
||||
cmd_output('git', 'commit', '-m', 'Add config.')
|
||||
|
||||
conflict_path = tmpdir_factory.get()
|
||||
conflict_path = tempdir_factory.get()
|
||||
cmd_output('git', 'clone', path, conflict_path)
|
||||
with cwd(conflict_path):
|
||||
cmd_output('git', 'checkout', 'origin/master', '-b', 'foo')
|
||||
@@ -91,8 +91,8 @@ def dont_write_to_home_directory():
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
def mock_out_store_directory(tmpdir_factory):
|
||||
tmpdir = tmpdir_factory.get()
|
||||
def mock_out_store_directory(tempdir_factory):
|
||||
tmpdir = tempdir_factory.get()
|
||||
with mock.patch.object(
|
||||
Store,
|
||||
'get_default_directory',
|
||||
@@ -102,13 +102,13 @@ def mock_out_store_directory(tmpdir_factory):
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
def store(tmpdir_factory):
|
||||
yield Store(os.path.join(tmpdir_factory.get(), '.pre-commit'))
|
||||
def store(tempdir_factory):
|
||||
yield Store(os.path.join(tempdir_factory.get(), '.pre-commit'))
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
def cmd_runner(tmpdir_factory):
|
||||
yield PrefixedCommandRunner(tmpdir_factory.get())
|
||||
def cmd_runner(tempdir_factory):
|
||||
yield PrefixedCommandRunner(tempdir_factory.get())
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
|
||||
@@ -12,14 +12,14 @@ from pre_commit.util import cwd
|
||||
from testing.fixtures import git_dir
|
||||
|
||||
|
||||
def test_get_root_at_root(tmpdir_factory):
|
||||
path = git_dir(tmpdir_factory)
|
||||
def test_get_root_at_root(tempdir_factory):
|
||||
path = git_dir(tempdir_factory)
|
||||
with cwd(path):
|
||||
assert git.get_root() == path
|
||||
|
||||
|
||||
def test_get_root_deeper(tmpdir_factory):
|
||||
path = git_dir(tmpdir_factory)
|
||||
def test_get_root_deeper(tempdir_factory):
|
||||
path = git_dir(tempdir_factory)
|
||||
|
||||
foo_path = os.path.join(path, 'foo')
|
||||
os.mkdir(foo_path)
|
||||
@@ -27,14 +27,14 @@ def test_get_root_deeper(tmpdir_factory):
|
||||
assert git.get_root() == path
|
||||
|
||||
|
||||
def test_get_root_not_git_dir(tmpdir_factory):
|
||||
with cwd(tmpdir_factory.get()):
|
||||
def test_get_root_not_git_dir(tempdir_factory):
|
||||
with cwd(tempdir_factory.get()):
|
||||
with pytest.raises(FatalError):
|
||||
git.get_root()
|
||||
|
||||
|
||||
def test_is_not_in_merge_conflict(tmpdir_factory):
|
||||
path = git_dir(tmpdir_factory)
|
||||
def test_is_not_in_merge_conflict(tempdir_factory):
|
||||
path = git_dir(tempdir_factory)
|
||||
with cwd(path):
|
||||
assert git.is_in_merge_conflict() is False
|
||||
|
||||
|
||||
@@ -128,11 +128,11 @@ def test_no_commands_run_command(mock_commands):
|
||||
|
||||
def test_help_cmd_in_empty_directory(
|
||||
mock_commands,
|
||||
tmpdir_factory,
|
||||
tempdir_factory,
|
||||
argparse_exit_mock,
|
||||
argparse_parse_args_spy,
|
||||
):
|
||||
path = tmpdir_factory.get()
|
||||
path = tempdir_factory.get()
|
||||
|
||||
with cwd(path):
|
||||
with pytest.raises(CalledExit):
|
||||
|
||||
@@ -15,9 +15,9 @@ from testing.util import get_head_sha
|
||||
from testing.util import skipif_slowtests_false
|
||||
|
||||
|
||||
def test_make_archive(tmpdir_factory):
|
||||
output_dir = tmpdir_factory.get()
|
||||
git_path = git_dir(tmpdir_factory)
|
||||
def test_make_archive(tempdir_factory):
|
||||
output_dir = tempdir_factory.get()
|
||||
git_path = git_dir(tempdir_factory)
|
||||
# Add a files to the git directory
|
||||
with cwd(git_path):
|
||||
cmd_output('touch', 'foo')
|
||||
@@ -38,7 +38,7 @@ def test_make_archive(tmpdir_factory):
|
||||
assert archive_path == os.path.join(output_dir, 'foo.tar.gz')
|
||||
assert os.path.exists(archive_path)
|
||||
|
||||
extract_dir = tmpdir_factory.get()
|
||||
extract_dir = tempdir_factory.get()
|
||||
|
||||
# Extract the tar
|
||||
with tarfile_open(archive_path) as tf:
|
||||
@@ -53,8 +53,8 @@ def test_make_archive(tmpdir_factory):
|
||||
|
||||
@skipif_slowtests_false
|
||||
@pytest.mark.integration
|
||||
def test_main(tmpdir_factory):
|
||||
path = tmpdir_factory.get()
|
||||
def test_main(tempdir_factory):
|
||||
path = tempdir_factory.get()
|
||||
|
||||
# Don't actually want to make these in the current repo
|
||||
with mock.patch.object(make_archives, 'RESOURCES_DIR', path):
|
||||
|
||||
@@ -9,8 +9,8 @@ from testing.util import get_head_sha
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
def manifest(store, tmpdir_factory):
|
||||
path = make_repo(tmpdir_factory, 'script_hooks_repo')
|
||||
def manifest(store, tempdir_factory):
|
||||
path = make_repo(tempdir_factory, 'script_hooks_repo')
|
||||
head_sha = get_head_sha(path)
|
||||
repo_path_getter = store.get_repo_path_getter(path, head_sha)
|
||||
yield Manifest(repo_path_getter)
|
||||
|
||||
@@ -29,7 +29,7 @@ from testing.util import xfailif_windows_no_ruby
|
||||
|
||||
|
||||
def _test_hook_repo(
|
||||
tmpdir_factory,
|
||||
tempdir_factory,
|
||||
store,
|
||||
repo_path,
|
||||
hook_id,
|
||||
@@ -38,7 +38,7 @@ def _test_hook_repo(
|
||||
expected_return_code=0,
|
||||
config_kwargs=None
|
||||
):
|
||||
path = make_repo(tmpdir_factory, repo_path)
|
||||
path = make_repo(tempdir_factory, repo_path)
|
||||
config = make_config_from_repo(path, **(config_kwargs or {}))
|
||||
repo = Repository.create(config, store)
|
||||
hook_dict = [
|
||||
@@ -50,18 +50,18 @@ def _test_hook_repo(
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
def test_python_hook(tmpdir_factory, store):
|
||||
def test_python_hook(tempdir_factory, store):
|
||||
_test_hook_repo(
|
||||
tmpdir_factory, store, 'python_hooks_repo',
|
||||
tempdir_factory, store, 'python_hooks_repo',
|
||||
'foo', [os.devnull],
|
||||
b"['" + five.to_bytes(os.devnull) + b"']\nHello World\n"
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
def test_python_hook_args_with_spaces(tmpdir_factory, store):
|
||||
def test_python_hook_args_with_spaces(tempdir_factory, store):
|
||||
_test_hook_repo(
|
||||
tmpdir_factory, store, 'python_hooks_repo',
|
||||
tempdir_factory, store, 'python_hooks_repo',
|
||||
'foo',
|
||||
[],
|
||||
b"['i have spaces', 'and\"\\'quotes', '$and !this']\n"
|
||||
@@ -76,9 +76,9 @@ def test_python_hook_args_with_spaces(tmpdir_factory, store):
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
def test_switch_language_versions_doesnt_clobber(tmpdir_factory, store):
|
||||
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(tmpdir_factory, 'python3_hooks_repo')
|
||||
path = make_repo(tempdir_factory, 'python3_hooks_repo')
|
||||
|
||||
def run_on_version(version, expected_output):
|
||||
config = make_config_from_repo(
|
||||
@@ -99,9 +99,9 @@ def test_switch_language_versions_doesnt_clobber(tmpdir_factory, store):
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
def test_versioned_python_hook(tmpdir_factory, store):
|
||||
def test_versioned_python_hook(tempdir_factory, store):
|
||||
_test_hook_repo(
|
||||
tmpdir_factory, store, 'python3_hooks_repo',
|
||||
tempdir_factory, store, 'python3_hooks_repo',
|
||||
'python3-hook',
|
||||
[os.devnull],
|
||||
b"3.3\n['" + five.to_bytes(os.devnull) + b"']\nHello World\n",
|
||||
@@ -111,9 +111,9 @@ def test_versioned_python_hook(tmpdir_factory, store):
|
||||
@skipif_slowtests_false
|
||||
@xfailif_windows_no_node
|
||||
@pytest.mark.integration
|
||||
def test_run_a_node_hook(tmpdir_factory, store):
|
||||
def test_run_a_node_hook(tempdir_factory, store):
|
||||
_test_hook_repo(
|
||||
tmpdir_factory, store, 'node_hooks_repo',
|
||||
tempdir_factory, store, 'node_hooks_repo',
|
||||
'foo', ['/dev/null'], b'Hello World\n',
|
||||
)
|
||||
|
||||
@@ -121,9 +121,9 @@ def test_run_a_node_hook(tmpdir_factory, store):
|
||||
@skipif_slowtests_false
|
||||
@xfailif_windows_no_node
|
||||
@pytest.mark.integration
|
||||
def test_run_versioned_node_hook(tmpdir_factory, store):
|
||||
def test_run_versioned_node_hook(tempdir_factory, store):
|
||||
_test_hook_repo(
|
||||
tmpdir_factory, store, 'node_0_11_8_hooks_repo',
|
||||
tempdir_factory, store, 'node_0_11_8_hooks_repo',
|
||||
'node-11-8-hook', ['/dev/null'], b'v0.11.8\nHello World\n',
|
||||
)
|
||||
|
||||
@@ -131,9 +131,9 @@ def test_run_versioned_node_hook(tmpdir_factory, store):
|
||||
@skipif_slowtests_false
|
||||
@xfailif_windows_no_ruby
|
||||
@pytest.mark.integration
|
||||
def test_run_a_ruby_hook(tmpdir_factory, store):
|
||||
def test_run_a_ruby_hook(tempdir_factory, store):
|
||||
_test_hook_repo(
|
||||
tmpdir_factory, store, 'ruby_hooks_repo',
|
||||
tempdir_factory, store, 'ruby_hooks_repo',
|
||||
'ruby_hook', ['/dev/null'], b'Hello world from a ruby hook\n',
|
||||
)
|
||||
|
||||
@@ -141,9 +141,9 @@ def test_run_a_ruby_hook(tmpdir_factory, store):
|
||||
@skipif_slowtests_false
|
||||
@xfailif_windows_no_ruby
|
||||
@pytest.mark.integration
|
||||
def test_run_versioned_ruby_hook(tmpdir_factory, store):
|
||||
def test_run_versioned_ruby_hook(tempdir_factory, store):
|
||||
_test_hook_repo(
|
||||
tmpdir_factory, store, 'ruby_1_9_3_hooks_repo',
|
||||
tempdir_factory, store, 'ruby_1_9_3_hooks_repo',
|
||||
'ruby_hook',
|
||||
['/dev/null'],
|
||||
b'1.9.3\n484\nHello world from a ruby hook\n',
|
||||
@@ -151,25 +151,25 @@ def test_run_versioned_ruby_hook(tmpdir_factory, store):
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
def test_system_hook_with_spaces(tmpdir_factory, store):
|
||||
def test_system_hook_with_spaces(tempdir_factory, store):
|
||||
_test_hook_repo(
|
||||
tmpdir_factory, store, 'system_hook_with_spaces_repo',
|
||||
tempdir_factory, store, 'system_hook_with_spaces_repo',
|
||||
'system-hook-with-spaces', ['/dev/null'], b'Hello World\n',
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
def test_run_a_script_hook(tmpdir_factory, store):
|
||||
def test_run_a_script_hook(tempdir_factory, store):
|
||||
_test_hook_repo(
|
||||
tmpdir_factory, store, 'script_hooks_repo',
|
||||
tempdir_factory, store, 'script_hooks_repo',
|
||||
'bash_hook', ['bar'], b'bar\nHello World\n',
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
def test_run_hook_with_spaced_args(tmpdir_factory, store):
|
||||
def test_run_hook_with_spaced_args(tempdir_factory, store):
|
||||
_test_hook_repo(
|
||||
tmpdir_factory, store, 'arg_per_line_hooks_repo',
|
||||
tempdir_factory, store, 'arg_per_line_hooks_repo',
|
||||
'arg-per-line',
|
||||
['foo bar', 'baz'],
|
||||
b'arg: hello\narg: world\narg: foo bar\narg: baz\n',
|
||||
@@ -178,8 +178,8 @@ def test_run_hook_with_spaced_args(tmpdir_factory, store):
|
||||
|
||||
@xfailif_no_pcre_support
|
||||
@pytest.mark.integration
|
||||
def test_pcre_hook_no_match(tmpdir_factory, store):
|
||||
path = git_dir(tmpdir_factory)
|
||||
def test_pcre_hook_no_match(tempdir_factory, store):
|
||||
path = git_dir(tempdir_factory)
|
||||
with cwd(path):
|
||||
with io.open('herp', 'w') as herp:
|
||||
herp.write('foo')
|
||||
@@ -188,20 +188,20 @@ def test_pcre_hook_no_match(tmpdir_factory, store):
|
||||
derp.write('bar')
|
||||
|
||||
_test_hook_repo(
|
||||
tmpdir_factory, store, 'pcre_hooks_repo',
|
||||
tempdir_factory, store, 'pcre_hooks_repo',
|
||||
'regex-with-quotes', ['herp', 'derp'], b'',
|
||||
)
|
||||
|
||||
_test_hook_repo(
|
||||
tmpdir_factory, store, 'pcre_hooks_repo',
|
||||
tempdir_factory, store, 'pcre_hooks_repo',
|
||||
'other-regex', ['herp', 'derp'], b'',
|
||||
)
|
||||
|
||||
|
||||
@xfailif_no_pcre_support
|
||||
@pytest.mark.integration
|
||||
def test_pcre_hook_matching(tmpdir_factory, store):
|
||||
path = git_dir(tmpdir_factory)
|
||||
def test_pcre_hook_matching(tempdir_factory, store):
|
||||
path = git_dir(tempdir_factory)
|
||||
with cwd(path):
|
||||
with io.open('herp', 'w') as herp:
|
||||
herp.write("\nherpfoo'bard\n")
|
||||
@@ -210,13 +210,13 @@ def test_pcre_hook_matching(tmpdir_factory, store):
|
||||
derp.write('[INFO] information yo\n')
|
||||
|
||||
_test_hook_repo(
|
||||
tmpdir_factory, store, 'pcre_hooks_repo',
|
||||
tempdir_factory, store, 'pcre_hooks_repo',
|
||||
'regex-with-quotes', ['herp', 'derp'], b"herp:2:herpfoo'bard\n",
|
||||
expected_return_code=123,
|
||||
)
|
||||
|
||||
_test_hook_repo(
|
||||
tmpdir_factory, store, 'pcre_hooks_repo',
|
||||
tempdir_factory, store, 'pcre_hooks_repo',
|
||||
'other-regex', ['herp', 'derp'], b'derp:1:[INFO] information yo\n',
|
||||
expected_return_code=123,
|
||||
)
|
||||
@@ -224,17 +224,17 @@ def test_pcre_hook_matching(tmpdir_factory, store):
|
||||
|
||||
@xfailif_no_pcre_support
|
||||
@pytest.mark.integration
|
||||
def test_pcre_many_files(tmpdir_factory, store):
|
||||
def test_pcre_many_files(tempdir_factory, store):
|
||||
# This is intended to simulate lots of passing files and one failing file
|
||||
# to make sure it still fails. This is not the case when naively using
|
||||
# a system hook with `grep -H -n '...'` and expected_return_code=123.
|
||||
path = git_dir(tmpdir_factory)
|
||||
path = git_dir(tempdir_factory)
|
||||
with cwd(path):
|
||||
with io.open('herp', 'w') as herp:
|
||||
herp.write('[INFO] info\n')
|
||||
|
||||
_test_hook_repo(
|
||||
tmpdir_factory, store, 'pcre_hooks_repo',
|
||||
tempdir_factory, store, 'pcre_hooks_repo',
|
||||
'other-regex',
|
||||
['/dev/null'] * 15000 + ['herp'],
|
||||
b'herp:1:[INFO] info\n',
|
||||
@@ -252,20 +252,20 @@ def _norm_pwd(path):
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
def test_cwd_of_hook(tmpdir_factory, store):
|
||||
def test_cwd_of_hook(tempdir_factory, store):
|
||||
# Note: this doubles as a test for `system` hooks
|
||||
path = git_dir(tmpdir_factory)
|
||||
path = git_dir(tempdir_factory)
|
||||
with cwd(path):
|
||||
_test_hook_repo(
|
||||
tmpdir_factory, store, 'prints_cwd_repo',
|
||||
tempdir_factory, store, 'prints_cwd_repo',
|
||||
'prints_cwd', ['-L'], _norm_pwd(path) + b'\n',
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
def test_lots_of_files(tmpdir_factory, store):
|
||||
def test_lots_of_files(tempdir_factory, store):
|
||||
_test_hook_repo(
|
||||
tmpdir_factory, store, 'script_hooks_repo',
|
||||
tempdir_factory, store, 'script_hooks_repo',
|
||||
'bash_hook', ['/dev/null'] * 15000, mock.ANY,
|
||||
)
|
||||
|
||||
@@ -296,15 +296,15 @@ def test_sha(mock_repo_config):
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
def test_languages(tmpdir_factory, store):
|
||||
path = make_repo(tmpdir_factory, 'python_hooks_repo')
|
||||
def test_languages(tempdir_factory, store):
|
||||
path = make_repo(tempdir_factory, 'python_hooks_repo')
|
||||
config = make_config_from_repo(path)
|
||||
repo = Repository.create(config, store)
|
||||
assert repo.languages == set([('python', 'default')])
|
||||
|
||||
|
||||
def test_reinstall(tmpdir_factory, store, log_info_mock):
|
||||
path = make_repo(tmpdir_factory, 'python_hooks_repo')
|
||||
def test_reinstall(tempdir_factory, store, log_info_mock):
|
||||
path = make_repo(tempdir_factory, 'python_hooks_repo')
|
||||
config = make_config_from_repo(path)
|
||||
repo = Repository.create(config, store)
|
||||
repo.require_installed()
|
||||
@@ -320,9 +320,9 @@ def test_reinstall(tmpdir_factory, store, log_info_mock):
|
||||
assert log_info_mock.call_count == 0
|
||||
|
||||
|
||||
def test_control_c_control_c_on_install(tmpdir_factory, store):
|
||||
def test_control_c_control_c_on_install(tempdir_factory, store):
|
||||
"""Regression test for #186."""
|
||||
path = make_repo(tmpdir_factory, 'python_hooks_repo')
|
||||
path = make_repo(tempdir_factory, 'python_hooks_repo')
|
||||
config = make_config_from_repo(path)
|
||||
repo = Repository.create(config, store)
|
||||
hook = repo.hooks[0][1]
|
||||
@@ -352,12 +352,12 @@ def test_control_c_control_c_on_install(tmpdir_factory, store):
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
def test_really_long_file_paths(tmpdir_factory, store):
|
||||
base_path = tmpdir_factory.get()
|
||||
def test_really_long_file_paths(tempdir_factory, store):
|
||||
base_path = tempdir_factory.get()
|
||||
really_long_path = os.path.join(base_path, 'really_long' * 10)
|
||||
cmd_output('git', 'init', really_long_path)
|
||||
|
||||
path = make_repo(tmpdir_factory, 'python_hooks_repo')
|
||||
path = make_repo(tempdir_factory, 'python_hooks_repo')
|
||||
config = make_config_from_repo(path)
|
||||
|
||||
with cwd(really_long_path):
|
||||
@@ -366,8 +366,8 @@ def test_really_long_file_paths(tmpdir_factory, store):
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
def test_config_overrides_repo_specifics(tmpdir_factory, store):
|
||||
path = make_repo(tmpdir_factory, 'script_hooks_repo')
|
||||
def test_config_overrides_repo_specifics(tempdir_factory, store):
|
||||
path = make_repo(tempdir_factory, 'script_hooks_repo')
|
||||
config = make_config_from_repo(path)
|
||||
|
||||
repo = Repository.create(config, store)
|
||||
@@ -378,19 +378,19 @@ def test_config_overrides_repo_specifics(tmpdir_factory, store):
|
||||
assert repo.hooks[0][1]['files'] == '\\.sh$'
|
||||
|
||||
|
||||
def _create_repo_with_tags(tmpdir_factory, src, tag):
|
||||
path = make_repo(tmpdir_factory, src)
|
||||
def _create_repo_with_tags(tempdir_factory, src, tag):
|
||||
path = make_repo(tempdir_factory, src)
|
||||
with cwd(path):
|
||||
cmd_output('git', 'tag', tag)
|
||||
return path
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
def test_tags_on_repositories(in_tmpdir, tmpdir_factory, store):
|
||||
def test_tags_on_repositories(in_tmpdir, tempdir_factory, store):
|
||||
tag = 'v1.1'
|
||||
git_dir_1 = _create_repo_with_tags(tmpdir_factory, 'prints_cwd_repo', tag)
|
||||
git_dir_1 = _create_repo_with_tags(tempdir_factory, 'prints_cwd_repo', tag)
|
||||
git_dir_2 = _create_repo_with_tags(
|
||||
tmpdir_factory, 'script_hooks_repo', tag,
|
||||
tempdir_factory, 'script_hooks_repo', tag,
|
||||
)
|
||||
|
||||
repo_1 = Repository.create(
|
||||
|
||||
@@ -20,16 +20,16 @@ def test_init_has_no_side_effects(tmpdir):
|
||||
assert os.getcwd() == current_wd
|
||||
|
||||
|
||||
def test_create_sets_correct_directory(tmpdir_factory):
|
||||
path = git_dir(tmpdir_factory)
|
||||
def test_create_sets_correct_directory(tempdir_factory):
|
||||
path = git_dir(tempdir_factory)
|
||||
with cwd(path):
|
||||
runner = Runner.create()
|
||||
assert runner.git_root == path
|
||||
assert os.getcwd() == path
|
||||
|
||||
|
||||
def test_create_changes_to_git_root(tmpdir_factory):
|
||||
path = git_dir(tmpdir_factory)
|
||||
def test_create_changes_to_git_root(tempdir_factory):
|
||||
path = git_dir(tempdir_factory)
|
||||
with cwd(path):
|
||||
# Change into some directory, create should set to root
|
||||
foo_path = os.path.join(path, 'foo')
|
||||
@@ -48,13 +48,13 @@ def test_config_file_path():
|
||||
assert runner.config_file_path == expected_path
|
||||
|
||||
|
||||
def test_repositories(tmpdir_factory, mock_out_store_directory):
|
||||
path = make_consuming_repo(tmpdir_factory, 'script_hooks_repo')
|
||||
def test_repositories(tempdir_factory, mock_out_store_directory):
|
||||
path = make_consuming_repo(tempdir_factory, 'script_hooks_repo')
|
||||
runner = Runner(path)
|
||||
assert len(runner.repositories) == 1
|
||||
|
||||
|
||||
def test_local_hooks(tmpdir_factory, mock_out_store_directory):
|
||||
def test_local_hooks(tempdir_factory, mock_out_store_directory):
|
||||
config = OrderedDict((
|
||||
('repo', 'local'),
|
||||
('hooks', (OrderedDict((
|
||||
@@ -72,7 +72,7 @@ def test_local_hooks(tmpdir_factory, mock_out_store_directory):
|
||||
('files', '^(.*)$'),
|
||||
))))
|
||||
))
|
||||
git_path = git_dir(tmpdir_factory)
|
||||
git_path = git_dir(tempdir_factory)
|
||||
add_config_to_repo(git_path, config)
|
||||
runner = Runner(git_path)
|
||||
assert len(runner.repositories) == 1
|
||||
|
||||
@@ -27,8 +27,8 @@ def get_short_git_status():
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
def foo_staged(tmpdir_factory):
|
||||
path = git_dir(tmpdir_factory)
|
||||
def foo_staged(tempdir_factory):
|
||||
path = git_dir(tempdir_factory)
|
||||
with cwd(path):
|
||||
with io.open('foo', 'w') as foo_file:
|
||||
foo_file.write(FOO_CONTENTS)
|
||||
@@ -113,8 +113,8 @@ def test_foo_both_modify_conflicting(foo_staged, cmd_runner):
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
def img_staged(tmpdir_factory):
|
||||
path = git_dir(tmpdir_factory)
|
||||
def img_staged(tempdir_factory):
|
||||
path = git_dir(tempdir_factory)
|
||||
with cwd(path):
|
||||
img_filename = os.path.join(path, 'img.jpg')
|
||||
shutil.copy(get_resource_path('img1.jpg'), img_filename)
|
||||
@@ -168,8 +168,8 @@ def test_img_conflict(img_staged, cmd_runner):
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
def submodule_with_commits(tmpdir_factory):
|
||||
path = git_dir(tmpdir_factory)
|
||||
def submodule_with_commits(tempdir_factory):
|
||||
path = git_dir(tempdir_factory)
|
||||
with cwd(path):
|
||||
cmd_output('git', 'commit', '--allow-empty', '-m', 'foo')
|
||||
sha1 = cmd_output('git', 'rev-parse', 'HEAD')[1].strip()
|
||||
@@ -184,8 +184,8 @@ def checkout_submodule(sha):
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
def sub_staged(submodule_with_commits, tmpdir_factory):
|
||||
path = git_dir(tmpdir_factory)
|
||||
def sub_staged(submodule_with_commits, tempdir_factory):
|
||||
path = git_dir(tempdir_factory)
|
||||
with cwd(path):
|
||||
cmd_output(
|
||||
'git', 'submodule', 'add', submodule_with_commits.path, 'sub',
|
||||
|
||||
@@ -80,8 +80,8 @@ def test_does_not_recreate_if_directory_already_exists(store):
|
||||
assert not os.path.exists(os.path.join(store.directory, 'README'))
|
||||
|
||||
|
||||
def test_clone(store, tmpdir_factory, log_info_mock):
|
||||
path = git_dir(tmpdir_factory)
|
||||
def test_clone(store, tempdir_factory, log_info_mock):
|
||||
path = git_dir(tempdir_factory)
|
||||
with cwd(path):
|
||||
cmd_output('git', 'commit', '--allow-empty', '-m', 'foo')
|
||||
sha = get_head_sha(path)
|
||||
|
||||
Reference in New Issue
Block a user