def test_not_nested_dict_converted(self): info = ons.Struct(nested=False) nuts = {'a': [1, 2], 'X': 'hello'} info.AA = nuts self.assertTrue(type(info.AA) == dict)
def test_attributes_keys(self): info = ons.Struct() item = [1, 2, 3] info['AA'] = item self.assertTrue(item == info.AA)
def test_order(self): keys = ['Z', 'z', 'a', 'B00', 'B1', 'B0'] values = list(range(len(keys))) info_1 = ons.Struct() info_2 = ons.Struct() for k, v in zip(keys, values): info_1[k] = v for k, v in zip(keys[::-1], values[::-1]): info_2[k] = v keys_test_1 = list(info_1.keys()) keys_test_2 = list(info_2.keys()) self.assertTrue(keys_test_1 == keys_test_2[::-1])
def test_special_keys(self): info = ons.Struct() item = [1, 2, 3] def fn(): info['_odict'] = item self.assertRaises(KeyError, fn)
def test_pickle_unpickle_keys(self): info = ons.Struct() info.A = [1, 2, 3, 4, 'WW'] z = pickle.dumps(info) anfo = pickle.loads(z) for k, v in info.items(): self.assertTrue(k in anfo)
def test_nested_dict_define(self): nuts = {'a': [1, 2], 'X': 'hello'} corn = {'b': [6, 9], 'Y': 'bye', 'm': nuts} yikes = {'c': [6, 9], 'Z': 'hello', 'n': corn} info = ons.Struct(yikes, nested=True) self.assertTrue(type(info.n) == ons.Struct) self.assertTrue(type(info.n.m) == ons.Struct)
def test_pickle_unpickle_value(self): info = ons.Struct() info.A = [1, 2, 3, 4, 'WW'] info.SS = 4 info.WWW = {'d': [1, 2, 3]} z = pickle.dumps(info) anfo = pickle.loads(z) for k, v in info.items(): self.assertTrue(v == anfo[k])
def test_nested_dict_list(self): nuts = {'a': [1, 2], 'X': 'hello'} corn = {'b': [6, 9], 'Y': 'bye'} yikes = {'c': [6, 9], 'Z': 'hello'} stuff = [nuts, corn, yikes] info = ons.Struct(nested=True) info.S = stuff self.assertTrue(type(info.S[0]) == ons.Struct)
def test_nested_dict_converted(self): info = ons.Struct(nested=True) nuts = {'a': [1, 2], 'X': 'hello'} corn = {'b': [6, 9], 'Y': 'bye'} info.AA = nuts self.assertTrue(type(info.AA) == ons.Struct) info.AA.BB = corn self.assertTrue(type(info.AA.BB) == ons.Struct)
def test_as_dict(self): info = ons.Struct(nested=True) nuts = {'a': [1, 2], 'X': 'hello'} corn = {'b': [6, 9], 'Y': 'bye'} info.AA = nuts info.AA.BB = corn info = info.asdict() self.assertTrue(type(info) == OrderedDict) self.assertTrue(type(info['AA']) == OrderedDict) self.assertTrue(type(info['AA']['BB']) == OrderedDict)
def test_does_it_run(self): info = ons.Struct()
def test_does_it_unpickle(self): info = ons.Struct() info.A = [1, 2, 3, 4, 'WW'] z = pickle.dumps(info) anfo = pickle.loads(z)
def test_does_it_pickle(self): info = ons.Struct() info.A = [1, 2, 3, 4, 'A'] z = pickle.dumps(info)
def test_nested_flag_default_not_set(self): info = ons.Struct() self.assertFalse(info.__dict__['_nested'])
def test_nested_flag_set(self): info = ons.Struct(nested=True) self.assertTrue(info.__dict__['_nested'])