def test_51_execution(self): print "\n(5.1) Test execution.\n ", capExplicit = "0" radEntries = None radCoeffRegis = "" radCoeffTd = "" try: self.article.execute() ## Check mass calculation parser = XmlParser() data = parser.loadFile(tNodePath % tNetwork) ## Open it for reading and save its xml data. entries = parser.getElements(data, "node") ## Loop through each source entry, totaling the mass. massSum = 0; for entry in entries: ## Create and initialize XmlEntryAnalyzer object. mass = parser.getChildText(entry, "mass") massSum = massSum + float(mass) ## Store capacitance of a specific node in question. if "GOOD_EXPLICIT_12" == parser.getChildText(entry, "name"): capExplicit = parser.getChildText(entry, "capacitance") ## Read radiation data for testing. radData = parser.loadFile(tRadPath % tNetwork) radEntries = parser.getElements(radData, "radiation") ## Check radiation coefficients. radCoeffTd = parser.getChildText(radEntries[0], "coefficient") radCoeffRegis = parser.getChildText(radEntries[1], "coefficient") except (Exception), e: print e self.fail("Uncaught exception during execute().")
class SymbolLoader(): ## @brief: ## Constructs the SymbolLoader and creates a XmlParser object. def __init__(self): ## An XmlParser() object for getting data from xml elements. self.mParser = XmlParser() ## Stores name of current file being parsed. self.mCurrentFile = "[mCurrentFile not set]" #=============================================================================================== ## @brief: ## Main public function. Creates a dictionary based on symbols defined in the xml file. ## @param[in]: symFiles name of xml-file containing symbols data ## @return: a dictionary with key = symbol, value = resulting numerical value of symbol def execute(self, symFiles): masterNameList = [] masterExpList = [] for file in symFiles: ## Read each file. [nameList, expList, desList, groupList] = self.loadSymbolsFrom(file) ## Update master lists masterNameList = masterNameList + nameList masterExpList = masterExpList + expList return self.defineSymbols(masterNameList, masterExpList, locals()) # ---------------------------------------------------------------------------------------------- ## @brief: ## Private method. Defines a symbol list given an expression list. ## @param[in]: symFile name of xml-file containing symbols data ## @param[in]: areDesAndGroupIncluded a boolean to specify if the group/des tags need to be ## read as well (like in the generate_TD_symbols case) ## @return: nameList list of text under <name> tag in symbols xml ## @return: expList list of text under <exp> tag in symbols xml def loadSymbolsFrom(self, symFile): ## Set current file for error reporting purposes. self.mCurrentFile = symFile ## Try to open the symbol file. Open it for reading and save its xml data. symbols = self.mParser.loadFile(symFile) ## Initialize lists. nameList = [] expList = [] desList = [] groupList = [] ## Loop over the symbols. for symbol in symbols: ## Initialize name for error reporting. name = "[error reading name]" ## Get data. try: name = self.mParser.getChildText(symbol, "name") expElem = self.mParser.getElements(symbol, "exp", True, name)[0] expText = self.mParser.getText(expElem, name) if name in nameList: ## If the symbol is a mass, it can overwrite a previous instance. if 'mass_' == name[:5]: expList[nameList.index(name)] = expText continue else: raise ThermError("Symbol previously defined (%s)." % name) ## Special instructions for capacitance symbols, for mass accounting purposes. if 'cap_' == name[:4]: try: ## Read the given mass from the symbols element. specHeatText = self.mParser.getChildText( expElem, "specHeat", name) massText = self.mParser.getChildText( expElem, "mass", name).replace('%Cp', specHeatText) expText = "(%s) * (%s)" % (massText, specHeatText) except (TagNotFound), e: ## Store a "-1" as an indication that no mass data was provided. massText = "-1" ## Append a symbol for the mass. nameList.append(name.replace("cap_", "mass_")) expList.append(massText) ## Append name and expression to list. nameList.append(name) expList.append(expText) except (TagNotFound, ThermError), e: print e, print "Symbol will be ignored (%s)." % name continue