def test_41_bad_destination_for_icd_file(self): print "\n(4.1) Test exception with a non-writable destination for ICD file.\n ", with SuppressOutput(): self.mThermAspectConfig.cIcdFile = "/users/delete_me.txt" newArticle = ThermAspectBuilder() newArticle.initialize(self.mThermAspectConfig) self.assertRaises(ThermError, newArticle.execute)
def test_31_circular_symbols(self): print "\n(3.1) Test exception when circular reference in symbols file.\n ", with SuppressOutput(): ## Include a symbols file with a circular reference. self.mThermAspectConfig.cSymFiles = ["symbolsTest.xml", "symbolsCircular.xml"] newArticle = ThermAspectBuilder() self.assertRaises(ThermError, newArticle.initialize, self.mThermAspectConfig)
def setUp(self): ## Instantiate ThermAspectConfig object. self.mThermAspectConfig = ThermAspectConfig() ## Loop through all individual networks. for network in tNetworks: ## Instantiate IndivNetworkConfig object. indivNetworkConfig = IndivNetworkConfig() ## Uniform ICD variables ## Name of sim system indivNetworkConfig.cIcdSettings.mSys = "iss" ## Name of icd bus indivNetworkConfig.cIcdSettings.mBus = "sim_bus" ## Name of icd trick sequence, or P-value. indivNetworkConfig.cIcdSettings.mTrickSeq = "P_PTCS " ## Name (abbreviation) of network to be built indivNetworkConfig.cNetwork = network ## Boolean to determine if the mass of structural nodes should be adjusted to match a ## total-mass expected value. indivNetworkConfig.cIsMassAdjustable = True #Files to read ............................................ ## Path and file name of Thermal Aspect Registry file. indivNetworkConfig.cRegisFile = tRegisPath % network ## Path and file name of Thermal Desktop file (TdNetworkConfig). indivNetworkConfig.cTdFile = tTdPath % (network,network) ## Path and file name of HtrRegistry file. indivNetworkConfig.cHtrFile = tHtrPath % network ## Path and file name of ThermalPanel registry/config file. indivNetworkConfig.cPanFile = tPanPath % network #Files to generate ........................................ ## Path and file name of Node configuration file. indivNetworkConfig.cNodeFile = tNodePath % network ## Path and file name of Conduction configuration file. indivNetworkConfig.cCondFile = tCondPath % network ## Path and file name of Radiation configuration file. indivNetworkConfig.cRadFile = tRadPath % network ## Path and file name of Et.Cetera (potentials, sources) configuration file. indivNetworkConfig.cEtcFile = tEtcPath % network ## Path and file name of TrickView file. Each network produces its own TrickView file. indivNetworkConfig.cTvFile = tTvPath % network ## Append the newly-constructed mIndivNetworkConfig to the list of network configs. self.mThermAspectConfig.cListNetworkConfigs.append(indivNetworkConfig) if "dummy" == network: #Files to read ............................................ ## Path and file name of Thermal Aspect Registry file. indivNetworkConfig.cRegisFile = None ## Path and file name of Thermal Desktop file (TdNetworkConfig). indivNetworkConfig.cTdFile = None ## Path and file name of HtrRegistry file. indivNetworkConfig.cHtrFile = None ## Path and file name of ThermalPanel registry/config file. indivNetworkConfig.cPanFile = None ## Set the mIndivNetworkConfig member as the first in the above loop. self.mIndivNetworkConfig = indivNetworkConfig ## Name of top-level script that creates the ThermAspectBuilder that creates this object. self.mThermAspectConfig.cCallingScript = thisScript ## Assumption to use for any specific heat values (Cp) not provided directly. self.mThermAspectConfig.cAssumedCp = 1.0 ## Set ICD file self.mThermAspectConfig.cIcdFile = tIcdFile ## Set enumeration header file. self.mThermAspectConfig.cEnumFile = tEnumFile ## Set symbol_loading module and files to read. self.mThermAspectConfig.cSymFiles = tSymFiles ## Instantiate an individual network indivPiece. self.indivPiece = IndivNetworkBuilder() ## Instantiate a full-scale article with the correct paths. self.article = ThermAspectBuilder() self.article.initialize(self.mThermAspectConfig)
class TestThermBuilder(unittest.TestCase): notSet = "[%s must explicitly be set]" uninitialized = "[%s not initialized]" def setUp(self): ## Instantiate ThermAspectConfig object. self.mThermAspectConfig = ThermAspectConfig() ## Loop through all individual networks. for network in tNetworks: ## Instantiate IndivNetworkConfig object. indivNetworkConfig = IndivNetworkConfig() ## Uniform ICD variables ## Name of sim system indivNetworkConfig.cIcdSettings.mSys = "iss" ## Name of icd bus indivNetworkConfig.cIcdSettings.mBus = "sim_bus" ## Name of icd trick sequence, or P-value. indivNetworkConfig.cIcdSettings.mTrickSeq = "P_PTCS " ## Name (abbreviation) of network to be built indivNetworkConfig.cNetwork = network ## Boolean to determine if the mass of structural nodes should be adjusted to match a ## total-mass expected value. indivNetworkConfig.cIsMassAdjustable = True #Files to read ............................................ ## Path and file name of Thermal Aspect Registry file. indivNetworkConfig.cRegisFile = tRegisPath % network ## Path and file name of Thermal Desktop file (TdNetworkConfig). indivNetworkConfig.cTdFile = tTdPath % (network,network) ## Path and file name of HtrRegistry file. indivNetworkConfig.cHtrFile = tHtrPath % network ## Path and file name of ThermalPanel registry/config file. indivNetworkConfig.cPanFile = tPanPath % network #Files to generate ........................................ ## Path and file name of Node configuration file. indivNetworkConfig.cNodeFile = tNodePath % network ## Path and file name of Conduction configuration file. indivNetworkConfig.cCondFile = tCondPath % network ## Path and file name of Radiation configuration file. indivNetworkConfig.cRadFile = tRadPath % network ## Path and file name of Et.Cetera (potentials, sources) configuration file. indivNetworkConfig.cEtcFile = tEtcPath % network ## Path and file name of TrickView file. Each network produces its own TrickView file. indivNetworkConfig.cTvFile = tTvPath % network ## Append the newly-constructed mIndivNetworkConfig to the list of network configs. self.mThermAspectConfig.cListNetworkConfigs.append(indivNetworkConfig) if "dummy" == network: #Files to read ............................................ ## Path and file name of Thermal Aspect Registry file. indivNetworkConfig.cRegisFile = None ## Path and file name of Thermal Desktop file (TdNetworkConfig). indivNetworkConfig.cTdFile = None ## Path and file name of HtrRegistry file. indivNetworkConfig.cHtrFile = None ## Path and file name of ThermalPanel registry/config file. indivNetworkConfig.cPanFile = None ## Set the mIndivNetworkConfig member as the first in the above loop. self.mIndivNetworkConfig = indivNetworkConfig ## Name of top-level script that creates the ThermAspectBuilder that creates this object. self.mThermAspectConfig.cCallingScript = thisScript ## Assumption to use for any specific heat values (Cp) not provided directly. self.mThermAspectConfig.cAssumedCp = 1.0 ## Set ICD file self.mThermAspectConfig.cIcdFile = tIcdFile ## Set enumeration header file. self.mThermAspectConfig.cEnumFile = tEnumFile ## Set symbol_loading module and files to read. self.mThermAspectConfig.cSymFiles = tSymFiles ## Instantiate an individual network indivPiece. self.indivPiece = IndivNetworkBuilder() ## Instantiate a full-scale article with the correct paths. self.article = ThermAspectBuilder() self.article.initialize(self.mThermAspectConfig) def test_11_construction(self): print "\n(1.1) Test generic construction.\n ", newPiece = IndivNetworkBuilder() self.assertEqual(newPiece.mRegisFile, self.uninitialized % "mRegisFile") self.assertEqual(newPiece.mTdFile, self.uninitialized % "mTdFile") self.assertEqual(newPiece.mNodeFile, self.uninitialized % "mNodeFile") self.assertEqual(newPiece.mCondFile, self.uninitialized % "mCondFile") self.assertEqual(newPiece.mRadFile, self.uninitialized % "mRadFile") self.assertEqual(newPiece.mHtrFile, self.uninitialized % "mHtrFile") self.assertEqual(newPiece.mPanFile, self.uninitialized % "mPanFile") self.assertEqual(newPiece.mEtcFile, self.uninitialized % "mEtcFile") self.assertEqual(newPiece.mTvFile, self.uninitialized % "mTvFile") ## @test Cannot execute on uninitialized article. with SuppressOutput(): self.assertRaises(ThermError, newPiece.execute) def test_12_initialization(self): print "\n(1.2) Test initialize().\n ", self.assertEqual(self.article.mSymFiles, tSymFiles) self.assertEqual(self.article.mIcdFile, tIcdFile) self.assertEqual(self.article.mEnumFile, tEnumFile) self.assertEqual(self.article.mIndivNetworkBuilders[-1].mRegisFile, tRegisPath % tNetwork) self.assertEqual(self.article.mIndivNetworkBuilders[-1].mTdFile, tTdPath % (tNetwork,tNetwork)) self.assertEqual(self.article.mIndivNetworkBuilders[-1].mNodeFile, tNodePath % tNetwork) self.assertEqual(self.article.mIndivNetworkBuilders[-1].mCondFile, tCondPath % tNetwork) self.assertEqual(self.article.mIndivNetworkBuilders[-1].mRadFile, tRadPath % tNetwork) self.assertEqual(self.article.mIndivNetworkBuilders[-1].mHtrFile, tHtrPath % tNetwork) self.assertEqual(self.article.mIndivNetworkBuilders[-1].mPanFile, tPanPath % tNetwork) self.assertEqual(self.article.mIndivNetworkBuilders[-1].mEtcFile, tEtcPath % tNetwork) self.assertEqual(self.article.mIndivNetworkBuilders[-1].mTvFile, tTvPath % tNetwork) def test_21_no_tdNetworkConfig_file(self): print "\n(2.1) Test exception when tdNetworkConfig file cannot be loaded.\n ", with SuppressOutput(): self.mIndivNetworkConfig.cTdFile = "td_file_doesnt_exist" self.indivPiece.initialize(self.mIndivNetworkConfig) self.assertRaises(ThermError, self.indivPiece.execute) def test_22_no_ThermRegistry_file(self): print "\n(2.2) Test exception when ThermRegistry file cannot be loaded.\n ", with SuppressOutput(): self.mIndivNetworkConfig.cRegisFile = "registry_file_doesnt_exist" self.indivPiece.initialize(self.mIndivNetworkConfig) self.assertRaises(ThermError, self.indivPiece.execute) def test_23_execute_before_initialize(self): print "\n(2.3) Test exception when IndivNetworkBuilder executed before initialized.\n ", with SuppressOutput(): self.assertRaises(ThermError, self.indivPiece.execute) def test_24_registry_not_well_formed(self): print "\n(2.4) Test exception when ThermRegistry not well formed.\n ", with SuppressOutput(): self.mIndivNetworkConfig.cRegisFile = "ThermRegistry_notwellformed.xml" self.indivPiece.initialize(self.mIndivNetworkConfig) self.assertRaises(ThermError, self.indivPiece.execute) def test_31_circular_symbols(self): print "\n(3.1) Test exception when circular reference in symbols file.\n ", with SuppressOutput(): ## Include a symbols file with a circular reference. self.mThermAspectConfig.cSymFiles = ["symbolsTest.xml", "symbolsCircular.xml"] newArticle = ThermAspectBuilder() self.assertRaises(ThermError, newArticle.initialize, self.mThermAspectConfig) def test_41_bad_destination_for_icd_file(self): print "\n(4.1) Test exception with a non-writable destination for ICD file.\n ", with SuppressOutput(): self.mThermAspectConfig.cIcdFile = "/users/delete_me.txt" newArticle = ThermAspectBuilder() newArticle.initialize(self.mThermAspectConfig) self.assertRaises(ThermError, newArticle.execute) 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().") ## Test correct number of nodes. self.assertEqual(len(self.article.mIndivNetworkBuilders[-1].masterNodeList), tNumNodes) ## Test capacitance of node that should have been overwritten by an explicity symbol. self.assertAlmostEqual(float(capExplicit), tCapExplicit) ## Test that mass was appropriately scaled to match the given total. self.assertAlmostEqual(massSum, tTotalMass, 1) ## Test correct number of panels. self.assertEqual(len(self.article.mIndivNetworkBuilders[-1].mPanList), tNumPanels) ## Test correct number of radiation links. self.assertEqual(len(radEntries), tNumRadLinks) ## Test correct radiation coefficients. self.assertAlmostEqual(float(radCoeffRegis), tRadCoeffRegis) self.assertAlmostEqual(float(radCoeffTd), tRadCoeffTd)
## Nullify unneeded files in the HX network. if 'hx' == network: indivNetworkConfig.cTdFile = None indivNetworkConfig.cHtrFile = indivNetworkConfig.cHtrFile.replace( 'HtrRegis', 'SrcRegis') indivNetworkConfig.cPanFile = None ## Change the HX to operate at a higher rate indivNetworkConfig.cIcdSettings.mPtcsRate = "HX_RATE" ## Append the newly-constructed mIndivNetworkConfig to the list of network configs. thermAspectConfig.cListNetworkConfigs.append(indivNetworkConfig) try: ## Instantiate, initialize, and execute the ThermAspectBuilder. builder = ThermAspectBuilder() builder.initialize(thermAspectConfig) builder.execute() except Exception, e: ## Build error message, checking first to see if colors are enabled. if sys.stdout.isatty(): # print in red print "\033[31mERROR!!!!!!!!!!!!!!!\033[0m", else: # print normal print "ERROR!!!!!!!!!!!!!!!!!!!!!!!!!!", print e print "Building of PTCS networks has FAILED.\n" print "======================================================================"