def deserialize(**kwargs: Union[str, EnumParser]) -> entities.StatePerson: return entity_deserialize( cls=entities.StatePerson, converter_overrides={ "residency_status": EntityFieldConverter(str, parse_residency_status), "full_name": EntityFieldConverter(str, normalize_flat_json), }, **kwargs)
def deserialize(**kwargs: Union[str, EnumParser] ) -> entities.StateSentenceGroup: return entity_deserialize( cls=entities.StateSentenceGroup, converter_overrides={ "status": EntityFieldConverter( EnumParser, get_parser_for_enum_with_default( StateSentenceStatus.PRESENT_WITHOUT_INFO), ), }, **kwargs)
def test_entity_deserialize_not_attr(self) -> None: with self.assertRaises(ValueError) as e: class _NotAnAttr: def __init__(self) -> None: self.an_int_field = 1 _ = entity_deserialize( # type: ignore[type-var] _NotAnAttr, converter_overrides={}, an_int_field="1" ) self.assertTrue( str(e.exception).startswith( "Can only deserialize attrs classes with entity_deserialize()" ) )
def test_entity_deserialize_not_entity(self) -> None: with self.assertRaises(ValueError) as e: @attr.s class _NotAnEntity: an_int_field: int = attr.ib(default=1) _ = entity_deserialize( # type: ignore[type-var] _NotAnEntity, converter_overrides={}, an_int_field="1" ) self.assertTrue( str(e.exception).startswith( "Can only deserialize Entity classes with entity_deserialize()" ) )
def deserialize( **kwargs: Union[str, EnumParser] ) -> MyEntityWithFieldOverrides: return entity_deserialize( MyEntityWithFieldOverrides, converter_overrides={ "str_with_override": EntityFieldConverter(str, str.lower), "int_with_override": EntityFieldConverter( str, parse_int_and_double ), "enum_with_override": EntityFieldConverter( EnumParser, set_race_to_white ), }, **kwargs )
def deserialize(**kwargs: Union[str, EnumParser] ) -> entities.StatePersonEthnicity: return entity_deserialize(cls=entities.StatePersonEthnicity, converter_overrides={}, **kwargs)
def deserialize(**kwargs: Union[str, EnumParser]) -> MyEntity: return entity_deserialize(MyEntity, converter_overrides={}, **kwargs)