mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-18 16:44:42 +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
|
|
@ -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