Skip to content

Commit 77f776c

Browse files
committed
add test
1 parent a7067d3 commit 77f776c

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

tests/validators/test_json.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import re
2+
from enum import Enum
23

34
import pytest
45

@@ -152,6 +153,23 @@ def test_dict_key(py_and_json: PyAndJson):
152153
]
153154

154155

156+
def test_enum() -> None:
157+
class MyEnum(Enum):
158+
a = 'a'
159+
b = 'b'
160+
161+
enum_schema = core_schema.lax_or_strict_schema(
162+
core_schema.no_info_after_validator_function(MyEnum, core_schema.str_schema()),
163+
core_schema.is_instance_schema(MyEnum),
164+
)
165+
v = core_schema.json_schema(enum_schema)
166+
v = SchemaValidator(v)
167+
assert v.validate_python('"a"') == MyEnum.a
168+
assert v.validate_python('"b"') == MyEnum.b
169+
with pytest.raises(ValidationError):
170+
v.validate_python('"c"')
171+
172+
155173
def test_any_schema_no_schema():
156174
v = SchemaValidator(core_schema.json_schema())
157175
assert 'validator:None' in plain_repr(v)

0 commit comments

Comments
 (0)