def testRefEquality(self): v = Storage({}) ra1 = v.getRef('a') ra2 = v.getRef('a') rb = v.getRef('b') self.assertEqual(ra1, ra2) self.assertNotEqual(ra1, rb)
def testData(self): store = Storage({}) store['people/data/tom'] = Data({}) t_data = store['people/data/tom'] t_data['name'] = 'Tom' t_data['age'] = 14 self.assertEqual(t_data['name'], 'Tom') env = Ref(store, 'people/data/tom') store['people/obj/tom'] = Person(env) tom = store['people/obj/tom'] self.assertEqual(tom.description(), 'Tom age 14') tom.haveBirthday() self.assertEqual(t_data['age'], 15) store['people/data/gary'] = Data({}) g_data = store['people/data/gary'] g_data['name'] = 'Gary' g_data['age'] = 48 t_data['dad'] = g_data self.assertEqual(type(t_data['dad']), Ref) self.assertEqual(tom.dadsName(), 'Gary') with Capture() as c: fcat(tom) self.assertEqual(c.getvalue(), "Person(env=ref(path='people/data/tom'))\n") # We can store refs anywhere in data. A top-level Data object # which has come from the store can turn itself into a ref. g_data['kids'] = [t_data] self.assertEqual(type(g_data['kids'][0]), Ref) self.assertEqual(g_data['kids'][0]['name'], 'Tom') # We do not support deep references into data (e.g. g_data['kids']) # because they would be very breakable, and copying would upset # the normal language expectation of node sharing. self.assertRaises(ValueError, t_data.__setitem__, 'siblings', g_data['kids']) store['caps/time'] = Time() t_data['time'] = store.getRef('caps/time') self.assertEqual(type(store['caps/time']), Time) self.assertEqual(type(t_data['time']), Ref) self.assertEqual(tom.whatTime(), 'Tea-time') t_data.save() g_data.save() del t_data, g_data, tom self.assertEqual(store.cache.values(), []) t_data = store['people/data/tom'] g_data = store['people/data/gary'] tom = store['people/obj/tom'] self.assertEqual(t_data['name'], 'Tom') self.assertEqual(t_data['age'], 15) self.assertEqual(type(t_data['time']), Ref) self.assertEqual(t_data['time'].time(), 'Tea-time') tom.haveBirthday() self.assertEqual(g_data['kids'][0]['age'], 16)
def testData(self): store = Storage({}) store['people/data/tom'] = Data({}) t_data = store['people/data/tom'] t_data['name'] = 'Tom' t_data['age'] = 14 self.assertEqual(t_data['name'], 'Tom') env = Ref(store, 'people/data/tom') store['people/obj/tom'] = Person(env) tom = store['people/obj/tom'] self.assertEqual(tom.description(), 'Tom age 14') tom.haveBirthday() self.assertEqual(t_data['age'], 15) store['people/data/gary'] = Data({}) g_data = store['people/data/gary'] g_data['name'] = 'Gary' g_data['age'] = 48 t_data['dad'] = g_data self.assertEqual(type(t_data['dad']), Ref) self.assertEqual(tom.dadsName(), 'Gary') with Capture() as c: fcat(tom) self.assertEqual(c.getvalue(), "Person(env=ref(path='people/data/tom'))\n") # We can store refs anywhere in data. A top-level Data object # which has come from the store can turn itself into a ref. g_data['kids'] = [t_data] self.assertEqual(type(g_data['kids'][0]), Ref) self.assertEqual(g_data['kids'][0]['name'], 'Tom') # We do not support deep references into data (e.g. g_data['kids']) # because they would be very breakable, and copying would upset # the normal language expectation of node sharing. self.assertRaises( ValueError, t_data.__setitem__, 'siblings', g_data['kids']) store['caps/time'] = Time() t_data['time'] = store.getRef('caps/time') self.assertEqual(type(store['caps/time']), Time) self.assertEqual(type(t_data['time']), Ref) self.assertEqual(tom.whatTime(), 'Tea-time') t_data.save() g_data.save() del t_data, g_data, tom self.assertEqual(store.cache.values(), []) t_data = store['people/data/tom'] g_data = store['people/data/gary'] tom = store['people/obj/tom'] self.assertEqual(t_data['name'], 'Tom') self.assertEqual(t_data['age'], 15) self.assertEqual(type(t_data['time']), Ref) self.assertEqual(t_data['time'].time(), 'Tea-time') tom.haveBirthday() self.assertEqual(g_data['kids'][0]['age'], 16)