mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-19 17:14:43 +04:00
Implement no-dependency system and script hook types. Closes #39.
This commit is contained in:
parent
02660f7c0a
commit
c418f2b94e
14 changed files with 86 additions and 52 deletions
|
|
@ -45,7 +45,7 @@ def is_valid_according_to_schema(obj, schema):
|
|||
|
||||
@pytest.mark.parametrize(('manifest_obj', 'expected'), (
|
||||
([], False),
|
||||
([{'id': 'a', 'name': 'b', 'entry': 'c'}], True),
|
||||
([{'id': 'a', 'name': 'b', 'entry': 'c', 'language': 'python'}], True),
|
||||
(
|
||||
[{
|
||||
'id': 'a',
|
||||
|
|
|
|||
|
|
@ -59,45 +59,36 @@ def prints_cwd_repo(dummy_git_repo):
|
|||
|
||||
|
||||
@pytest.yield_fixture
|
||||
def config_for_node_hooks_repo(node_hooks_repo):
|
||||
def script_hooks_repo(dummy_git_repo):
|
||||
yield _make_repo(dummy_git_repo, 'script_hooks_repo')
|
||||
|
||||
|
||||
def _make_config(path, hook_id, file_regex):
|
||||
config = {
|
||||
'repo': node_hooks_repo,
|
||||
'sha': git.get_head_sha(node_hooks_repo),
|
||||
'hooks': [{
|
||||
'id': 'foo',
|
||||
'files': '\.js$',
|
||||
}],
|
||||
'repo': path,
|
||||
'sha': git.get_head_sha(path),
|
||||
'hooks': [{'id': hook_id, 'files': file_regex}],
|
||||
}
|
||||
jsonschema.validate([config], CONFIG_JSON_SCHEMA)
|
||||
validate_config_extra([config])
|
||||
yield config
|
||||
return config
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
def config_for_node_hooks_repo(node_hooks_repo):
|
||||
yield _make_config(node_hooks_repo, 'foo', '\.js$')
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
def config_for_python_hooks_repo(python_hooks_repo):
|
||||
config = {
|
||||
'repo': python_hooks_repo,
|
||||
'sha': git.get_head_sha(python_hooks_repo),
|
||||
'hooks': [{
|
||||
'id': 'foo',
|
||||
'files': '\.py$',
|
||||
}],
|
||||
}
|
||||
jsonschema.validate([config], CONFIG_JSON_SCHEMA)
|
||||
validate_config_extra([config])
|
||||
yield config
|
||||
yield _make_config(python_hooks_repo, 'foo', '\.py$')
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
def config_for_prints_cwd_repo(prints_cwd_repo):
|
||||
config = {
|
||||
'repo': prints_cwd_repo,
|
||||
'sha': git.get_head_sha(prints_cwd_repo),
|
||||
'hooks': [{
|
||||
'id': 'prints_cwd',
|
||||
'files': '\.py$',
|
||||
}],
|
||||
}
|
||||
jsonschema.validate([config], CONFIG_JSON_SCHEMA)
|
||||
validate_config_extra([config])
|
||||
yield config
|
||||
yield _make_config(prints_cwd_repo, 'prints_cwd', '^$')
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
def config_for_script_hooks_repo(script_hooks_repo):
|
||||
yield _make_config(script_hooks_repo, 'bash_hook', '^$')
|
||||
|
|
|
|||
|
|
@ -1,15 +1,11 @@
|
|||
|
||||
import pytest
|
||||
|
||||
import pre_commit.constants as C
|
||||
from pre_commit.languages.all import all_languages
|
||||
from pre_commit.languages.all import languages
|
||||
|
||||
|
||||
def test_all_languages_have_repo_setups():
|
||||
assert set(languages.keys()) == C.SUPPORTED_LANGUAGES
|
||||
|
||||
|
||||
@pytest.mark.parametrize('language', C.SUPPORTED_LANGUAGES)
|
||||
@pytest.mark.parametrize('language', all_languages)
|
||||
def test_all_languages_support_interface(language):
|
||||
assert hasattr(languages[language], 'install_environment')
|
||||
assert hasattr(languages[language], 'run_hook')
|
||||
|
|
|
|||
|
|
@ -67,6 +67,7 @@ def test_run_a_hook_lots_of_files(config_for_python_hooks_repo):
|
|||
|
||||
@pytest.mark.integration
|
||||
def test_cwd_of_hook(config_for_prints_cwd_repo):
|
||||
# Note: this doubles as a test for `system` hooks
|
||||
repo = Repository(config_for_prints_cwd_repo)
|
||||
ret = repo.run_hook(
|
||||
PrefixedCommandRunner(C.HOOKS_WORKSPACE), 'prints_cwd', [],
|
||||
|
|
@ -89,6 +90,17 @@ def test_run_a_node_hook(config_for_node_hooks_repo):
|
|||
assert ret[1] == 'Hello World\n'
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
def test_run_a_script_hook(config_for_script_hooks_repo):
|
||||
repo = Repository(config_for_script_hooks_repo)
|
||||
ret = repo.run_hook(
|
||||
PrefixedCommandRunner(C.HOOKS_WORKSPACE), 'bash_hook', ['bar'],
|
||||
)
|
||||
|
||||
assert ret[0] == 0
|
||||
assert ret[1] == 'bar\nHello World\n'
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_repo_config():
|
||||
config = {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue