Skip to content

Commit

Permalink
Update test_list_fail_fast
Browse files Browse the repository at this point in the history
  • Loading branch information
uriyyo committed Jun 13, 2024
1 parent db30a76 commit 28fb9a9
Showing 1 changed file with 38 additions and 10 deletions.
48 changes: 38 additions & 10 deletions tests/validators/test_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,21 +397,49 @@ def f(v: int) -> int:
)


def test_list_fail_fast():
s = core_schema.list_schema(core_schema.int_schema(), fail_fast=True)
@pytest.mark.parametrize(
'fail_fast,expected',
[
pytest.param(
True,
[
{
'type': 'int_parsing',
'loc': (1,),
'msg': 'Input should be a valid integer, unable to parse string as an integer',
'input': 'not-num',
}
],
id='fail_fast',
),
pytest.param(
False,
[
{
'type': 'int_parsing',
'loc': (1,),
'msg': 'Input should be a valid integer, unable to parse string as an integer',
'input': 'not-num',
},
{
'type': 'int_parsing',
'loc': (2,),
'msg': 'Input should be a valid integer, unable to parse string as an integer',
'input': 'again',
},
],
id='not_fail_fast',
),
],
)
def test_list_fail_fast(fail_fast, expected):
s = core_schema.list_schema(core_schema.int_schema(), fail_fast=fail_fast)
v = SchemaValidator(s)

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

assert exc_info.value.errors(include_url=False) == [
{
'type': 'int_parsing',
'loc': (1,),
'msg': 'Input should be a valid integer, unable to parse string as an integer',
'input': 'not-num',
}
]
assert exc_info.value.errors(include_url=False) == expected


class MySequence(collections.abc.Sequence):
Expand Down

0 comments on commit 28fb9a9

Please sign in to comment.