mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
Simplify Repository.cmd_runner
This commit is contained in:
parent
f9db2b5b06
commit
c5cbd473c7
4 changed files with 24 additions and 46 deletions
|
|
@ -5,23 +5,20 @@ from plumbum import local
|
|||
from pre_commit.clientlib.validate_config import CONFIG_JSON_SCHEMA
|
||||
from pre_commit.clientlib.validate_config import validate_config_extra
|
||||
from pre_commit.jsonschema_extensions import apply_defaults
|
||||
from pre_commit.prefixed_command_runner import PrefixedCommandRunner
|
||||
from pre_commit.repository import Repository
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
def test_install_python_repo_in_env(config_for_python_hooks_repo, store):
|
||||
repo = Repository.create(config_for_python_hooks_repo, store)
|
||||
repo.install(PrefixedCommandRunner(store.directory))
|
||||
repo.install()
|
||||
assert os.path.exists(os.path.join(store.directory, repo.sha, 'py_env'))
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
def test_run_a_python_hook(config_for_python_hooks_repo, store):
|
||||
repo = Repository.create(config_for_python_hooks_repo, store)
|
||||
ret = repo.run_hook(
|
||||
PrefixedCommandRunner(store.directory), 'foo', ['/dev/null'],
|
||||
)
|
||||
ret = repo.run_hook('foo', ['/dev/null'])
|
||||
|
||||
assert ret[0] == 0
|
||||
assert ret[1] == "['/dev/null']\nHello World\n"
|
||||
|
|
@ -30,9 +27,7 @@ def test_run_a_python_hook(config_for_python_hooks_repo, store):
|
|||
@pytest.mark.integration
|
||||
def test_lots_of_files(config_for_python_hooks_repo, store):
|
||||
repo = Repository.create(config_for_python_hooks_repo, store)
|
||||
ret = repo.run_hook(
|
||||
PrefixedCommandRunner(store.directory), 'foo', ['/dev/null'] * 15000,
|
||||
)
|
||||
ret = repo.run_hook('foo', ['/dev/null'] * 15000)
|
||||
|
||||
assert ret[0] == 0
|
||||
|
||||
|
|
@ -41,9 +36,7 @@ def test_lots_of_files(config_for_python_hooks_repo, store):
|
|||
def test_cwd_of_hook(config_for_prints_cwd_repo, store):
|
||||
# Note: this doubles as a test for `system` hooks
|
||||
repo = Repository.create(config_for_prints_cwd_repo, store)
|
||||
ret = repo.run_hook(
|
||||
PrefixedCommandRunner(store.directory), 'prints_cwd', [],
|
||||
)
|
||||
ret = repo.run_hook('prints_cwd', [])
|
||||
|
||||
assert ret[0] == 0
|
||||
assert ret[1] == repo.repo_url + '\n'
|
||||
|
|
@ -56,7 +49,7 @@ def test_cwd_of_hook(config_for_prints_cwd_repo, store):
|
|||
@pytest.mark.integration
|
||||
def test_run_a_node_hook(config_for_node_hooks_repo, store):
|
||||
repo = Repository.create(config_for_node_hooks_repo, store)
|
||||
ret = repo.run_hook(PrefixedCommandRunner(store.directory), 'foo', [])
|
||||
ret = repo.run_hook('foo', [])
|
||||
|
||||
assert ret[0] == 0
|
||||
assert ret[1] == 'Hello World\n'
|
||||
|
|
@ -65,9 +58,7 @@ def test_run_a_node_hook(config_for_node_hooks_repo, store):
|
|||
@pytest.mark.integration
|
||||
def test_run_a_script_hook(config_for_script_hooks_repo, store):
|
||||
repo = Repository.create(config_for_script_hooks_repo, store)
|
||||
ret = repo.run_hook(
|
||||
PrefixedCommandRunner(store.directory), 'bash_hook', ['bar'],
|
||||
)
|
||||
ret = repo.run_hook('bash_hook', ['bar'])
|
||||
|
||||
assert ret[0] == 0
|
||||
assert ret[1] == 'bar\nHello World\n'
|
||||
|
|
@ -106,14 +97,14 @@ def test_languages(config_for_python_hooks_repo, store):
|
|||
|
||||
def test_reinstall(config_for_python_hooks_repo, store):
|
||||
repo = Repository.create(config_for_python_hooks_repo, store)
|
||||
repo.require_installed(PrefixedCommandRunner(store.directory))
|
||||
repo.require_installed()
|
||||
# Reinstall with same repo should not trigger another install
|
||||
# TODO: how to assert this?
|
||||
repo.require_installed(PrefixedCommandRunner(store.directory))
|
||||
repo.require_installed()
|
||||
# Reinstall on another run should not trigger another install
|
||||
# TODO: how to assert this?
|
||||
repo = Repository.create(config_for_python_hooks_repo, store)
|
||||
repo.require_installed(PrefixedCommandRunner(store.directory))
|
||||
repo.require_installed()
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
|
|
@ -122,4 +113,4 @@ def test_really_long_file_paths(config_for_python_hooks_repo, store):
|
|||
local['git']['init', path]()
|
||||
with local.cwd(path):
|
||||
repo = Repository.create(config_for_python_hooks_repo, store)
|
||||
repo.require_installed(PrefixedCommandRunner(store.directory))
|
||||
repo.require_installed()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue