mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
Make hooks specify files. Optionally allow config to override manifest.
This commit is contained in:
parent
0ec9020346
commit
96174deac6
25 changed files with 81 additions and 50 deletions
|
|
@ -46,20 +46,34 @@ def test_additional_manifest_check_languages_failing(obj):
|
|||
additional_manifest_check(obj)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(('manifest_obj', 'expected'), (
|
||||
([], False),
|
||||
([{'id': 'a', 'name': 'b', 'entry': 'c', 'language': 'python'}], True),
|
||||
@pytest.mark.parametrize(
|
||||
('manifest_obj', 'expected'),
|
||||
(
|
||||
[{
|
||||
'id': 'a',
|
||||
'name': 'b',
|
||||
'entry': 'c',
|
||||
'language': 'python',
|
||||
'expected_return_value': 0,
|
||||
}],
|
||||
True,
|
||||
),
|
||||
))
|
||||
([], False),
|
||||
(
|
||||
[{
|
||||
'id': 'a',
|
||||
'name': 'b',
|
||||
'entry': 'c',
|
||||
'language': 'python',
|
||||
'files': r'\.py$'
|
||||
}],
|
||||
True,
|
||||
),
|
||||
(
|
||||
[{
|
||||
'id': 'a',
|
||||
'name': 'b',
|
||||
'entry': 'c',
|
||||
'language': 'python',
|
||||
'language_version': 'python3.3',
|
||||
'files': r'\.py$',
|
||||
'expected_return_value': 0,
|
||||
}],
|
||||
True,
|
||||
),
|
||||
)
|
||||
)
|
||||
def test_is_valid_according_to_schema(manifest_obj, expected):
|
||||
ret = is_valid_according_to_schema(manifest_obj, MANIFEST_JSON_SCHEMA)
|
||||
assert ret is expected
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ def up_to_date_repo(python_hooks_repo):
|
|||
config = OrderedDict((
|
||||
('repo', python_hooks_repo),
|
||||
('sha', get_head_sha(python_hooks_repo)),
|
||||
('hooks', [OrderedDict((('id', 'foo'), ('files', '')))]),
|
||||
('hooks', [OrderedDict((('id', 'foo'),))]),
|
||||
))
|
||||
wrapped_config = apply_defaults([config], CONFIG_JSON_SCHEMA)
|
||||
validate_config_extra(wrapped_config)
|
||||
|
|
@ -147,7 +147,7 @@ def hook_disappearing_repo(python_hooks_repo):
|
|||
config = OrderedDict((
|
||||
('repo', python_hooks_repo),
|
||||
('sha', get_head_sha(python_hooks_repo)),
|
||||
('hooks', [OrderedDict((('id', 'foo'), ('files', '')))]),
|
||||
('hooks', [OrderedDict((('id', 'foo'),))]),
|
||||
))
|
||||
config_wrapped = apply_defaults([config], CONFIG_JSON_SCHEMA)
|
||||
validate_config_extra(config_wrapped)
|
||||
|
|
|
|||
|
|
@ -122,11 +122,11 @@ def system_hook_with_spaces_repo(dummy_git_repo):
|
|||
yield _make_repo(dummy_git_repo, 'system_hook_with_spaces_repo')
|
||||
|
||||
|
||||
def _make_config(path, hook_id, file_regex):
|
||||
def _make_config(path, hook_id):
|
||||
config = {
|
||||
'repo': path,
|
||||
'sha': get_head_sha(path),
|
||||
'hooks': [{'id': hook_id, 'files': file_regex}],
|
||||
'hooks': [{'id': hook_id}],
|
||||
}
|
||||
config_wrapped = apply_defaults([config], CONFIG_JSON_SCHEMA)
|
||||
validate_config_extra(config_wrapped)
|
||||
|
|
@ -135,48 +135,48 @@ def _make_config(path, hook_id, file_regex):
|
|||
|
||||
@pytest.yield_fixture
|
||||
def config_for_node_hooks_repo(node_hooks_repo):
|
||||
yield _make_config(node_hooks_repo, 'foo', '\\.js$')
|
||||
yield _make_config(node_hooks_repo, 'foo')
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
def config_for_node_0_11_8_hooks_repo(node_0_11_8_hooks_repo):
|
||||
yield _make_config(node_0_11_8_hooks_repo, 'node-11-8-hook', '\\.js$')
|
||||
yield _make_config(node_0_11_8_hooks_repo, 'node-11-8-hook')
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
def config_for_ruby_hooks_repo(ruby_hooks_repo):
|
||||
yield _make_config(ruby_hooks_repo, 'ruby_hook', '\\.rb$')
|
||||
yield _make_config(ruby_hooks_repo, 'ruby_hook')
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
def config_for_ruby_1_9_3_p547_hooks_repo(ruby_1_9_3_p547_hooks_repo):
|
||||
yield _make_config(ruby_1_9_3_p547_hooks_repo, 'ruby_hook', '\\.rb$')
|
||||
yield _make_config(ruby_1_9_3_p547_hooks_repo, 'ruby_hook')
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
def config_for_python_hooks_repo(python_hooks_repo):
|
||||
yield _make_config(python_hooks_repo, 'foo', '\\.py$')
|
||||
yield _make_config(python_hooks_repo, 'foo')
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
def config_for_python3_hooks_repo(python3_hooks_repo):
|
||||
yield _make_config(python3_hooks_repo, 'python3-hook', '\\.py$')
|
||||
yield _make_config(python3_hooks_repo, 'python3-hook')
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
def config_for_prints_cwd_repo(prints_cwd_repo):
|
||||
yield _make_config(prints_cwd_repo, 'prints_cwd', '^$')
|
||||
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', '')
|
||||
yield _make_config(script_hooks_repo, 'bash_hook')
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
def config_for_system_hook_with_spaces(system_hook_with_spaces_repo):
|
||||
yield _make_config(
|
||||
system_hook_with_spaces_repo, 'system-hook-with-spaces', '',
|
||||
system_hook_with_spaces_repo, 'system-hook-with-spaces',
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -198,7 +198,7 @@ def repo_with_passing_hook(config_for_script_hooks_repo, empty_git_dir):
|
|||
|
||||
@pytest.yield_fixture
|
||||
def repo_with_failing_hook(failing_hook_repo, empty_git_dir):
|
||||
_make_repo_from_configs(_make_config(failing_hook_repo, 'failing_hook', ''))
|
||||
_make_repo_from_configs(_make_config(failing_hook_repo, 'failing_hook'))
|
||||
yield empty_git_dir
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ def test_manifest_contents(manifest):
|
|||
'description': '',
|
||||
'entry': 'bin/hook.sh',
|
||||
'expected_return_value': 0,
|
||||
'files': '',
|
||||
'id': 'bash_hook',
|
||||
'language': 'script',
|
||||
'language_version': 'default',
|
||||
|
|
@ -29,6 +30,7 @@ def test_hooks(manifest):
|
|||
'description': '',
|
||||
'entry': 'bin/hook.sh',
|
||||
'expected_return_value': 0,
|
||||
'files': '',
|
||||
'id': 'bash_hook',
|
||||
'language': 'script',
|
||||
'language_version': 'default',
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ def test_run_versioned_hook(config_for_python3_hooks_repo, store):
|
|||
assert ret[1] == "3.3\n['/dev/null']\nHello World\n"
|
||||
|
||||
|
||||
@skipif_slowtests_false
|
||||
@pytest.mark.integration
|
||||
def test_run_versioned_node_hook(config_for_node_0_11_8_hooks_repo, store):
|
||||
repo = Repository.create(config_for_node_0_11_8_hooks_repo, store)
|
||||
|
|
@ -152,3 +153,13 @@ def test_really_long_file_paths(config_for_python_hooks_repo, store):
|
|||
with local.cwd(path):
|
||||
repo = Repository.create(config_for_python_hooks_repo, store)
|
||||
repo.require_installed()
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
def test_config_overrides_repo_specifics(config_for_script_hooks_repo, store):
|
||||
repo = Repository.create(config_for_script_hooks_repo, store)
|
||||
assert repo.hooks['bash_hook']['files'] == ''
|
||||
# Set the file regex to something else
|
||||
config_for_script_hooks_repo['hooks'][0]['files'] = '\\.sh$'
|
||||
repo = Repository.create(config_for_script_hooks_repo, store)
|
||||
assert repo.hooks['bash_hook']['files'] == '\\.sh$'
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue