示例#1
0
    def test_container(self):
        c = jwzthreading.Container()
        repr(c)

        c2 = jwzthreading.Container()
        self.assertTrue(c.is_dummy())
        self.assertEquals(c.children, [])
        self.assertEquals(c.parent, None)
        self.assertFalse(c.has_descendant(c2))

        # Add a child
        c3 = jwzthreading.Container()
        c.add_child(c2)
        c2.add_child(c3)
        self.assertEquals(c.children, [c2])
        self.assertEquals(c2.parent, c)
        self.assertTrue(c.has_descendant(c2))
        self.assertTrue(c.has_descendant(c3))
        self.assertTrue(c.has_descendant(c))

        # Remove a child
        c.remove_child(c2)
        self.assertEquals(c.children, [])
        self.assertEquals(c2.parent, None)
        self.assertFalse(c.has_descendant(c3))
        self.assertTrue(c2.has_descendant(c3))

        # Add child of one container to another
        c3 = jwzthreading.Container()
        c.add_child(c3)
        c2.add_child(c3)
        self.assertEquals(c3.parent, c2)
示例#2
0
    def test_deep_container(self):
        # Build a 50000-deep list of nested Containers.
        parent = jwzthreading.Container()
        L = [parent]
        for i in range(50000):
            child = jwzthreading.Container()
            parent.add_child(child)
            L.append(child)
            parent = child

        # Test finding the last child
        self.assertTrue(L[0].has_descendant(L[-1]))

        # Test a search that fails
        self.assertFalse(L[0].has_descendant(jwzthreading.Container()))
示例#3
0
 def test_prune_promote(self):
     p = jwzthreading.Container()
     c1 = jwzthreading.Container()
     c1.message = jwzthreading.Message()
     p.add_child(c1)
     self.assertEquals(jwzthreading.prune_container(p), [c1])
示例#4
0
 def test_prune_empty(self):
     c = jwzthreading.Container()
     self.assertEquals(jwzthreading.prune_container(c), [])