|
19 | 19 | from pre_commit.schema import Map |
20 | 20 | from pre_commit.schema import MISSING |
21 | 21 | from pre_commit.schema import Not |
| 22 | +from pre_commit.schema import NotIn |
22 | 23 | from pre_commit.schema import Optional |
23 | 24 | from pre_commit.schema import OptionalNoDefault |
24 | 25 | from pre_commit.schema import remove_defaults |
@@ -107,6 +108,16 @@ def test_not(val, expected): |
107 | 108 | assert (compared == val) is expected |
108 | 109 |
|
109 | 110 |
|
| 111 | +@pytest.mark.parametrize( |
| 112 | + ('values', 'expected'), |
| 113 | + (('bar', True), ('foo', False), (MISSING, False)), |
| 114 | +) |
| 115 | +def test_not_in(values, expected): |
| 116 | + compared = NotIn(('baz', 'foo')) |
| 117 | + assert (values == compared) is expected |
| 118 | + assert (compared == values) is expected |
| 119 | + |
| 120 | + |
110 | 121 | trivial_array_schema = Array(Map('foo', 'id')) |
111 | 122 |
|
112 | 123 |
|
@@ -196,6 +207,13 @@ def test_optional_key_missing(schema): |
196 | 207 | condition_key='key', condition_value=Not(True), ensure_absent=True, |
197 | 208 | ), |
198 | 209 | ) |
| 210 | +map_conditional_absent_not_in = Map( |
| 211 | + 'foo', 'key', |
| 212 | + Conditional( |
| 213 | + 'key2', check_bool, |
| 214 | + condition_key='key', condition_value=NotIn((1, 2)), ensure_absent=True, |
| 215 | + ), |
| 216 | +) |
199 | 217 |
|
200 | 218 |
|
201 | 219 | @pytest.mark.parametrize('schema', (map_conditional, map_conditional_not)) |
@@ -248,6 +266,19 @@ def test_ensure_absent_conditional_not(): |
248 | 266 | ) |
249 | 267 |
|
250 | 268 |
|
| 269 | +def test_ensure_absent_conditional_not_in(): |
| 270 | + with pytest.raises(ValidationError) as excinfo: |
| 271 | + validate({'key': 1, 'key2': True}, map_conditional_absent_not_in) |
| 272 | + _assert_exception_trace( |
| 273 | + excinfo.value, |
| 274 | + ( |
| 275 | + 'At foo(key=1)', |
| 276 | + 'Expected key2 to be absent when key is any of (1, 2), ' |
| 277 | + 'found key2: True', |
| 278 | + ), |
| 279 | + ) |
| 280 | + |
| 281 | + |
251 | 282 | def test_no_error_conditional_absent(): |
252 | 283 | validate({}, map_conditional_absent) |
253 | 284 | validate({}, map_conditional_absent_not) |
|
0 commit comments