Exemple #1
0
 def writeXML(self, writeTo, targets=None, skip=None):
     """
   Write out ARMA information
   @ In, writeTo, xmlUtils.StaticXmlElement, entity to write to
   @ In, targets, list, optional, unused
   @ In, skip, list, optional, unused
   @ Out, None
 """
     # do everything that Segments do
     Segments.writeXML(self, writeTo, targets, skip)
     # add some stuff specific to clustering
     main = writeTo.getRoot()
     labels = self._clusterInfo['labels']
     for i, repRom in enumerate(self._roms):
         # find associated node
         modify = xmlUtils.findPath(main,
                                    'SegmentROM[@segment={}]'.format(i))
         # make changes to reflect being a cluster
         modify.tag = 'ClusterROM'
         modify.attrib['cluster'] = modify.attrib.pop('segment')
         modify.append(
             xmlUtils.newNode(
                 'segments_represented',
                 text=', '.join(
                     str(x) for x in np.arange(len(labels))[labels == i])))
Exemple #2
0
 def _findTarg(self,root,target):
   """
     Searches "root" for "target" node and makes it if not found
     @ In, root, xml.etree.ElementTree.Element, node to search under
     @ In, target, string, name of target to find
     @ Out, targ, xml.etree.ElementTree.Element, desired target node
   """
   #find target node
   targ = xmlUtils.findPath(root,target)
   #if it doesn't exist, make it and add it
   if targ is None:
     targ = xmlUtils.newNode(target)
     root.append(targ)
   return targ
Exemple #3
0
 def _readPath(self,root,inpPath,fileName):
   """
     Reads in values from XML tree.
     @ In, root, xml.etree.ElementTree.Element, node to start from
     @ In, inPath, string, |-separated list defining path from root (not including root)
     @ In, fileName, string, used in error
     @ Out, desiredNode, xml.etree.ElementTree.Element, desired node
   """
   #improve path format
   path = '|'.join(c.strip() for c in inpPath.strip().split('|'))
   desiredNode = xmlUtils.findPath(root,path)
   if desiredNode is None:
     self.raiseAnError(RuntimeError,'Did not find "%s|%s" in file "%s"' %(root.tag,path,fileName))
   return desiredNode
Exemple #4
0
#          Static XML                #
######################################
# create it
static = Files.StaticXMLOutput()
static.messageHandler = mh
# start a new tree
static.newTree('TestRoot')
# test instance
checkTrue('Static root node type', isinstance(static.tree, ET.ElementTree))
# test tag
checkSame('Static root node name', static.tree.getroot().tag, 'TestRoot')
# add some scalars
static.addScalar('FirstTarget', 'pi', 3.14159)
static.addScalar('FirstTarget', 'e', 6.18)
# check values
pi = xmlUtils.findPath(static.tree.getroot(), 'FirstTarget/pi')
e = xmlUtils.findPath(static.tree.getroot(), 'FirstTarget/e')
checkFloat('Static pi', float(pi.text), 3.14159)
checkFloat('Static e', float(e.text), 6.18)
# add a vector
static.addVector('SecondTarget', 'pi', {'e': 0, 'pi': 1})
static.addVector('SecondTarget', 'e', {'e': 1, 'pi': 0})
# check values
checkFloat(
    'Static pi wrt pi',
    float(xmlUtils.findPath(static.tree.getroot(), 'SecondTarget/pi/pi').text),
    1.0)
checkFloat(
    'Static pi wrt e',
    float(xmlUtils.findPath(static.tree.getroot(), 'SecondTarget/pi/e').text),
    0.0)
Exemple #5
0
inps.append('root/child[0]')
outs.append(xmlUtils.fixTagsInXpath(inps[4]))
exps.append('root/child[0]')  # no change

for i in range(5):
    if outs[i] == exps[i]:
        results['pass'] += 1
    else:
        results['fail'] += 1
        print('ERROR: fixTagsInXpath #{}: expected "{}" but got "{}"'.format(
            i, exps[i], outs[i]))

# test findPath
###test successful find
found = xmlUtils.findPath(xmlTree.getroot(), 'child/cchild')
okay = True
#  type
if type(found) != elemType:
    okay = False
    print(
        'ERROR: Test of "findPath" failed!  Returned node was not an xml.etree.ElementTree!  Instead was:',
        type(found))
elif found.tag != 'cchild':
    okay = False
    print(
        'ERROR: Test of "findPath" failed!  Returned node tag was not "cchild"!  Instead was:',
        found.tag)
if okay:
    results['pass'] += 1
else: