def test_as_json(): dataclass_json = generate( AClass, generators=[override_int_generator, override_str_generator], as_json=True) assert dataclass_json == json.dumps({'x': 23, 'y': 'override'})
def test_is_dataclass(): dataclass = generate( AClass, generators=[override_int_generator, override_str_generator])() assert is_dataclass(dataclass)
def test_as_dict(): dataclass_dict = generate( AClass, generators=[override_int_generator, override_str_generator], as_dict=True) assert dataclass_dict == {'x': 23, 'y': 'override'}
def test_partial_override_generator(): override = generate(AClass, generators=[override_str_generator])() assert override.x != int_generator() assert override.y == override_str_generator()
def test_complete_override_generators(): override = generate( AClass, generators=[override_int_generator, override_str_generator])() assert override.x == override_int_generator() assert override.y == override_str_generator()
def test_not_supported_type(): with pytest.raises(NotSupportedType): generate(ClassWithNoSupportedType)()
def test_simple(): generated = generate(ClassWithYDefault)() assert generated.y == ClassWithYDefault.y # default value provided assert (generated.x != int_generator() ) # no default value provided, so it will use the generator
from fistro.fistro import generate from fistro.fistro import generate_from_json, get_class_body_from_annotations @dataclass class Employee: id: int birthday: date last_access: datetime password: str number_plates: List[int] name: str = 'Carlos Sánchez' employee = generate(Employee)() print(employee) specific_str = """{ "_id": "5ae09b3947467b00111e7bf6", "localExposure": 0, "answer": "mitigate", "idRisk": "5ae09b3947467b00111e7bf6", "version": 4, "country": "BR", "company": "0185", "currency": "BRL", "zone": "DIRT8", "internalRef": "RSP-BR-0185-DIRT8-105", "creationDate": "2017-12-13T23:00:00.000Z", "title": "Tributário: Contribuições Previdenciárias sobre Plano de Stock Options",