mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-18 08:34:41 +04:00
Add support for meta hooks
This commit is contained in:
parent
39d5205e31
commit
88c676a7c1
6 changed files with 130 additions and 1 deletions
|
|
@ -645,6 +645,31 @@ def test_local_hook_fails(
|
|||
)
|
||||
|
||||
|
||||
def test_meta_hook_passes(
|
||||
cap_out, repo_with_passing_hook, mock_out_store_directory,
|
||||
):
|
||||
config = OrderedDict((
|
||||
('repo', 'meta'),
|
||||
(
|
||||
'hooks', (
|
||||
OrderedDict((
|
||||
('id', 'test-hook'),
|
||||
)),
|
||||
),
|
||||
),
|
||||
))
|
||||
add_config_to_repo(repo_with_passing_hook, config)
|
||||
|
||||
_test_run(
|
||||
cap_out,
|
||||
repo_with_passing_hook,
|
||||
opts={'verbose': True},
|
||||
expected_outputs=[b'Hello World!'],
|
||||
expected_ret=0,
|
||||
stage=False,
|
||||
)
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
def modified_config_repo(repo_with_passing_hook):
|
||||
with modify_config(repo_with_passing_hook, commit=False) as config:
|
||||
|
|
|
|||
|
|
@ -709,6 +709,18 @@ def test_hook_id_not_present(tempdir_factory, store, fake_log_handler):
|
|||
)
|
||||
|
||||
|
||||
def test_meta_hook_not_present(store, fake_log_handler):
|
||||
config = {'repo': 'meta', 'hooks': [{'id': 'i-dont-exist'}]}
|
||||
repo = Repository.create(config, store)
|
||||
with pytest.raises(SystemExit):
|
||||
repo.require_installed()
|
||||
assert fake_log_handler.handle.call_args[0][0].msg == (
|
||||
'`i-dont-exist` is not a valid meta hook. '
|
||||
'Typo? Perhaps it is introduced in a newer version? '
|
||||
'Often `pre-commit autoupdate` fixes this.'
|
||||
)
|
||||
|
||||
|
||||
def test_too_new_version(tempdir_factory, store, fake_log_handler):
|
||||
path = make_repo(tempdir_factory, 'script_hooks_repo')
|
||||
with modify_manifest(path) as manifest:
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ from pre_commit.schema import load_from_filename
|
|||
from pre_commit.schema import Map
|
||||
from pre_commit.schema import MISSING
|
||||
from pre_commit.schema import Not
|
||||
from pre_commit.schema import NotIn
|
||||
from pre_commit.schema import Optional
|
||||
from pre_commit.schema import OptionalNoDefault
|
||||
from pre_commit.schema import remove_defaults
|
||||
|
|
@ -107,6 +108,16 @@ def test_not(val, expected):
|
|||
assert (compared == val) is expected
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
('values', 'expected'),
|
||||
(('bar', True), ('foo', False), (MISSING, False)),
|
||||
)
|
||||
def test_not_in(values, expected):
|
||||
compared = NotIn(('baz', 'foo'))
|
||||
assert (values == compared) is expected
|
||||
assert (compared == values) is expected
|
||||
|
||||
|
||||
trivial_array_schema = Array(Map('foo', 'id'))
|
||||
|
||||
|
||||
|
|
@ -196,6 +207,13 @@ map_conditional_absent_not = Map(
|
|||
condition_key='key', condition_value=Not(True), ensure_absent=True,
|
||||
),
|
||||
)
|
||||
map_conditional_absent_not_in = Map(
|
||||
'foo', 'key',
|
||||
Conditional(
|
||||
'key2', check_bool,
|
||||
condition_key='key', condition_value=NotIn((1, 2)), ensure_absent=True,
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('schema', (map_conditional, map_conditional_not))
|
||||
|
|
@ -248,6 +266,19 @@ def test_ensure_absent_conditional_not():
|
|||
)
|
||||
|
||||
|
||||
def test_ensure_absent_conditional_not_in():
|
||||
with pytest.raises(ValidationError) as excinfo:
|
||||
validate({'key': 1, 'key2': True}, map_conditional_absent_not_in)
|
||||
_assert_exception_trace(
|
||||
excinfo.value,
|
||||
(
|
||||
'At foo(key=1)',
|
||||
'Expected key2 to be absent when key is any of (1, 2), '
|
||||
'found key2: True',
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
def test_no_error_conditional_absent():
|
||||
validate({}, map_conditional_absent)
|
||||
validate({}, map_conditional_absent_not)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue