Remove plumbum

This commit is contained in:
Anthony Sottile 2014-10-01 17:27:23 -07:00
parent 5d9ba14841
commit bbd2572b11
24 changed files with 236 additions and 203 deletions

View file

@ -2,7 +2,6 @@ from __future__ import unicode_literals
import pytest
import shutil
from plumbum import local
import pre_commit.constants as C
from pre_commit.commands.autoupdate import _update_repository
@ -10,6 +9,8 @@ from pre_commit.commands.autoupdate import autoupdate
from pre_commit.commands.autoupdate import RepositoryCannotBeUpdatedError
from pre_commit.ordereddict import OrderedDict
from pre_commit.runner import Runner
from pre_commit.util import cmd_output
from pre_commit.util import cwd
from testing.auto_namedtuple import auto_namedtuple
from testing.fixtures import make_config_from_repo
from testing.fixtures import make_repo
@ -52,8 +53,8 @@ def out_of_date_repo(tmpdir_factory):
original_sha = get_head_sha(path)
# Make a commit
with local.cwd(path):
local['git']['commit', '--allow-empty', '-m', 'foo']()
with cwd(path):
cmd_output('git', 'commit', '--allow-empty', '-m', 'foo')
head_sha = get_head_sha(path)
yield auto_namedtuple(
@ -95,13 +96,13 @@ def hook_disappearing_repo(tmpdir_factory):
path = make_repo(tmpdir_factory, 'python_hooks_repo')
original_sha = get_head_sha(path)
with local.cwd(path):
with cwd(path):
shutil.copy(
get_resource_path('manifest_without_foo.yaml'),
C.MANIFEST_FILE,
)
local['git']('add', '.')
local['git']('commit', '-m', 'Remove foo')
cmd_output('git', 'add', '.')
cmd_output('git', 'commit', '-m', 'Remove foo')
yield auto_namedtuple(path=path, original_sha=original_sha)

View file

@ -9,7 +9,6 @@ import re
import subprocess
import stat
import sys
from plumbum import local
from pre_commit.commands.install_uninstall import IDENTIFYING_HASH
from pre_commit.commands.install_uninstall import PREVIOUS_IDENTIFYING_HASHES
@ -19,6 +18,8 @@ from pre_commit.commands.install_uninstall import is_previous_pre_commit
from pre_commit.commands.install_uninstall import make_executable
from pre_commit.commands.install_uninstall import uninstall
from pre_commit.runner import Runner
from pre_commit.util import cmd_output
from pre_commit.util import cwd
from pre_commit.util import resource_filename
from testing.fixtures import git_dir
from testing.fixtures import make_consuming_repo
@ -86,13 +87,13 @@ def _get_commit_output(
home=None,
env_base=os.environ,
):
local['touch'](touch_file)
local['git']('add', touch_file)
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()
env = dict(env_base, **{'PRE_COMMIT_HOME': home})
return local['git'].run(
['commit', '-m', 'Commit!', '--allow-empty'],
return cmd_output(
'git', 'commit', '-m', 'Commit!', '--allow-empty',
# git commit puts pre-commit to stderr
stderr=subprocess.STDOUT,
env=env,
@ -123,7 +124,7 @@ NORMAL_PRE_COMMIT_RUN = re.compile(
def test_install_pre_commit_and_run(tmpdir_factory):
path = make_consuming_repo(tmpdir_factory, 'script_hooks_repo')
with local.cwd(path):
with cwd(path):
assert install(Runner(path)) == 0
ret, output = _get_commit_output(tmpdir_factory)
@ -133,7 +134,7 @@ def test_install_pre_commit_and_run(tmpdir_factory):
def test_install_idempotent(tmpdir_factory):
path = make_consuming_repo(tmpdir_factory, 'script_hooks_repo')
with local.cwd(path):
with cwd(path):
assert install(Runner(path)) == 0
assert install(Runner(path)) == 0
@ -144,13 +145,13 @@ def test_install_idempotent(tmpdir_factory):
def test_environment_not_sourced(tmpdir_factory):
path = make_consuming_repo(tmpdir_factory, 'script_hooks_repo')
with local.cwd(path):
with cwd(path):
# Patch the executable to simulate rming virtualenv
with mock.patch.object(sys, 'executable', '/bin/false'):
assert install(Runner(path)) == 0
ret, stdout, stderr = local['git'].run(
['commit', '--allow-empty', '-m', 'foo'],
ret, stdout, stderr = cmd_output(
'git', 'commit', '--allow-empty', '-m', 'foo',
env={'HOME': os.environ['HOME']},
retcode=None,
)
@ -177,7 +178,7 @@ FAILING_PRE_COMMIT_RUN = re.compile(
def test_failing_hooks_returns_nonzero(tmpdir_factory):
path = make_consuming_repo(tmpdir_factory, 'failing_hook_repo')
with local.cwd(path):
with cwd(path):
assert install(Runner(path)) == 0
ret, output = _get_commit_output(tmpdir_factory)
@ -195,7 +196,7 @@ EXISTING_COMMIT_RUN = re.compile(
def test_install_existing_hooks_no_overwrite(tmpdir_factory):
path = make_consuming_repo(tmpdir_factory, 'script_hooks_repo')
with local.cwd(path):
with cwd(path):
runner = Runner(path)
# Write out an "old" hook
@ -220,7 +221,7 @@ def test_install_existing_hooks_no_overwrite(tmpdir_factory):
def test_install_existing_hook_no_overwrite_idempotent(tmpdir_factory):
path = make_consuming_repo(tmpdir_factory, 'script_hooks_repo')
with local.cwd(path):
with cwd(path):
runner = Runner(path)
# Write out an "old" hook
@ -250,7 +251,7 @@ FAIL_OLD_HOOK = re.compile(
def test_failing_existing_hook_returns_1(tmpdir_factory):
path = make_consuming_repo(tmpdir_factory, 'script_hooks_repo')
with local.cwd(path):
with cwd(path):
runner = Runner(path)
# Write out a failing "old" hook
@ -268,7 +269,7 @@ def test_failing_existing_hook_returns_1(tmpdir_factory):
def test_install_overwrite_no_existing_hooks(tmpdir_factory):
path = make_consuming_repo(tmpdir_factory, 'script_hooks_repo')
with local.cwd(path):
with cwd(path):
assert install(Runner(path), overwrite=True) == 0
ret, output = _get_commit_output(tmpdir_factory)
@ -278,7 +279,7 @@ def test_install_overwrite_no_existing_hooks(tmpdir_factory):
def test_install_overwrite(tmpdir_factory):
path = make_consuming_repo(tmpdir_factory, 'script_hooks_repo')
with local.cwd(path):
with cwd(path):
runner = Runner(path)
# Write out the "old" hook
@ -295,7 +296,7 @@ def test_install_overwrite(tmpdir_factory):
def test_uninstall_restores_legacy_hooks(tmpdir_factory):
path = make_consuming_repo(tmpdir_factory, 'script_hooks_repo')
with local.cwd(path):
with cwd(path):
runner = Runner(path)
# Write out an "old" hook
@ -315,7 +316,7 @@ def test_uninstall_restores_legacy_hooks(tmpdir_factory):
def test_replace_old_commit_script(tmpdir_factory):
path = make_consuming_repo(tmpdir_factory, 'script_hooks_repo')
with local.cwd(path):
with cwd(path):
runner = Runner(path)
# Install a script that looks like our old script
@ -340,7 +341,7 @@ def test_replace_old_commit_script(tmpdir_factory):
def test_uninstall_doesnt_remove_not_our_hooks(tmpdir_factory):
path = git_dir(tmpdir_factory)
with local.cwd(path):
with cwd(path):
runner = Runner(path)
with io.open(runner.pre_commit_path, 'w') as pre_commit_file:
pre_commit_file.write('#!/usr/bin/env bash\necho 1\n')
@ -364,7 +365,7 @@ def test_installs_hooks_with_hooks_True(
mock_out_store_directory,
):
path = make_consuming_repo(tmpdir_factory, 'script_hooks_repo')
with local.cwd(path):
with cwd(path):
install(Runner(path), hooks=True)
ret, output = _get_commit_output(
tmpdir_factory, home=mock_out_store_directory,
@ -376,7 +377,7 @@ def test_installs_hooks_with_hooks_True(
def test_installed_from_venv(tmpdir_factory):
path = make_consuming_repo(tmpdir_factory, 'script_hooks_repo')
with local.cwd(path):
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

View file

@ -7,13 +7,14 @@ import os
import os.path
import pytest
import subprocess
from plumbum import local
from pre_commit.commands.install_uninstall import install
from pre_commit.commands.run import _get_skips
from pre_commit.commands.run import _has_unmerged_paths
from pre_commit.commands.run import run
from pre_commit.runner import Runner
from pre_commit.util import cmd_output
from pre_commit.util import cwd
from testing.auto_namedtuple import auto_namedtuple
from testing.fixtures import make_consuming_repo
@ -21,20 +22,20 @@ 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')
with local.cwd(git_path):
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')
with local.cwd(git_path):
with cwd(git_path):
yield git_path
def stage_a_file():
local['touch']('foo.py')
local['git']('add', 'foo.py')
cmd_output('touch', 'foo.py')
cmd_output('git', 'add', 'foo.py')
def get_write_mock_output(write_mock):
@ -180,7 +181,7 @@ def test_merge_conflict_modified(in_merge_conflict, mock_out_store_directory):
def test_merge_conflict_resolved(in_merge_conflict, mock_out_store_directory):
local['git']('add', '.')
cmd_output('git', 'add', '.')
ret, printed = _do_run(in_merge_conflict, _get_opts())
for msg in ('Checking merge-conflict files only.', 'Bash hook', 'Passed'):
assert msg in printed
@ -228,11 +229,11 @@ def test_hook_id_in_verbose_output(
def test_multiple_hooks_same_id(
repo_with_passing_hook, mock_out_store_directory,
):
with local.cwd(repo_with_passing_hook):
with cwd(repo_with_passing_hook):
# Add bash hook on there again
with io.open('.pre-commit-config.yaml', 'a+') as config_file:
config_file.write(' - id: bash_hook\n')
local['git']('add', '.pre-commit-config.yaml')
cmd_output('git', 'add', '.pre-commit-config.yaml')
stage_a_file()
ret, output = _do_run(repo_with_passing_hook, _get_opts())
@ -243,11 +244,11 @@ def test_multiple_hooks_same_id(
def test_stdout_write_bug_py26(
repo_with_failing_hook, mock_out_store_directory, tmpdir_factory,
):
with local.cwd(repo_with_failing_hook):
with cwd(repo_with_failing_hook):
# Add bash hook on there again
with io.open('.pre-commit-config.yaml', 'a+') as config_file:
config_file.write(' args: [""]\n')
local['git']('add', '.pre-commit-config.yaml')
cmd_output('git', 'add', '.pre-commit-config.yaml')
stage_a_file()
install(Runner(repo_with_failing_hook))
@ -255,8 +256,8 @@ def test_stdout_write_bug_py26(
# Don't want to write to home directory
env = dict(os.environ, **{'PRE_COMMIT_HOME': tmpdir_factory.get()})
# Have to use subprocess because pytest monkeypatches sys.stdout
_, stdout, _ = local['git'].run(
('commit', '-m', 'Commit!'),
_, stdout, _ = cmd_output(
'git', 'commit', '-m', 'Commit!',
# git commit puts pre-commit to stderr
stderr=subprocess.STDOUT,
env=env,