From b2412fe49ed5ca7e977d3f25873f8b045858697c Mon Sep 17 00:00:00 2001 From: sydney-runkle Date: Mon, 22 Apr 2024 08:24:32 -0500 Subject: [PATCH] add test --- tests/validators/test_enums.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/tests/validators/test_enums.py b/tests/validators/test_enums.py index 89db8aa21..49abc415b 100644 --- a/tests/validators/test_enums.py +++ b/tests/validators/test_enums.py @@ -1,6 +1,6 @@ import re import sys -from enum import Enum +from enum import Enum, IntFlag import pytest @@ -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)