def test_get_id(self): vc = ValueCache() vc['bibo1'] = object() vc['bibo2'] = object() vc['bibo3'] = object() self.assertEqual(vc.get_id('bibo1'), 1) self.assertEqual(vc.get_id('bibo2'), 2) self.assertEqual(vc.get_id('bibo3'), 3) vc['bibo1'] = object() vc['bibo2'] = object() vc['bibo3'] = object() self.assertEqual(vc.get_id('bibo1'), 1) self.assertEqual(vc.get_id('bibo2'), 2) self.assertEqual(vc.get_id('bibo3'), 3) vc.clear() self.assertEqual(vc.get_id('bibo1'), None) self.assertEqual(vc.get_id('bibo2'), None) self.assertEqual(vc.get_id('bibo3'), None) vc['bibo1'] = object() vc['bibo2'] = object() vc['bibo3'] = object() self.assertEqual(vc.get_id('bibo1'), 4) self.assertEqual(vc.get_id('bibo2'), 5) self.assertEqual(vc.get_id('bibo3'), 6)
def test_rename_key(self): bibo = object() vc = ValueCache() vc['bibo'] = bibo bibo_id = vc.get_id('bibo') bibo_child = vc.child('bibo') vc.rename_key('bibo', 'bert') self.assertNotIn('bibo', vc) self.assertNotIn('bibo._child', vc) self.assertIn('bert', vc) self.assertIs(vc['bert'], bibo) self.assertIn('bert._child', vc) self.assertIs(vc['bert._child'], bibo_child) self.assertEqual(vc.get_id('bert'), bibo_id)