Skip to content

Commit 37d4e29

Browse files
committed
fix frozen set
1 parent 9aa8497 commit 37d4e29

File tree

1 file changed

+15
-21
lines changed

1 file changed

+15
-21
lines changed

tests/validators/test_frozenset.py

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import re
22
from collections import deque
33
from typing import Any
4+
from pydantic_core import core_schema as cs
5+
from pydantic_core import CoreConfig
46

57
import pytest
68

79
from pydantic_core import SchemaValidator, ValidationError
8-
from pydantic_core import core_schema as cs
910

1011
from ..conftest import Err, PyAndJson, infinite_generator, plain_repr
1112

@@ -26,14 +27,14 @@ def test_frozenset_ints_both(py_and_json: PyAndJson, input_value, expected):
2627
[([], frozenset()), ([1, '2', b'3'], {1, '2', b'3'}), (frozenset([1, '2', b'3']), {1, '2', b'3'})],
2728
)
2829
def test_frozenset_any(input_value, expected):
29-
v = SchemaValidator(schema=cs.frozenset_schema())
30+
v = SchemaValidator(cs.frozenset_schema())
3031
output = v.validate_python(input_value)
3132
assert output == expected
3233
assert isinstance(output, frozenset)
3334

3435

3536
def test_no_copy():
36-
v = SchemaValidator(schema=cs.frozenset_schema())
37+
v = SchemaValidator(cs.frozenset_schema())
3738
input_value = frozenset([1, 2, 3])
3839
output = v.validate_python(input_value)
3940
assert output == input_value
@@ -85,7 +86,7 @@ def test_frozenset_no_validators_both(py_and_json: PyAndJson, input_value, expec
8586
)
8687
@pytest.mark.thread_unsafe # generators in parameters not compatible with pytest-run-parallel, https://github.com/Quansight-Labs/pytest-run-parallel/issues/14
8788
def test_frozenset_ints_python(input_value, expected):
88-
v = SchemaValidator(schema=cs.frozenset_schema(items_schema=cs.int_schema()))
89+
v = SchemaValidator(cs.frozenset_schema(items_schema=cs.int_schema()))
8990
if isinstance(expected, Err):
9091
with pytest.raises(ValidationError, match=re.escape(expected.message)):
9192
v.validate_python(input_value)
@@ -100,14 +101,14 @@ def test_frozenset_ints_python(input_value, expected):
100101
[(frozenset([1, 2.5, '3']), {1, 2.5, '3'}), ([1, 2.5, '3'], {1, 2.5, '3'}), ([(1, 2), (3, 4)], {(1, 2), (3, 4)})],
101102
)
102103
def test_frozenset_no_validators_python(input_value, expected):
103-
v = SchemaValidator(schema=cs.frozenset_schema())
104+
v = SchemaValidator(cs.frozenset_schema())
104105
output = v.validate_python(input_value)
105106
assert output == expected
106107
assert isinstance(output, frozenset)
107108

108109

109110
def test_frozenset_multiple_errors():
110-
v = SchemaValidator(schema=cs.frozenset_schema(items_schema=cs.int_schema()))
111+
v = SchemaValidator(cs.frozenset_schema(items_schema=cs.int_schema()))
111112
with pytest.raises(ValidationError) as exc_info:
112113
v.validate_python(['a', (1, 2), []])
113114
assert exc_info.value.errors(include_url=False) == [
@@ -169,7 +170,7 @@ def generate_repeats():
169170
)
170171
@pytest.mark.thread_unsafe # generators in parameters not compatible with pytest-run-parallel, https://github.com/Quansight-Labs/pytest-run-parallel/issues/14
171172
def test_frozenset_kwargs_python(kwargs: dict[str, Any], input_value, expected):
172-
v = SchemaValidator(schema=cs.frozenset_schema(**kwargs))
173+
v = SchemaValidator(cs.frozenset_schema(**kwargs))
173174
if isinstance(expected, Err):
174175
with pytest.raises(ValidationError, match=re.escape(expected.message)):
175176
v.validate_python(input_value)
@@ -181,7 +182,7 @@ def test_frozenset_kwargs_python(kwargs: dict[str, Any], input_value, expected):
181182

182183
@pytest.mark.parametrize('input_value,expected', [({1, 2, 3}, {1, 2, 3}), ([1, 2, 3], [1, 2, 3])])
183184
def test_union_frozenset_list(input_value, expected):
184-
v = SchemaValidator(schema=cs.union_schema(choices=[cs.frozenset_schema(), cs.list_schema()]))
185+
v = SchemaValidator(cs.union_schema(choices=[cs.frozenset_schema(), cs.list_schema()]))
185186
if isinstance(expected, Err):
186187
with pytest.raises(ValidationError, match=re.escape(expected.message)):
187188
v.validate_python(input_value)
@@ -218,14 +219,7 @@ def test_union_frozenset_list(input_value, expected):
218219
],
219220
)
220221
def test_union_frozenset_int_frozenset_str(input_value, expected):
221-
v = SchemaValidator(
222-
schema=cs.union_schema(
223-
choices=[
224-
cs.frozenset_schema(items_schema=cs.int_schema(strict=True)),
225-
cs.frozenset_schema(items_schema=cs.str_schema(strict=True)),
226-
]
227-
)
228-
)
222+
v = SchemaValidator(cs.union_schema(choices=[cs.frozenset_schema(items_schema=cs.int_schema(strict=True)), cs.frozenset_schema(items_schema=cs.str_schema(strict=True))]))
229223
if isinstance(expected, Err):
230224
with pytest.raises(ValidationError, match=re.escape(expected.message)) as exc_info:
231225
v.validate_python(input_value)
@@ -244,7 +238,7 @@ def test_frozenset_as_dict_keys(py_and_json: PyAndJson):
244238

245239

246240
def test_repr():
247-
v = SchemaValidator(schema=cs.frozenset_schema(strict=True, min_length=42))
241+
v = SchemaValidator(cs.frozenset_schema(strict=True, min_length=42))
248242
assert plain_repr(v) == (
249243
'SchemaValidator('
250244
'title="frozenset[any]",'
@@ -266,7 +260,7 @@ def gen(error: bool):
266260
raise RuntimeError('my error')
267261
yield 3
268262

269-
v = SchemaValidator(schema=cs.frozenset_schema(items_schema=cs.int_schema()))
263+
v = SchemaValidator(cs.frozenset_schema(items_schema=cs.int_schema()))
270264
r = v.validate_python(gen(False))
271265
assert r == {1, 2, 3}
272266
assert isinstance(r, frozenset)
@@ -295,7 +289,7 @@ def gen(error: bool):
295289
],
296290
)
297291
def test_frozenset_from_dict_items(input_value, items_schema, expected):
298-
v = SchemaValidator(schema=cs.frozenset_schema(items_schema=items_schema))
292+
v = SchemaValidator(cs.frozenset_schema(items_schema=items_schema))
299293
output = v.validate_python(input_value)
300294
assert isinstance(output, frozenset)
301295
assert output == expected
@@ -337,9 +331,9 @@ def test_frozenset_from_dict_items(input_value, items_schema, expected):
337331
],
338332
)
339333
def test_frozenset_fail_fast(fail_fast, expected):
340-
v = SchemaValidator(schema=cs.frozenset_schema(items_schema=cs.int_schema(), fail_fast=fail_fast))
334+
v = SchemaValidator(cs.frozenset_schema(items_schema=cs.int_schema(), fail_fast=fail_fast))
341335

342336
with pytest.raises(ValidationError) as exc_info:
343337
v.validate_python([1, 'not-num', 'again'])
344338

345-
assert exc_info.value.errors(include_url=False) == expected
339+
assert exc_info.value.errors(include_url=False) == expected

0 commit comments

Comments
 (0)