def test_flyweight(self): instance = sdn.Instance() href1 = HRef.from_parent_and_item(None, instance) href2 = HRef.from_parent_and_item(None, instance) self.assertTrue(href1 is href2) import weakref w_href1 = weakref.ref(href1) w_href2 = weakref.ref(href2) href1 = None href2 = None import gc gc.collect() self.assertIsNone(w_href1()) self.assertIsNone(w_href2()) instance2 = sdn.Instance() href1 = HRef.from_sequence([instance, instance2]) href2_parent = HRef(instance, None) href2 = HRef.from_parent_and_item(href2_parent, instance2) self.assertTrue(href1 is href2)
def test_hRef_shortcut(self): item = Instance("myCable") def2 = Definition("Hello") item.reference = def2 hr = HRef(item) self.assertEqual(hr.item.name, item.name, 'Href item shorcut error')