def testLoadTables(self): "Test Readin of IGM Lookup Tables" tableDirectory = str(os.environ['SIMS_SED_LIBRARY_DIR'] + '/igm') #First make sure that if variance option is turned on but there are no variance files that #the correct error is raised testIGM = ApplyIGM() testIGM.initializeIGM(zMax = 1.5) testMeanLookupTable = open('MeanLookupTable_zSource1.5.tbl', 'w') testMeanLookupTable.write('300.0 0.9999') testMeanLookupTable.close() self.assertRaisesRegexp(IOError, "Cannot find variance tables.", testIGM.loadTables, os.getcwd()) os.remove('MeanLookupTable_zSource1.5.tbl') #Then make sure that the mean lookup tables and var lookup tables all get loaded into proper dicts testIGMDicts = ApplyIGM() testIGMDicts.initializeIGM() testIGMDicts.loadTables(tableDirectory) redshiftValues = ['1.5', '1.6', '1.7', '1.8', '1.9', '2.0', '2.1', '2.2', '2.3', '2.4', '2.5', '2.6', '2.7', '2.8', '2.9'] self.assertItemsEqual(testIGMDicts.meanLookups.keys(), redshiftValues) self.assertItemsEqual(testIGMDicts.varLookups.keys(), redshiftValues) #Finally make sure that if Variance Boolean is false that nothing is passed in to varLookups testIGMVar = ApplyIGM() testIGMVar.initializeIGM() testIGMVar.loadTables(tableDirectory, varianceTbl = False) self.assertEqual(testIGMVar.varLookups, {})
def testLoadTables(self): "Test Readin of IGM Lookup Tables" tableDirectory = str(os.environ['SIMS_SED_LIBRARY_DIR'] + '/igm') #First make sure that if variance option is turned on but there are no variance files that #the correct error is raised testIGM = ApplyIGM() testIGM.initializeIGM(zMax=1.5) testMeanLookupTable = open('MeanLookupTable_zSource1.5.tbl', 'w') testMeanLookupTable.write('300.0 0.9999') testMeanLookupTable.close() self.assertRaisesRegexp(IOError, "Cannot find variance tables.", testIGM.loadTables, os.getcwd()) os.remove('MeanLookupTable_zSource1.5.tbl') #Then make sure that the mean lookup tables and var lookup tables all get loaded into proper dicts testIGMDicts = ApplyIGM() testIGMDicts.initializeIGM() testIGMDicts.loadTables(tableDirectory) redshiftValues = [ '1.5', '1.6', '1.7', '1.8', '1.9', '2.0', '2.1', '2.2', '2.3', '2.4', '2.5', '2.6', '2.7', '2.8', '2.9' ] self.assertItemsEqual(testIGMDicts.meanLookups.keys(), redshiftValues) self.assertItemsEqual(testIGMDicts.varLookups.keys(), redshiftValues) #Finally make sure that if Variance Boolean is false that nothing is passed in to varLookups testIGMVar = ApplyIGM() testIGMVar.initializeIGM() testIGMVar.loadTables(tableDirectory, varianceTbl=False) self.assertEqual(testIGMVar.varLookups, {})
def testLoadTables(self): "Test Read-in of IGM Lookup Tables" tableDirectory = str(getPackageDir('sims_photUtils') + '/python/lsst/sims/photUtils/igm_tables') # First make sure that if variance option is turned on but # there are no variance files that the correct error is raised testIGM = ApplyIGM() testIGM.initializeIGM(zMax = 1.5) with gzip.open('MeanLookupTable_zSource1.5.tbl.gz', 'wt') as testMeanLookupTable: testMeanLookupTable.write('300.0 0.9999\n') self.assertRaisesRegexp(IOError, "Cannot find variance tables.", testIGM.loadTables, os.getcwd()) os.remove('MeanLookupTable_zSource1.5.tbl.gz') # Then make sure that the mean lookup tables and var lookup # tables all get loaded into proper dicts testIGMDicts = ApplyIGM() testIGMDicts.initializeIGM() testIGMDicts.loadTables(tableDirectory) redshiftValues = ['1.5', '1.6', '1.7', '1.8', '1.9', '2.0', '2.1', '2.2', '2.3', '2.4', '2.5', '2.6', '2.7', '2.8', '2.9'] # Python 3 replaces assertItemsEqual() with assertCountEqual() if hasattr(self, 'assertItemsEqual'): self.assertItemsEqual(list(testIGMDicts.meanLookups.keys()), redshiftValues) self.assertItemsEqual(list(testIGMDicts.varLookups.keys()), redshiftValues) else: self.assertCountEqual(list(testIGMDicts.meanLookups.keys()), redshiftValues) self.assertCountEqual(list(testIGMDicts.varLookups.keys()), redshiftValues) # Finally make sure that if Variance Boolean is false that # nothing is passed in to varLookups testIGMVar = ApplyIGM() testIGMVar.initializeIGM() testIGMVar.loadTables(tableDirectory, varianceTbl = False) self.assertEqual(testIGMVar.varLookups, {})