Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
sydney-runkle committed Apr 22, 2024
1 parent c1d6597 commit b2412fe
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion tests/validators/test_enums.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import re
import sys
from enum import Enum
from enum import Enum, IntFlag

import pytest

Expand Down Expand Up @@ -267,3 +267,21 @@ class MyEnum(Enum):

with pytest.raises(SchemaError, match='`members` should have length > 0'):
SchemaValidator(core_schema.enum_schema(MyEnum, []))


def test_missing_error_converted_to_val_error() -> None:
class MyFlags(IntFlag):
OFF = 0
ON = 1

v = SchemaValidator(
core_schema.with_default_schema(
schema=core_schema.enum_schema(MyFlags, list(MyFlags.__members__.values())), default=MyFlags.OFF
)
)

assert v.validate_python(MyFlags.OFF) is MyFlags.OFF
assert v.validate_python(0) is MyFlags.OFF

with pytest.raises(ValidationError):
v.validate_python(None)

0 comments on commit b2412fe

Please sign in to comment.