def readFromStgXML(self, inputFilesList, basePath): '''Read in the list of fields that have already been specified to be tested from a set of StGermain input files. Useful when e.g. working with an Analytic Solution plugin.''' self.fromXML = True # create a flattened file absInputFiles = stgpath.convertLocalXMLFilesToAbsPaths( inputFilesList, basePath) ffile = stgxml.createFlattenedXML(absInputFiles) xmlDoc = etree.parse(ffile) stgRoot = xmlDoc.getroot() # Go and grab necessary info from XML file componentEl = stgxml.getStructNode(stgRoot, self.stgXMLCompListName) fieldTestDataEl = stgxml.getStructNode(componentEl, self.stgXMLCompName) fieldTestListEl = stgxml.getListNode(fieldTestDataEl, self.stgXMLSpecFList) fieldTestStructEls = fieldTestListEl.getchildren() for fieldStruct in fieldTestStructEls: numericField = stgxml.getParamValue(fieldStruct, 'NumericField', str) self.fields[numericField] = FieldComparisonOp(numericField) # NB: not reading in all the other specifying stuff currently. Possibly # would be useful to do this in future. os.remove(ffile)
def readFromStgXML(self, inputFilesList, basePath): '''Read in the list of fields that have already been specified to be tested from a set of StGermain input files. Useful when e.g. working with an Analytic Solution plugin.''' self.fromXML = True # create a flattened file absInputFiles = stgpath.convertLocalXMLFilesToAbsPaths( inputFilesList, basePath) ffile = stgxml.createFlattenedXML(absInputFiles) xmlDoc = etree.parse(ffile) stgRoot = xmlDoc.getroot() # Go and grab necessary info from XML file fieldTestDataEl = stgxml.getStructNode(stgRoot, self.stgXMLSpecName) fieldTestListEl = stgxml.getListNode(fieldTestDataEl, self.stgXMLSpecFList) fieldTestEls = fieldTestListEl.getchildren() # As per the current spec, the field names are followed by an index # of analytic solution ii = 0 while ii < len(fieldTestEls): fieldName = fieldTestEls[ii].text self.fields[fieldName] = FieldComparisonOp(fieldName) # Skip the index ii += 1 ii += 1 # NB: not reading in all the other specifying stuff currently. Possibly # would be useful to do this in future. os.remove(ffile)
def readFromStgXML(self, inputFilesList, basePath): '''Read in the list of fields that have already been specified to be tested from a set of StGermain input files. Useful when e.g. working with an Analytic Solution plugin.''' self.fromXML = True # create a flattened file absInputFiles = stgpath.convertLocalXMLFilesToAbsPaths(inputFilesList, basePath) ffile=stgxml.createFlattenedXML(absInputFiles) xmlDoc = etree.parse(ffile) stgRoot = xmlDoc.getroot() # Go and grab necessary info from XML file componentEl = stgxml.getStructNode(stgRoot, self.stgXMLCompListName) fieldTestDataEl = stgxml.getStructNode(componentEl, self.stgXMLCompName) fieldTestListEl = stgxml.getListNode(fieldTestDataEl, self.stgXMLSpecFList) fieldTestStructEls = fieldTestListEl.getchildren() for fieldStruct in fieldTestStructEls: numericField=stgxml.getParamValue(fieldStruct,'NumericField',str) self.fields[numericField]=FieldComparisonOp(numericField) # NB: not reading in all the other specifying stuff currently. Possibly # would be useful to do this in future. os.remove(ffile)
def test_getListNode(self): listNode = stgxml.getListNode(self.flatXMLRoot, "FieldVariablesToCheckpoint") self.assertEqual(listNode.attrib['name'], "FieldVariablesToCheckpoint") self.assertEqual(listNode.text.strip(), "") self.assertEqual(len(listNode), 3) listNode = stgxml.getListNode(self.flatXMLRoot, "voodoo") self.assertEqual(listNode, None) # Test for the plugins and imports lists, in both listNode = stgxml.getListNode(self.inXMLRoot, "plugins") self.assertEqual(listNode.attrib['name'], "plugins") self.assertEqual(listNode.text.strip(), "") self.assertEqual(len(listNode), 2) listNode = stgxml.getListNode(self.flatXMLRoot, "plugins") self.assertEqual(listNode.tag, stgxml.addNsPrefix("plugins")) self.assertEqual(listNode.text.strip(), "") # This is a merged list, containing 3 plugin definitions self.assertEqual(len(listNode), 3) listNode = stgxml.getListNode(self.inXMLRoot, "import") self.assertEqual(listNode.attrib['name'], "import") self.assertEqual(listNode.text.strip(), "") self.assertEqual(len(listNode), 1) listNode = stgxml.getListNode(self.flatXMLRoot, "import") self.assertEqual(listNode.tag, stgxml.addNsPrefix("import")) self.assertEqual(listNode.text.strip(), "") self.assertEqual(len(listNode), 1)