def test_iterMetaChildrenLargeNetwork(self): # large network children = [] parentMeta = base.MetaBase(nodes.createDGNode("parentMeta", "network")) # to test connecting multiple nodes to a single parent for i in range(100): child = base.MetaBase( nodes.createDGNode("child{}".format(i), "network")) parentMeta.addChild(child) children.append(child) self.assertTrue(len(parentMeta.metaChildren()), len(children)) parent = parentMeta for child in children: child.removeParent() child.addParent(parent) parent = child self.assertEquals( len([i for i in parentMeta.iterMetaChildren(depthLimit=1)]), 1) # we hit a depth limit self.assertEquals( len([i for i in parentMeta.iterMetaChildren(depthLimit=100)]), 100) self.assertEquals( len([ i for i in parentMeta.iterMetaChildren(depthLimit=len(children) + 1) ]), len(children))
def test_addChild(self): newNode = nodes.createDagNode("test", "transform") newParent = base.MetaBase(newNode) self.meta.addChild(newParent) self.assertEquals(len(self.meta.metaChildren()), 1) self.assertEquals(self.meta.metaChildren()[0].mobject(), newParent.mobject())
def test_iterMetaChildren(self): childOne = base.MetaBase(nodes.createDagNode("child", "transform")) childTwo = base.MetaBase(nodes.createDagNode("child1", "transform")) childThree = base.MetaBase(nodes.createDagNode("child2", "transform")) self.meta.addChild(childOne) childOne.addChild(childTwo) childTwo.addChild(childThree) iterchildren = [i for i in self.meta.iterMetaChildren()] nonChildren = [i for i in self.meta.iterMetaChildren(depthLimit=1)] self.assertEquals(len(nonChildren), 1) self.assertEquals(len(iterchildren), 3) selection = [childOne, childTwo, childThree] # non recursive self.assertTrue(nonChildren[0] in nonChildren) for i in selection: self.assertTrue(i in iterchildren) selection.remove(i)
def test_setattr(self): self.meta.uuid = "testClass" self.assertEquals(self.meta.uuid.asString(), "testClass") with self.assertRaises(TypeError): self.meta.uuid = 10 child = base.MetaBase() self.meta.metaParent = child self.assertIsNotNone(child.metaParent()) self.assertIsNotNone(self.meta.metaChildren())
def test_removeParent(self): newNode = nodes.createDagNode("test", "transform") newParent = base.MetaBase(newNode) self.meta.addParent(newParent) self.assertEquals(len(list(newParent.iterMetaChildren())), 1) self.meta.removeParent(newParent) self.assertEquals(len(list(newParent.iterMetaChildren())), 0) self.meta.addParent(newParent) self.assertEquals(len(list(newParent.iterMetaChildren())), 1) self.meta.removeParent(newParent) self.assertEquals(len(list(newParent.iterMetaChildren())), 0)
def test_setattr(self): self.meta.addAttribute("testAttr", "", attrtypes.kMFnDataString) self.assertEquals(self.meta.testAttr.asString(), "") self.meta.testAttr = "testClass" self.assertEquals(self.meta.testAttr.asString(), "testClass") with self.assertRaises(TypeError): self.meta.testAttr = 10 child = base.MetaBase() child.addParent(self.meta) self.assertIsInstance(list(child.metaParents())[0], base.MetaBase) self.assertIsInstance(list(self.meta.iterMetaChildren())[0], base.MetaBase)
def test_removeChild(self): newNode = nodes.createDagNode("test", "transform") newParent = base.MetaBase(newNode) self.meta.addParent(newParent) self.assertEquals(len(newParent.metaChildren()), 1) newParent.removeChild(self.meta) self.assertEquals(len(newParent.metaChildren()), 0) self.meta.addParent(newParent) self.assertEquals(len(newParent.metaChildren()), 1) newParent.removeChild(self.meta.mobject()) self.assertEquals(len(newParent.metaChildren()), 0)
def setUp(self): self.meta = base.MetaBase(name="testNode", lock=True)
def test_addParent(self): newNode = nodes.createDagNode("test", "transform") newParent = base.MetaBase(newNode) self.meta.addParent(newParent) self.assertEquals(list(self.meta.metaParents())[0].mobject(), newParent.mobject())
def test_name(self): self.assertEquals(self.meta.fullPathName(), "testNode_meta") self.assertEquals(base.MetaBase(nodes.createDagNode("transform1", "transform")).fullPathName(), "|transform1")