Coverage for tests/test_exceptions.py: 100%
16 statements
« prev ^ index » next coverage.py v7.17.3, created at 2026-11-13 05:19 +0000
« prev ^ index » next coverage.py v7.17.3, created at 2026-11-13 05:19 +0000
1import pytest 1abcdefghijklmnopqrst
3from fast_depends.exceptions import ValidationError 1abcdefghijklmnopqrst
4from fast_depends.library.serializer import OptionItem 1abcdefghijklmnopqrst
6EXPECTED = {"a": OptionItem(field_name="a", field_type=int)} 1abcdefghijklmnopqrst
9def test_str_with_keyword_options() -> None: 1abcdefghijklmnopqrst
10 error = ValidationError( 1abcdefghijklmnopqrst
11 incoming_options={"a": "not-an-int"},
12 locations=("a",),
13 expected=EXPECTED,
14 original_error=ValueError("original"),
15 )
17 assert str(error) == ( 1abcdefghijklmnopqrst
18 "\n Incoming options: a=`not-an-int`"
19 "\n In the following option types error occurred:"
20 "\n OptionItem[a, type=`int`]"
21 )
24def test_str_with_positional_options() -> None: 1abcdefghijklmnopqrst
25 error = ValidationError( 1abcdefghijklmnopqrst
26 incoming_options="not-an-int",
27 locations=("a",),
28 expected=EXPECTED,
29 original_error=ValueError("original"),
30 )
32 assert str(error) == ( 1abcdefghijklmnopqrst
33 "\n Incoming options: `not-an-int`"
34 "\n In the following option types error occurred:"
35 "\n OptionItem[a, type=`int`]"
36 )
39def test_unknown_location_falls_back_to_all_expected_options() -> None: 1abcdefghijklmnopqrst
40 error = ValidationError( 1abcdefghijklmnopqrst
41 incoming_options={"a": "not-an-int"},
42 locations=("unknown",),
43 expected=EXPECTED,
44 original_error=ValueError("original"),
45 )
47 assert error.error_fields == tuple(EXPECTED.values()) 1abcdefghijklmnopqrst
50def test_is_a_value_error() -> None: 1abcdefghijklmnopqrst
51 with pytest.raises(ValueError): # noqa: PT011 1abcdefghijklmnopqrst
52 raise ValidationError( 1abcdefghijklmnopqrst
53 incoming_options={},
54 locations=(),
55 expected={},
56 original_error=ValueError("original"),
57 )