File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change 1
1
import re
2
+ from enum import Enum
2
3
3
4
import pytest
4
5
@@ -152,6 +153,23 @@ def test_dict_key(py_and_json: PyAndJson):
152
153
]
153
154
154
155
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
+
155
173
def test_any_schema_no_schema ():
156
174
v = SchemaValidator (core_schema .json_schema ())
157
175
assert 'validator:None' in plain_repr (v )
You can’t perform that action at this time.
0 commit comments