def test_flatten_function_TypeError(self): """flatten, check the try:except: at the top""" # interesting behavior on what is created self.assertEqual(dm.flatten(np.arange(5)), { 0: 0, 1: 1, 2: 2, 3: 3, 4: 4 })
def test_unflatten_function(self): """Unflatten should unflatten a flattened SpaceData""" a = dm.SpaceData() a['1'] = dm.SpaceData(dog = 5, pig = dm.SpaceData(fish=dm.SpaceData(a='carp', b='perch'))) a['4'] = dm.SpaceData(cat = 'kitty') a['5'] = 4 a[9] = dm.dmarray([1,2,3]) b = dm.flatten(a) c = dm.unflatten(b) self.assertTrue(9 in a.keys()) self.assertTrue(9 in c.keys()) del a[9] del c[9] self.assertEqual(sorted(a.keys()), sorted(c.keys())) self.assertEqual(sorted(a['1'].keys()), sorted(c['1'].keys())) self.assertEqual(sorted(a['1']['pig'].keys()), sorted(c['1']['pig'].keys())) self.assertEqual(sorted(a['1']['pig']['fish'].keys()), sorted(c['1']['pig']['fish'].keys()))
def test_flatten_function(self): """Flatten should flatten a nested SpaceData""" a = dm.SpaceData() a['1'] = dm.SpaceData(dog = 5, pig = dm.SpaceData(fish=dm.SpaceData(a='carp', b='perch'))) a['4'] = dm.SpaceData(cat = 'kitty') a['5'] = 4 self.assertEqual(a['1']['dog'], 5) b = dm.flatten(a) try: b['1']['dog'] except KeyError: pass else: self.fail('KeyError not raised') # might be possible that list order is not preserved and this fails, # if so change to a bunch of self.assertTrue and in statements self.assertEqual(sorted(b.keys()), sorted(['1<--pig<--fish<--a', '4<--cat', '1<--dog', '1<--pig<--fish<--b', '5']))