()
| 979 | |
| 980 | |
| 981 | def test_lax_or_strict_definitions() -> None: |
| 982 | cat = core_schema.typed_dict_schema({'kind': core_schema.typed_dict_field(core_schema.literal_schema(['cat']))}) |
| 983 | lax_dog = core_schema.typed_dict_schema({'kind': core_schema.typed_dict_field(core_schema.literal_schema(['DOG']))}) |
| 984 | strict_dog = core_schema.definitions_schema( |
| 985 | core_schema.typed_dict_schema({'kind': core_schema.typed_dict_field(core_schema.literal_schema(['dog']))}), |
| 986 | [core_schema.int_schema(ref='my-int-definition')], |
| 987 | ) |
| 988 | dog = core_schema.definitions_schema( |
| 989 | core_schema.lax_or_strict_schema(lax_schema=lax_dog, strict_schema=strict_dog), |
| 990 | [core_schema.str_schema(ref='my-str-definition')], |
| 991 | ) |
| 992 | discriminated_schema = apply_discriminator(core_schema.union_schema([cat, dog]), 'kind') |
| 993 | # insert_assert(discriminated_schema) |
| 994 | assert discriminated_schema == { |
| 995 | 'type': 'tagged-union', |
| 996 | 'choices': { |
| 997 | 'cat': { |
| 998 | 'type': 'typed-dict', |
| 999 | 'fields': {'kind': {'type': 'typed-dict-field', 'schema': {'type': 'literal', 'expected': ['cat']}}}, |
| 1000 | }, |
| 1001 | 'DOG': { |
| 1002 | 'type': 'lax-or-strict', |
| 1003 | 'lax_schema': { |
| 1004 | 'type': 'typed-dict', |
| 1005 | 'fields': { |
| 1006 | 'kind': {'type': 'typed-dict-field', 'schema': {'type': 'literal', 'expected': ['DOG']}} |
| 1007 | }, |
| 1008 | }, |
| 1009 | 'strict_schema': { |
| 1010 | 'type': 'definitions', |
| 1011 | 'schema': { |
| 1012 | 'type': 'typed-dict', |
| 1013 | 'fields': { |
| 1014 | 'kind': {'type': 'typed-dict-field', 'schema': {'type': 'literal', 'expected': ['dog']}} |
| 1015 | }, |
| 1016 | }, |
| 1017 | 'definitions': [{'type': 'int', 'ref': 'my-int-definition'}], |
| 1018 | }, |
| 1019 | }, |
| 1020 | 'dog': { |
| 1021 | 'type': 'lax-or-strict', |
| 1022 | 'lax_schema': { |
| 1023 | 'type': 'typed-dict', |
| 1024 | 'fields': { |
| 1025 | 'kind': {'type': 'typed-dict-field', 'schema': {'type': 'literal', 'expected': ['DOG']}} |
| 1026 | }, |
| 1027 | }, |
| 1028 | 'strict_schema': { |
| 1029 | 'type': 'definitions', |
| 1030 | 'schema': { |
| 1031 | 'type': 'typed-dict', |
| 1032 | 'fields': { |
| 1033 | 'kind': {'type': 'typed-dict-field', 'schema': {'type': 'literal', 'expected': ['dog']}} |
| 1034 | }, |
| 1035 | }, |
| 1036 | 'definitions': [{'type': 'int', 'ref': 'my-int-definition'}], |
| 1037 | }, |
| 1038 | }, |
nothing calls this directly
no test coverage detected