def testReparentWithTheSameParent(self): '''Set the same parent twice to check if the ref continue the same''' obj = ObjectType() parent = ObjectType() self.assertEqual(sys.getrefcount(obj), 2) obj.setParent(parent) self.assertEqual(sys.getrefcount(obj), 3) obj.setParent(parent) self.assertEqual(sys.getrefcount(obj), 3)
def testParentDestructor(self): '''Delete parent object should invalidate child''' parent = ObjectType() child = ObjectType() child.setParent(parent) refcount_before = sys.getrefcount(child) del parent self.assertRaises(RuntimeError, child.objectName) self.assertEqual(sys.getrefcount(child), refcount_before-1)
def testReparentedObjectTypeIdentityWithParentsCreatedInCpp(self): '''Reparent children from one parent to another, both created in C++.''' object_list = [] old_parent = ObjectType.create() new_parent = ObjectType.create() for i in range(3): obj = ObjectType() object_list.append(obj) obj.setParent(old_parent) for obj in object_list: obj.setParent(new_parent) for child in new_parent.children(): self.assert_(child in object_list)
def testReparentedObjectTypeIdentity(self): '''Reparent children from one parent to another.''' object_list = [] old_parent = ObjectType() new_parent = ObjectType() for i in range(3): obj = ObjectType() object_list.append(obj) obj.setParent(old_parent) for obj in object_list: obj.setParent(new_parent) for child in new_parent.children(): self.assertTrue(child in object_list)