Skip to content

Commit b2412fe

Browse files
committed
add test
1 parent c1d6597 commit b2412fe

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

tests/validators/test_enums.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import re
22
import sys
3-
from enum import Enum
3+
from enum import Enum, IntFlag
44

55
import pytest
66

@@ -267,3 +267,21 @@ class MyEnum(Enum):
267267

268268
with pytest.raises(SchemaError, match='`members` should have length > 0'):
269269
SchemaValidator(core_schema.enum_schema(MyEnum, []))
270+
271+
272+
def test_missing_error_converted_to_val_error() -> None:
273+
class MyFlags(IntFlag):
274+
OFF = 0
275+
ON = 1
276+
277+
v = SchemaValidator(
278+
core_schema.with_default_schema(
279+
schema=core_schema.enum_schema(MyFlags, list(MyFlags.__members__.values())), default=MyFlags.OFF
280+
)
281+
)
282+
283+
assert v.validate_python(MyFlags.OFF) is MyFlags.OFF
284+
assert v.validate_python(0) is MyFlags.OFF
285+
286+
with pytest.raises(ValidationError):
287+
v.validate_python(None)

0 commit comments

Comments
 (0)