Exemple #1
0
 def nodeLinkage(self):
     with Tree('pytree',self.shot+6,'new') as pytree:
         pytree.default.addNode('pytreesub','subtree').include_in_pulse=True
         for i in range(10):
             node=pytree.addNode('val%02d' % (i,),'numeric')
             node.record=i
             node=pytree.top.addNode('sig%02d' % (i,),'signal')
             node.record=Signal(i,None,i)
             node=pytree.top.addNode('child%02d' % (i,),'structure')
             node.addNode('text','text')
             node.addNode('child','structure')
         pytree.write()
     with Tree('pytreesub',self.shot+6,'new') as pytreesub:
         ip=pytreesub.addNode('ip','signal')
         ip.tag='IP'
         for i in range(3):
             node=pytreesub.top.addNode('child%02d' % (i,),'structure')
             node.addDevice('dt200_%02d' % (i,),'dt200').on=False
         pytreesub.write()
     from numpy import array,int32
     pytree.readonly()
     top=TreeNode(0,pytree)
     members=pytree.getNodeWild(':*')
     self.assertEqual((members==top.member_nids).all(),True)
     self.assertEqual((members==top.getMembers()).all(),True)
     self.assertEqual(top.member.nid_number,members[0].nid_number)
     member=top.member
     for idx in range(1,len(members)):
         self.assertEqual(member.brother.nid_number,members[idx].nid_number)
         member=member.brother
     children=pytree.getNodeWild('.*')
     self.assertEqual((children==top.children_nids).all(),True)
     self.assertEqual((children==top.getChildren()).all(),True)
     self.assertEqual(top.child.nid_number,children[0].nid_number)
     child=top.child
     for idx in range(1,len(children)):
         self.assertEqual(child.brother.nid_number,children[idx].nid_number)
         child=child.brother
     self.assertEqual(top.child.nid_number,pytree.getNode(str(top.child)).nid_number)
     self.assertEqual(top.child.child.parent.nid_number,top.child.nid_number)
     x=array(int32(0)).repeat(len(members)+len(children))
     x[0:len(children)]=children.nid_number.data()
     x[len(children):]=members.nid_number.data()
     self.assertEqual((Array(x)==top.descendants.nid_number).all(),True)
     self.assertEqual((top.descendants.nid_number==top.getDescendants().nid_number).all(),True)
     self.assertEqual(top.child.child.depth,3)
     self.assertEqual(top.getNumDescendants(),len(x))
     self.assertEqual(top.getNumMembers(),len(members))
     self.assertEqual(top.getNumChildren(),len(children))
     self.assertEqual(top.number_of_members,len(members))
     self.assertEqual(top.number_of_children,len(children))
     self.assertEqual(top.number_of_descendants,len(x))
     devs=pytree.getNodeWild('\\PYTREESUB::TOP.***','DEVICE')
     dev=devs[0].conglomerate_nids
     self.assertEqual((dev.nid_number==devs[0].getConglomerateNodes().nid_number).all(),True)
     self.assertEqual((dev.conglomerate_elt==Array(array(range(len(dev)))+1)).all(),True)
     for idx in range(len(dev)):
         self.assertEqual(dev[idx].conglomerate_elt,idx+1)
         self.assertEqual(dev[idx].getConglomerateElt(),idx+1)
     self.assertEqual(top.child.is_child,True)
     self.assertEqual(top.child.is_member,False)
     self.assertEqual(top.member.is_child,False)
     self.assertEqual(top.member.is_member,True)
     self.assertEqual(top.child.is_child,top.child.isChild())
     self.assertEqual(top.child.is_member,top.child.isMember())
     ip=pytree.getNode('\\ip')
     pytree.setDefault(ip)
     self.assertEqual(ip.fullpath,"\\PYTREE::TOP.PYTREESUB:IP")
     self.assertEqual(ip.fullpath,ip.getFullPath())
     self.assertEqual(ip.minpath,"\\IP")
     self.assertEqual(ip.minpath,ip.getMinPath())
     self.assertEqual(ip.node_name,'IP')
     self.assertEqual(ip.node_name,ip.getNodeName())
     self.assertEqual(ip.path,"\\PYTREESUB::IP")
     self.assertEqual(ip.path,ip.getPath())
Exemple #2
0
 def test():
     from numpy import array, int32
     pytree = Tree('pytree', self.shot, 'ReadOnly')
     top = TreeNode(0, pytree)
     members = pytree.getNodeWild(':*')
     self.assertEqual((members == top.member_nids).all(), True)
     self.assertEqual((members == top.getMembers()).all(), True)
     self.assertEqual(top.member.nid_number, members[0].nid_number)
     member = top.member
     for idx in range(1, len(members)):
         self.assertEqual(member.brother.nid_number,
                          members[idx].nid_number)
         member = member.brother
     children = pytree.getNodeWild('.*')
     self.assertEqual((children == top.children_nids).all(), True)
     self.assertEqual((children == top.getChildren()).all(), True)
     self.assertEqual(top.child.nid_number, children[0].nid_number)
     child = top.child
     for idx in range(1, len(children)):
         self.assertEqual(child.brother.nid_number,
                          children[idx].nid_number)
         child = child.brother
     self.assertEqual(top.child.nid_number,
                      pytree.getNode(str(top.child)).nid_number)
     self.assertEqual(top.child.child.parent.nid_number,
                      top.child.nid_number)
     x = array(int32(0)).repeat(len(members) + len(children))
     x[0:len(children)] = children.nid_number.data()
     x[len(children):] = members.nid_number.data()
     self.assertEqual(
         (makeArray(x) == top.descendants.nid_number).all(), True)
     self.assertEqual(
         (top.descendants.nid_number == top.getDescendants().nid_number
          ).all(), True)
     self.assertEqual(top.child.child.depth, 3)
     self.assertEqual(top.getNumDescendants(), len(x))
     self.assertEqual(top.getNumMembers(), len(members))
     self.assertEqual(top.getNumChildren(), len(children))
     self.assertEqual(top.number_of_members, len(members))
     self.assertEqual(top.number_of_children, len(children))
     self.assertEqual(top.number_of_descendants, len(x))
     devs = pytree.getNodeWild('\\PYTREESUB::TOP.***', 'DEVICE')
     dev = devs[0].conglomerate_nids
     self.assertEqual(
         (dev.nid_number == devs[0].getConglomerateNodes().nid_number
          ).all(), True)
     self.assertEqual(
         (dev.conglomerate_elt == makeArray(array(range(len(dev))) +
                                            1)).all(), True)
     for idx in range(len(dev)):
         self.assertEqual(dev[idx].conglomerate_elt, idx + 1)
         self.assertEqual(dev[idx].getConglomerateElt(), idx + 1)
     self.assertEqual(top.child.is_child, True)
     self.assertEqual(top.child.is_member, False)
     self.assertEqual(top.member.is_child, False)
     self.assertEqual(top.member.is_member, True)
     self.assertEqual(top.child.is_child, top.child.isChild())
     self.assertEqual(top.child.is_member, top.child.isMember())
     ip = pytree.getNode('\\ip')
     pytree.setDefault(ip)
     self.assertEqual(ip.fullpath, "\\PYTREE::TOP.PYTREESUB:IP")
     self.assertEqual(ip.fullpath, ip.getFullPath())
     self.assertEqual(ip.minpath, "\\IP")
     self.assertEqual(ip.minpath, ip.getMinPath())
     self.assertEqual(ip.node_name, 'IP')
     self.assertEqual(ip.node_name, ip.getNodeName())
     self.assertEqual(ip.path, "\\PYTREESUB::IP")
     self.assertEqual(ip.path, ip.getPath())