def testDeleteChild(self):
        '''Delete child in python should not invalidate child'''
        parent = ObjectType()
        child = ObjectType(parent)
        name = ''.join(random.sample(string.letters, 5))
        child.setObjectName(name)

        del child
        new_child = parent.children()[0]
        self.assertEqual(new_child.objectName(), name)
    def testDeleteChild(self):
        '''Delete child in python should not invalidate child'''
        parent = ObjectType()
        child = ObjectType(parent)
        name = ''.join(random.sample(string.letters, 5))
        child.setObjectName(name)

        del child
        new_child = parent.children()[0]
        self.assertEqual(new_child.objectName(), name)
 def testReparentedObjectTypeIdentityWithChildrenCreatedInCpp(self):
     '''Reparent children created in C++ from one parent to another.'''
     object_list = []
     old_parent = ObjectType()
     new_parent = ObjectType()
     for i in range(3):
         obj = ObjectType.create()
         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)
 def testReparentedObjectTypeIdentityWithChildrenCreatedInCpp(self):
     '''Reparent children created in C++ from one parent to another.'''
     object_list = []
     old_parent = ObjectType()
     new_parent = ObjectType()
     for i in range(3):
         obj = ObjectType.create()
         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 testInvalidateChild(self):
        '''Invalidating method call should remove child from the care of a parent if it has one.'''
        parent = ObjectType()
        child1 = ObjectType(parent)
        child1.setObjectName('child1')
        child2 = ObjectType.create()
        child2.setParent(parent)
        child2.setObjectName('child2')

        self.assertEqual(parent.children(), [child1, child2])

        bbox = BlackBox()

        # This method steals ownership from Python to C++.
        bbox.keepObjectType(child1)
        self.assertEqual(parent.children(), [child2])

        bbox.keepObjectType(child2)
        self.assertEqual(parent.children(), [])

        del parent

        self.assertEqual(child1.objectName(), 'child1')
        self.assertRaises(RuntimeError, child2.objectName)
    def testInvalidateChild(self):
        '''Invalidating method call should remove child from the care of a parent if it has one.'''
        parent = ObjectType()
        child1 = ObjectType(parent)
        child1.setObjectName('child1')
        child2 = ObjectType.create()
        child2.setParent(parent)
        child2.setObjectName('child2')

        self.assertEqual(parent.children(), [child1, child2])

        bbox = BlackBox()

        # This method steals ownership from Python to C++.
        bbox.keepObjectType(child1)
        self.assertEqual(parent.children(), [child2])

        bbox.keepObjectType(child2)
        self.assertEqual(parent.children(), [])

        del parent

        self.assertEqual(child1.objectName(), 'child1')
        self.assertRaises(RuntimeError, child2.objectName)