}, "generated": trim(f""" import attr @attr.s class Test: foo: int = attr.ib() bar: int = attr.ib({field_meta('Bar')}) baz: float = attr.ib() """) }, "complex": { "model": ("Test", { "foo": int, "baz": DOptional(DList(DList(str))), "bar": DOptional(IntString), "qwerty": FloatString, "asdfg": DOptional(int), "dict": DDict(int), "ID": int, "not": bool, "1day": int, "день_недели": str, }), "fields_data": { "foo": { "name": "foo", "type": "int", "body": "attr.ib()" },
DList({ 'int': int, 'items': { 'count': int, 'wrapper': DList(cycle_ref) } }) }], id="cycle_with_wrapper"), pytest.param( [{"field" + str(i): int for i in range(10)}, {"field" + str(i): int for i in range(1, 10)}, {"field" + str(i): int for i in range(9)}], [{ "field0": DOptional(int), **{"field" + str(i): int for i in range(1, 9)}, "field9": DOptional(int), }], id="merge_models"), pytest.param( [{"field" + str(i): int for i in range(10)}, {"field" + str(i): int for i in range(5, 10)}, {"field" + str(i): int for i in range(5)}], [{"field" + str(i): int for i in range(10)}, {"field" + str(i): int for i in range(5, 10)}, {"field" + str(i): int
from collections import OrderedDict from random import shuffle import pytest from json_to_models.dynamic_typing import DOptional, DUnion, FloatString, IntString from json_to_models.generator import MetadataGenerator # List of fields sets | result field set test_data = [ pytest.param( [{'a': int}, {'a': int, 'b': int}], {'a': int, 'b': DOptional(int)}, id="optional_fields" ), pytest.param( [{'a': int}, {'a': float}], {'a': DUnion(int, float)}, id="union" ), pytest.param( [{'a': DUnion(str, bool)}, {'a': float}], {'a': DUnion(str, bool, float)}, id="merge_unions" ), pytest.param( [{'a': DUnion(str, bool)}, {'a': DUnion(int, float)}], {'a': DUnion(str, bool, int, float)}, id="merge_unions2" ), pytest.param(
"bar: int", "baz: float", ] }, "generated": trim(""" class Test: foo: int bar: int baz: float """) }, "complex": { "model": ("Test", { "foo": int, "baz": DOptional(DList(DList(str))), "bar": IntString, "d": DDict(Unknown) }), "fields_data": { "foo": { "name": "foo", "type": "int" }, "baz": { "name": "baz", "type": "Optional[List[List[str]]]" }, "bar": { "name": "bar", "type": "IntString"
test_data = [ pytest.param(OrderedDict([('a', int), ('b', float)]), [OrderedDict([('a', int), ('b', float)])], id="flat"), pytest.param(OrderedDict([ ('nested', OrderedDict([('a', int), ('b', float)])), ('b', float) ]), [ OrderedDict([('nested', OrderedDict([('a', int), ('b', float)])), ('b', float)]), OrderedDict([('a', int), ('b', float)]) ], id="nested"), pytest.param( OrderedDict([ ('nested', OrderedDict([('a', int), ('b', float)])), ('nested_single', DOptional(OrderedDict([('c', int), ('d', float)]))), ('nested_complex', DTuple( OrderedDict([ ('nested_2', DOptional(OrderedDict([('x', int), ('y', float)]))), ('f', float) ]), OrderedDict([('g', int), ('h', float)]), )) ]), [ # 1A OrderedDict([('nested', OrderedDict([('a', int), ('b', float)])), ('nested_single', DOptional(OrderedDict([('c', int), ('d', float)]))),
# MetaData | Optimized MetaData test_data = [ pytest.param(DUnion(int), int, id="single_DUnion"), pytest.param( {'a': DUnion({'b': int}, {'b': float})}, {'a': {'b': float}}, id="merge_nested_dicts" ), pytest.param( {'1': DUnion( {'a': DUnion({'b': int}, {'b': float})}, {'a': DUnion({'b': float}, {'b': int})}, {'a': Null}, )}, {'1': {'a': DOptional({'b': float})}}, id="merge_nested_dicts" ), pytest.param( DUnion(FloatString, IntString), FloatString, id="str_types_merge" ), pytest.param( DUnion(FloatString, BooleanString), str, id="str_types_merge_not_resolved" ), pytest.param( DList(DUnion(FloatString, BooleanString)), DList(str),