def tuple_dict(): PT = procrustes.Tuple(I, S, I) PD = procrustes.Dict({'a': I, 'b': S, 'c': PT}) pd = PD({'b': 'kuku', 'c': (None, 'Lorem', 91)}) Assert(pd.data) == {'a': None, 'c': (None, 'Lorem', None), 'b': 'kuku'} pd = PD({'b': 'kuku', 'c': (None, 'Lorem', 90)}) Assert(pd.data) == {'a': None, 'c': (None, 'Lorem', 90), 'b': 'kuku'}
def simple_dict(): PD = procrustes.Dict({'a': I, 'b': S}) pd = PD({'a': None, 'b': 'Lorem Ipsum'}) Assert(pd.data) == {'a': None, 'b': 'Lorem Ipsum'} pd = PD({'b': 'Lorem Ipsum'}) Assert(pd.data) == {'a': None, 'b': 'Lorem Ipsum'}
def empty_flatten(): I = procrustes.Integer(max=90, required=False) S = procrustes.String() PL = procrustes.List(I) PD = procrustes.Dict({'a': I, 'b': S}) PT = procrustes.Tuple(I, S, I, PL, PD) Assert(dict(PT().flatten())) == { '4__b': None, '4__a': None, '1': None, '0': None, '2': None, '3__0': None }
def flat_deepen(): PT = procrustes.Tuple(I, S, I) PD = procrustes.Dict({'a': I, 'b': S, 'c': PT}) pd = PD({'b': 'kuku', 'c': (None, 'Lorem', 78)}) flat = dict(pd.flatten()) Assert(flat) == { 'a': None, 'c__2': 78, 'c__1': 'Lorem', 'c__0': None, 'b': 'kuku' } flat = {'a': None, 'c__2': 78, 'c__1': 'Lorem', 'b': 'kuku'} deep = PD.deepen(flat) Assert(deep) == {'a': None, 'c': (None, 'Lorem', 78), 'b': 'kuku'} pd = PD(deep) Assert(pd.data) == {'a': None, 'c': (None, 'Lorem', 78), 'b': 'kuku'}