def test_remove_parent(self): root = ma.Node('root') child1 = ma.Node('child1', root) child1.removeParent(root) self.assertEqual(child1.refcount(), 1) self.assertEqual(root.hasChildren(), False) self.assertEqual(child1.hasParents(), False)
def test_ctor_with_parent(self): root = ma.Node('root') child = ma.Node('child', root) self.assertEqual(root.hasChildren(), True) self.assertEqual(child.hasParents(), True) self.assertEqual(root.name(), 'root') self.assertEqual(child.name(), 'child') del root self.assertEqual(child.hasParents(), False)
def test_several_children(self): root = ma.Node('root') child1 = ma.Node('child1', root) child2 = ma.Node('child2', root) self.assertEqual(root.refcount(), 1) self.assertEqual(child1.refcount(), 2) self.assertEqual(child2.refcount(), 2) del root self.assertEqual(child1.refcount(), 1) self.assertEqual(child2.refcount(), 1)
def test_add_parent(self): root = ma.Node('root') child1 = ma.Node('child1') child1.addParent(root) self.assertEqual(child1.refcount(), 2) self.assertEqual(root.hasChildren(), True) self.assertEqual(child1.hasParents(), True) self.assertEqual(root.child(0).name(), 'child1') del root self.assertEqual(child1.refcount(), 1)
def test_clear_node(self): root = ma.Node('root') child1 = ma.Node('child1', root) child2 = ma.Node('child2', root) self.assertEqual(root.refcount(), 1) self.assertEqual(child1.refcount(), 2) self.assertEqual(child2.refcount(), 2) root.clear() self.assertEqual(root.refcount(), 1) self.assertEqual(child1.refcount(), 1) self.assertEqual(child2.refcount(), 1)
def test_find_children(self): root = ma.Node('root') node = ma.Node('node', root) node.setProperty('foo', 'bar') node.setProperty('hello', True) children = root.findChildren(ma.T_Node, '.*', [['name', 'node']]) self.assertEqual(len(children), 1) self.assertEqual(children[0].name(), 'node') children = root.findChildren(ma.T_Node, '.*', [['foo', 'bar']]) self.assertEqual(len(children), 1) self.assertEqual(children[0].name(), 'node') children = root.findChildren(ma.T_Node, '.*', [['hello', True]]) self.assertEqual(len(children), 1) self.assertEqual(children[0].name(), 'node')
def test_clone_node(self): root = ma.Node('root') ma.Node('child1', root) other = root.clone() other.setName('Foo') other.child(0).setName('Bar') self.assertEqual(root.hasChildren(), True) self.assertEqual(other.hasChildren(), True) self.assertEqual(root.refcount(), 1) self.assertEqual(other.refcount(), 1) self.assertEqual(root.name(), 'root') self.assertEqual(other.name(), 'Foo') self.assertEqual(root.child(0).name(), 'child1') self.assertEqual(other.child(0).name(), 'Bar')
def test_find_Children(self): root = ma.Node('Root') evt01 = ma.Event('Foot Strike', 0., 'Right', 'Anonymous', root) evt02 = ma.Event('Foot Strike', 1.05, 'Right', 'Anonymous', root) evt03 = ma.Event('Foot Strike', 2.11, 'Right', 'Anonymous', root) evt04 = ma.Event('Foot Strike', 0.5, 'Left', 'Anonymous', root) evt05 = ma.Event('Foot Strike', 1.60, 'Left', 'Anonymous', root) evt06 = ma.Event('Foot Strike', 2.73, 'Left', 'Anonymous', root) evt07 = ma.Event('Foot Off', 0.84, 'Right', 'Anonymous', root) evt08 = ma.Event('Foot Off', 1.90, 'Right', 'Anonymous', root) evt09 = ma.Event('Foot Off', 2.85, 'Right', 'Anonymous', root) evt10 = ma.Event('Foot Off', 0.75, 'Left', 'Anonymous', root) evt11 = ma.Event('Foot Off', 2.10, 'Left', 'Anonymous', root) evt12 = ma.Event('Foot Off', 3.09, 'Left', 'Anonymous', root) evts = root.findChildren(ma.T_Event, 'Foot Strike') self.assertEqual(len(evts), 6) evts = root.findChildren(ma.T_Event, 'Foot Strike', [['context', 'Right']]) self.assertEqual(len(evts), 3) evts = root.findChildren(ma.T_Event, '.*', [['context', 'Right']]) self.assertEqual(len(evts), 6) evts = root.findChildren(ma.T_Event, 'Foot Off') self.assertEqual(len(evts), 6) evts = root.findChildren(ma.T_Event, 'Foot Off', [['context', 'Left']]) self.assertEqual(len(evts), 3) evts = root.findChildren(ma.T_Event, '.*', [['context', 'Left']]) self.assertEqual(len(evts), 6)
def test_set_property(self): root = ma.Node('root') self.assertEqual(root.property('name').cast('string'), 'root') root.setProperty('foo', 1) self.assertEqual(root.property('foo').cast('int'), 1) root.setProperty('bar', ma.Any(10.0)) self.assertEqual(root.property('bar').cast('float'), 10.0)
def test_copy_variable_in_cell(self): nodes = [] for i in range(0, 3): node = ma.Node('Node' + str(i + 1)) nodes.append(node) self.assertEqual(nodes[0].name(), 'Node1') self.assertEqual(nodes[1].name(), 'Node2') self.assertEqual(nodes[2].name(), 'Node3')
def test_copy_node(self): root = ma.Node('root') child1 = ma.Node('child1', root) child2 = ma.Node('child2', child1) other = ma.Node('other') sub1 = ma.Node('sub1', other) other.copy(root) self.assertEqual(sub1.hasParents(), False) self.assertEqual(root.refcount(), 1) self.assertEqual(child1.refcount(), 2) self.assertEqual(child2.refcount(), 2) self.assertEqual(other.refcount(), 1) self.assertEqual(sub1.refcount(), 1) other.child(0).setName('Goal') other.child(0).child(0).setName('Goal2') self.assertEqual(child1.name(), 'child1') self.assertEqual(child2.name(), 'child2')
def test_children(self): root = ma.Node('root') child1 = ma.Node('child1', root) child2 = ma.Node('child2', root) children = root.children() self.assertEqual(len(children), 2) self.assertEqual(children[0].name(), child1.name()) self.assertEqual(children[1].name(), child2.name()) del root self.assertEqual(children[0].hasParents(), False) self.assertEqual(children[1].hasParents(), False) del child1 del child2 # Still exist? self.assertEqual(children[0].name(), 'child1') self.assertEqual(children[1].name(), 'child2') self.assertEqual(children[0].refcount(), 1) self.assertEqual(children[1].refcount(), 1)
def test_find_child(self): root = ma.Node('root') node = ma.Node('node', root) node.setProperty('foo', 'bar') node.setProperty('hello', True) child = root.findChild(ma.T_Node, 'node') self.assertEqual(child == None, False) self.assertEqual(child.name(), 'node') child = root.findChild(ma.T_Node, 'anything') self.assertEqual(child == None, True) child = root.findChild(ma.T_Node, 'node', [['foo', 'bar']]) self.assertEqual(child == None, False) self.assertEqual(child.name(), 'node') child = root.findChild(ma.T_Node, 'node', [['hello', False]]) self.assertEqual(child == None, True) child = root.findChild(ma.T_Node, '', [['foo', 'bar']]) self.assertEqual(child == None, False) self.assertEqual(child.name(), 'node')
def test_node_cast(self): root = ma.Node('Root') evt01 = ma.Event('Foot Strike', 0., 'Right', 'Anonymous', root) evt01_ = ma.node_cast(ma.T_Event, root.child(0)) self.assertEqual(root.hasChildren(), True) self.assertEqual(evt01.refcount(), 3) self.assertEqual(evt01_.refcount(), 3) self.assertEqual(evt01.hasParents(), True) self.assertEqual(evt01_.hasParents(), True) self.assertEqual(evt01.name(), evt01_.name()) del evt01 self.assertEqual(root.hasChildren(), True) self.assertEqual(evt01_.refcount(), 2) del root self.assertEqual(evt01_.hasParents(), False) self.assertEqual(evt01_.refcount(), 1)
def test_ctor(self): n = ma.Node('test') self.assertEqual(n.name(), 'test')
def test_child0(self): root = ma.Node('root') self.assertRaises(IndexError, root.child, 0)