def test_optional_multiple_types(self): self.assertFieldsEqual( field_for_schema(Optional[Union[int, str]]), union_field.Union( [ ( int, fields.Integer(allow_none=True, required=False, default=None, missing=None), ), ( str, fields.String(allow_none=True, required=False, default=None, missing=None), ), ], required=False, default=None, missing=None, ), )
def test_union_multiple_types_with_none(self): self.assertFieldsEqual( field_for_schema(Union[int, str, None]), union_field.Union( [ ( int, fields.Integer( allow_none=True, required=False, dump_default=None, load_default=None, ), ), ( str, fields.String( allow_none=True, required=False, dump_default=None, load_default=None, ), ), ], required=False, dump_default=None, load_default=None, ), )
def test_union(self): self.assertFieldsEqual( field_for_schema(Union[int, str]), union_field.Union( [ (int, fields.Integer(required=True)), (str, fields.String(required=True)), ], required=True, ), )