def setUp(self): # TODO: Move into setupclass for big files # May have to copy data in the write tests to avoid poisoning the other tests filename = 'coad/master.xml' #filename='test/118-Bus.xml' #filename='test/Solar33P.xml' #filename='test/WFIP-MISO.xml' #filename='test/WWSIS.xml' self.coad = COAD(filename) # Fix bad api for python 3.2 if not hasattr(self, 'assertItemsEqual'): self.assertItemsEqual = self.assertCountEqual
def test_get_properties(self): '''Test get properties ''' filename = 'coad/test/118-Bus.xml' coad = COAD(filename) # Get properties line = coad['Line']['126'] props = { 'System.System': { 'Reactance': '0.0202', 'Max Flow': '9900', 'Min Flow': '-9900', 'Resistance': '0.00175' } } self.assertEqual(line.get_properties(), props) # Get property self.assertEqual(line.get_property('Max Flow', 'System.System'), '9900') # Get properties filename = 'coad/test/RTS-96.xml' coad = COAD(filename) g = coad['Generator']['101-1'] props = { 'System.System': { 'Mean Time to Repair': '50', 'Load Point': ['15.8', '16', '19.8', '20'], 'Heat Rate': ['15063', '15000', '14500', '14499'], 'Min Up Time': '1', 'Max Ramp Up': '3', 'Min Down Time': '1', 'Min Stable Level': '15.8', 'Units': '1', 'Start Cost Time': ['0', '1'], 'Maintenance Frequency': '2', 'Maintenance Rate': '3.84', 'Max Capacity': '20', 'Forced Outage Rate': '10' } } self.assertEqual(g.get_properties(), props) # Get property self.assertEqual(g.get_property('Load Point'), ['15.8', '16', '19.8', '20']) # Tagged properties #print coad['Generator']['118-1'].get_properties() self.assertEqual( coad['Generator']['118-1'].get_properties()['Scenario.RT_UC'], {'Commit': '0'})
def test_multi_properties(self): '''Tests related to properties with a list of values ''' filename = 'coad/test/RTS-96.xml' coad = COAD(filename) # Get properties g = coad['Generator']['101-1'] props = { 'Mean Time to Repair': '50', 'Load Point': ['15.8', '16', '19.8', '20'], 'Heat Rate': ['15063', '15000', '14500', '14499'], 'Min Up Time': '1', 'Max Ramp Up': '3', 'Min Down Time': '1', 'Min Stable Level': '15.8', 'Units': '1', 'Start Cost Time': ['0', '1'], 'Maintenance Frequency': '2', 'Maintenance Rate': '3.84', 'Max Capacity': '20', 'Forced Outage Rate': '10' } self.assertEqual(g.get_properties()['System.System'], props) # Get property self.assertEqual(g.get_property('Load Point'), ['15.8', '16', '19.8', '20']) # Set property g.set_property('Load Point', ['a', 'b', 'c', 'd']) self.assertEqual(g.get_property('Load Point'), ['a', 'b', 'c', 'd']) # Set property with wrong length with self.assertRaises(Exception): g.set_property('Load Point', ['a', 'b', 'c']) # Set properties new_props = { 'Maintenance Rate': 'aaaa', 'Heat Rate': ['bbbb', 'cccc', 'dddd', 'eeee'] } g2 = coad['Generator']['123-3'] g2.set_properties(new_props) # Test save and load coad.save('coad/test/RTS-96_props_test.xml') saved_coad = COAD('coad/test/RTS-96_props_test.xml') props['Load Point'] = ['a', 'b', 'c', 'd'] g = saved_coad['Generator']['101-1'] self.assertEqual(g.get_properties()['System.System'], props) g2 = saved_coad['Generator']['123-3'] self.assertEqual(g2.get_property('Maintenance Rate'), new_props['Maintenance Rate']) self.assertEqual(g2.get_property('Heat Rate'), new_props['Heat Rate'])
def test_blank_elements(self): '''Make sure blank elements are saved properly ''' filename = 'coad/test/118-Bus_with_blanks.xml' pre = COAD(filename) cur = pre.dbcon.execute( "SELECT name FROM category WHERE category_id=49") val = cur.fetchone()[0] self.assertEqual(val, "") pre.save('coad/test/118-Bus_with_blanks_test.xml') post = COAD('coad/test/118-Bus_with_blanks_test.xml') cur = post.dbcon.execute( "SELECT name FROM category WHERE category_id=49") val = cur.fetchone()[0] self.assertEqual(val, "")
def test_set_children(self): # Single new child self.coad['Model']['Base'].set_children( self.coad['Performance']['Gurobi']) should_contain = [ self.coad['Horizon']['Base'], self.coad['Report']['Base'], self.coad['ST Schedule']['Base'], self.coad['Performance']['Gurobi'] ] self.assertEqual(should_contain, self.coad['Model']['Base'].get_children()) # Duplicates self.coad['Model']['Base'].set_children( self.coad['Performance']['Gurobi'], replace=False) self.assertEqual( 1, len(self.coad['Model']['Base'].get_children('Performance'))) # TODO: Test multiple new children of different classes that overwrites existing # TODO: Test adding new child once collection functionality is understood # TODO: Add mix of new child classes once collection functionality is understood # Children with multiple collections available filename = 'coad/test/RTS-96.xml' coad = COAD(filename) self.assertRaises(Exception, coad['Node']['101'].set_children, coad['Zone'].meta['class_id']) self.assertEqual( 178, coad['Node']['101'].get_collection_id( coad['Zone'].meta['class_id'], name="Zone")) dzone = coad['Zone'].new("Dummy Zone") coad['Node']['101'].set_children(dzone, name="Zone")
def test_split_horizon_split_type_multiatatime(self): '''Test splitting a horizon with multiple steps at a time on a different step type ''' coad = COAD('coad/test/horizon_split_test.xml') split_horizon(coad, 'MultiAtATime', 4, 0, split_type=2, planning_horizon=3) test_name = 'MultiAtATime_004P_OLd000_001' self.assertIn(test_name, coad['Model'].keys()) horizons = coad['Model'][test_name].get_children("Horizon") self.assertEqual(1, len(horizons)) self.assertEqual(test_name, horizons[0].meta['name']) h = coad['Horizon'][test_name] self.assertEqual('45292.0', h['Chrono Date From']) self.assertEqual('64.0', h['Chrono Step Count']) self.assertEqual('1', h['Chrono Step Type']) self.assertEqual('3', h['Chrono At a Time']) self.assertEqual('45292', h["Date From"]) self.assertEqual('1', h["Step Count"]) self.assertEqual('3', h["Step Type"]) test_name = 'MultiAtATime_004P_OLd000_004' self.assertIn(test_name, coad['Model'].keys()) horizons = coad['Model'][test_name].get_children("Horizon") self.assertEqual(1, len(horizons)) self.assertEqual(test_name, horizons[0].meta['name']) h = coad['Horizon'][test_name] self.assertEqual('45316.0', h['Chrono Date From']) self.assertEqual('56.0', h['Chrono Step Count']) self.assertEqual('1', h['Chrono Step Type']) self.assertEqual('3', h['Chrono At a Time']) self.assertEqual('45292', h["Date From"]) self.assertEqual('2', h["Step Count"]) self.assertEqual('3', h["Step Type"])
def test_modify_single_tagged_properties(self): '''Tests related to modifying tagged properties with a single value ''' filename = 'coad/test/RTS-96.xml' coad = COAD(filename) self.assertEqual( coad['Generator']['118-1'].get_properties()['Scenario.RT_UC'], {'Commit': '0'}) coad['Generator']['118-1'].set_property('Commit', 'totally_committed', 'Scenario.RT_UC') # Test that dynamic and enabled flag is not set for Unit Commitment Optimality self.assertEqual( coad['Generator'].valid_properties['System']['12']['is_dynamic'], 'false') self.assertEqual( coad['Generator'].valid_properties['System']['12']['is_enabled'], 'false') self.assertRaises(Exception, coad['Generator']['118-1'].set_property, 'Unit Commitment Optimality', 'I hate input masks', 'Scenario.RT_UC') # Make sure invalid assignment does not trigger is_dynamic=true self.assertEqual( coad['Generator'].valid_properties['System']['12']['is_dynamic'], 'false') self.assertEqual( coad['Generator'].valid_properties['System']['12']['is_enabled'], 'false') # This tag isn't set at all coad['Generator']['118-1'].set_property('Unit Commitment Optimality', 'Rounded Relaxation', 'Scenario.RT_UC') self.assertEqual( coad['Generator'].valid_properties['System']['12']['is_dynamic'], 'true') self.assertEqual( coad['Generator'].valid_properties['System']['12']['is_enabled'], 'true') coad.save('coad/test/RTS-96_props_test.xml') saved_coad = COAD('coad/test/RTS-96_props_test.xml') expected = { 'Commit': 'totally_committed', 'Unit Commitment Optimality': 'Rounded Relaxation' } self.assertEqual( saved_coad['Generator']['118-1'].get_properties() ['Scenario.RT_UC'], expected)
def test_new_object(self): '''Test creation of objects ''' copy_coad = COAD('coad/master.xml') new_obj = copy_coad['Model'].new("Test Model") self.assertEqual("Test Model", new_obj.meta['name']) new_obj2 = copy_coad['Model'].new("Test Model Custom", category="Custom Category") self.assertEqual("Test Model Custom", new_obj2.meta['name']) self.assertEqual("Custom Category", new_obj2.get_category()) filename = 'coad/test/RTS-96.xml' coad = COAD(filename) new_obj = coad['Node'].new("Test Node") new_obj.set_property("Allow Dump Energy", "No") self.assertEqual("No", new_obj.get_property("Allow Dump Energy")) coad['Purchaser'].new("Mypurchase") self.assertEqual('true', coad['Purchaser'].meta['is_enabled'])
def test_delete_properties(self): '''Tests related to deleting properties ''' filename = 'coad/test/RTS-96.xml' coad = COAD(filename) g = coad['Generator']['101-1'] props = {'Load Point': ['1', '2', '3', '4']} g.set_property("Load Point", props['Load Point'], tag="Scenario.DA") self.assertEqual(props, g.get_properties()['Scenario.DA']) g.delete_property("Load Point", tag="Scenario.DA") self.assertNotIn("Scenario.DA", g.get_properties().keys())
def test_add_set_category(self): '''Test category creation for class and set for object ''' copy_coad = COAD('coad/master.xml') copy_coad['Performance'].add_category("Test Category") new_cat = copy_coad['Performance'].get_categories()[1] self.assertEqual("Test Category", new_cat['name']) self.assertEqual("1", new_cat['rank']) copy_coad['Performance']['Gurobi'].set_category("Test Category") self.assertEqual("Test Category", copy_coad['Performance']['Gurobi'].get_category())
def test_modify_multiband_tagged_properties(self): '''Tests related to modifying tagged properties with a list of values ''' filename = 'coad/test/RTS-96.xml' coad = COAD(filename) test_list = ['1', '2', '3', '4'] coad['Generator']['118-1'].set_property("Load Point", test_list, tag="Scenario.4HA_UC") self.assertEqual( coad['Generator']['118-1'].get_property("Load Point", "Scenario.4HA_UC"), test_list)
def test_tag_property(self): '''Test tagging and untagging of existing property ''' filename = 'coad/test/RTS-96.xml' coad = COAD(filename) g = coad['Generator']['101-1'] props = { 'Load Point': ['15.8', '16', '19.8', '20'], } g.tag_property("Load Point", tag="Scenario.DA") self.assertEqual(props, g.get_properties()['Scenario.DA']) g.untag_property("Load Point", tag="Scenario.DA") self.assertNotIn("Scenario.DA", g.get_properties().keys())
def test_get_text(self): '''Get text values for Data File objects ''' filename = 'coad/test/RTS-96.xml' coad = COAD(filename) expected = { u'Scenario.4HA_UC': { u'Filename': u'\\Model a_DA_Base Solution\\interval\\ST Generator(*).Units Generating.csv' } } result = coad['Data File']['4HA_UC'].get_text() self.assertEqual(result, expected)
def test_7_400_2(self): '''Test changes related to the 7.400.2 version of master.xml ''' coad = COAD('coad/master_7.400.2.xml') # Test model first, as the horizons will attach themselves to the copied base model oldobj = coad['Model']['Base'] newobj = oldobj.copy('Test Base Model') self.assertIn('Test Base Model', coad['Model']) should_contain = [ coad['Horizon']['Base'], coad['Report']['Base'], coad['ST Schedule']['Base'] ] self.assertItemsEqual(should_contain, coad['Model']['Test Base Model'].get_children()) oldobj = coad['Horizon']['Base'] newobj = oldobj.copy('New Horizon') self.assertNotEqual(oldobj.meta['name'], newobj.meta['name']) for (k, v) in oldobj.items(): self.assertEqual(v, newobj[k]) self.assertEqual(['Base', 'New Horizon'], coad.list('Horizon')) self.assertNotEqual(coad['Horizon']['Base'].meta['GUID'], coad['Horizon']['New Horizon'].meta['GUID']) newobj = oldobj.copy() self.assertNotEqual(oldobj.meta['name'], newobj.meta['name'])
def test_single_properties(self): '''Tests related to properties with a single value ''' filename = 'coad/test/118-Bus.xml' coad = COAD(filename) # Get properties line = coad['Line']['126'] props = { 'Reactance': '0.0202', 'Max Flow': '9900', 'Min Flow': '-9900', 'Resistance': '0.00175' } self.assertEqual(line.get_properties()['System.System'], props) # Get property self.assertEqual(line.get_property('Max Flow'), '9900') # Set property line.set_property('Min Flow', '123456') self.assertEqual(line.get_property('Min Flow'), '123456') # Set properties new_props = { 'Reactance': 'aaaa', 'Max Flow': 'bbbb', 'Min Flow': 'cccc', 'Resistance': 'dddd' } line_a = coad['Line']['027'] line_a.set_properties(new_props) # Test save and load coad.save('coad/test/118-Bus_props_test.xml') solar = COAD('coad/test/118-Bus_props_test.xml') props['Min Flow'] = '123456' line = solar['Line']['126'] self.assertEqual(line.get_properties()['System.System'], props) line_a = coad['Line']['027'] self.assertEqual(line_a.get_properties()['System.System'], new_props)
def test_split_horizon(self): coad = COAD('coad/test/Solar33P.xml') split_horizon(coad,'M01 Cost Need 0603',8,0,True) test_no_offset = 'M01 Cost Need 0603_008P_OLd000_007' self.assertIn(test_no_offset,coad['Model'].keys()) self.assertIn(coad['Horizon'][test_no_offset],coad['Model'][test_no_offset].get_children()) self.assertEqual('43843.0',coad['Horizon'][test_no_offset]['Chrono Date From']) self.assertEqual('2.0',coad['Horizon'][test_no_offset]['Chrono Step Count']) split_horizon(coad,'M01 Cost Need 0603',8,1,True) test_day_offset = 'M01 Cost Need 0603_008P_OLd001_006' self.assertIn(test_no_offset,coad['Model'].keys()) self.assertIn(coad['Horizon'][test_day_offset],coad['Model'][test_day_offset].get_children()) self.assertEqual('43840.0',coad['Horizon'][test_day_offset]['Chrono Date From']) self.assertEqual('3.0',coad['Horizon'][test_day_offset]['Chrono Step Count']) self.assertIn(coad['Model'][test_no_offset], coad['System']['WECC'].get_children('Model')) self.assertIn(coad['Horizon'][test_no_offset], coad['System']['WECC'].get_children('Horizon'))
def test_split_horizon_split_type(self): '''Test splitting a horizon on a different step type ''' coad = COAD('coad/test/horizon_split_test.xml') split_horizon(coad, 'Base', 52, 0, split_type=2) test_name = 'Base_052P_OLd000_001' self.assertIn(test_name, coad['Model'].keys()) # assertEqual will always return true with objects of the same type, even if they're different objects horizons = coad['Model'][test_name].get_children("Horizon") self.assertEqual(1, len(horizons)) self.assertEqual(test_name, horizons[0].meta['name']) self.assertEqual('43831.0',coad['Horizon'][test_name]['Chrono Date From']) self.assertEqual('168.0',coad['Horizon'][test_name]['Chrono Step Count']) self.assertEqual('1',coad['Horizon'][test_name]['Chrono Step Type']) test_name = 'Base_052P_OLd000_025' horizons = coad['Model'][test_name].get_children("Horizon") self.assertEqual(1, len(horizons)) self.assertEqual(test_name, horizons[0].meta['name']) self.assertEqual('43999.0',coad['Horizon'][test_name]['Chrono Date From']) self.assertEqual('168.0',coad['Horizon'][test_name]['Chrono Step Count']) self.assertEqual('1',coad['Horizon'][test_name]['Chrono Step Type']) test_name = 'Base_052P_OLd000_052' horizons = coad['Model'][test_name].get_children("Horizon") self.assertEqual(1, len(horizons)) self.assertEqual(test_name, horizons[0].meta['name']) self.assertEqual('44188.0',coad['Horizon'][test_name]['Chrono Date From']) self.assertEqual('216.0',coad['Horizon'][test_name]['Chrono Step Count']) self.assertEqual('1',coad['Horizon'][test_name]['Chrono Step Type']) # Make sure the original model only has the one horizon horizons = coad['Model']['Base'].get_children("Horizon") self.assertEqual(1, len(horizons)) self.assertEqual('Base', horizons[0].meta['name']) # Test planning horizon test_name = 'Base_052P_OLd000_052' h = coad['Horizon'][test_name] set_planning_horizon(h) self.assertEqual(44166, h["Date From"]) self.assertEqual(2, h["Step Count"]) self.assertEqual(3, h["Step Type"]) set_planning_horizon(h, step_type=1) self.assertEqual('44188.0', h["Date From"]) self.assertEqual(10, h["Step Count"]) self.assertEqual(1, h["Step Type"])
def test_set_text(self): '''Set text values for Data File objects ''' filename = 'coad/test/RTS-96.xml' coad = COAD(filename) # Change an existing data file expected = {'Scenario.4HA_UC': {'Filename': 'test_filename'}} coad['Data File']['4HA_UC'].set_text('Filename', 'test_filename') result = coad['Data File']['4HA_UC'].get_text() self.assertEqual(result, expected) # Create a new data file text coad['Data File']['RT_UC'].copy('test_data_file') coad['Data File']['test_data_file'].set_text('Filename', 'another_test_filename', tag='Scenario.4HA_UC') result = coad['Data File']['test_data_file'].get_text() expected = {'Scenario.4HA_UC': {'Filename': 'another_test_filename'}} self.assertEqual(result, expected) cur = coad.dbcon.cursor() cur.execute( "SELECT class_id FROM text WHERE data_id=(SELECT MAX(data_id) FROM text)" ) self.assertEqual(41, cur.fetchone()[0]) # Dup settings caused prop list to grow coad['Data File']['test_data_file'].set_text('Filename', 'another_test_filename', tag='Scenario.4HA_UC') result = coad['Data File']['test_data_file'].get_properties() self.assertEqual('0', result['Scenario.4HA_UC']['Filename']) # set_text to another tag with datafile must create a new data row coad['Region']['Region1'].set_text('Load', 'another_test_filename', tag='Scenario.4HA_UC') cur.execute( "SELECT data_id FROM property_view WHERE child_object_id=? AND name='Load'", (coad['Region']['Region1'].meta['object_id'], )) result = [row[0] for row in cur.fetchall()] # Should be 3 with no duplicates self.assertEqual(len(set(result)), 3)
def main(): parser = argparse.ArgumentParser(description="Export csv files for a specific PLEXOS input model") parser.add_argument('-f', '--filepath', help='path to PLEXOS input .xml or .db') parser.add_argument('-a', '--all', help='all objects in dataset',default='True') parser.add_argument('-m', '--models', help='list of models to export',default='') parser.add_argument('-c', '--filter_cls', help='optional-class of filter string, e.g. Region, Zone',default='') parser.add_argument('-n', '--filter_val', help='optional-name of region or zone to extract',default='') parser.add_argument('-o', '--output_folder', help='folder to output csv files') args = parser.parse_args() from coad.COAD import COAD from coad.export_plexos_model import write_object_report coad = COAD(args.filepath) if args.all: all_objs = get_all_objects(coad) write_object_report(coad['System']['System'],interesting_objs = all_objs, folder = args.output_folder) else: for m in args.models: write_object_report(coad['Model'][m],interesting_objs = None, folder = args.output_folder)
import datetime from coad.COAD import COAD from coad.ModelUtil import datetime_to_plex coad = COAD('RTS-GMLC.xml') #7/14/2024 date_start = str(datetime_to_plex(datetime.datetime(2024, 7, 14, 0, 0))) new_horizon = coad['Horizon']['Base'].copy("Interesting Week") new_horizon["Step Count"] = "8" new_horizon["Date From"] = date_start new_horizon["Chrono Date From"] = date_start new_horizon["Chrono Step Count"] = "8" coad['Model']['DAY_AHEAD'].set_children(new_horizon) coad.save("one_week_model.xml")
class TestObjectDict(unittest.TestCase): def setUp(self): # TODO: Move into setupclass for big files # May have to copy data in the write tests to avoid poisoning the other tests filename = 'coad/master.xml' #filename='test/118-Bus.xml' #filename='test/Solar33P.xml' #filename='test/WFIP-MISO.xml' #filename='test/WWSIS.xml' self.coad = COAD(filename) # Fix bad api for python 3.2 if not hasattr(self, 'assertItemsEqual'): self.assertItemsEqual = self.assertCountEqual def test_copy(self): oldobj = self.coad['Performance']['Gurobi'] newobj = oldobj.copy() self.assertNotEqual(oldobj.meta['name'], newobj.meta['name']) for (k, v) in oldobj.items(): self.assertEqual(v, newobj[k]) self.coad.list('Performance') newobj = oldobj.copy() self.assertNotEqual(oldobj.meta['name'], newobj.meta['name']) oldobj = self.coad['Model']['Base'] newobj = oldobj.copy('Test Base Model') self.assertIn('Test Base Model', self.coad['Model']) should_contain = [ self.coad['Horizon']['Base'], self.coad['Report']['Base'], self.coad['ST Schedule']['Base'] ] self.assertItemsEqual( should_contain, self.coad['Model']['Test Base Model'].get_children()) self.assertItemsEqual( [self.coad['System']['System']], self.coad['Model']['Test Base Model'].get_parents()) self.assertRaises(Exception, self.coad['Model']['Base'].copy, 'Test Base Model') def test_get_parents(self): should_contain = [ master_coad['System']['System'], master_coad['Model']['Base'] ] self.assertItemsEqual(should_contain, master_coad['Horizon']['Base'].get_parents()) self.assertItemsEqual( [master_coad['Model']['Base']], master_coad['Horizon']['Base'].get_parents('Model')) def test_get_children(self): should_contain = [ self.coad['Horizon']['Base'], self.coad['Report']['Base'], self.coad['ST Schedule']['Base'] ] self.assertItemsEqual(should_contain, self.coad['Model']['Base'].get_children()) self.assertItemsEqual( [self.coad['Horizon']['Base']], self.coad['Model']['Base'].get_children('Horizon')) def test_set_children(self): # Single new child self.coad['Model']['Base'].set_children( self.coad['Performance']['Gurobi']) should_contain = [ self.coad['Horizon']['Base'], self.coad['Report']['Base'], self.coad['ST Schedule']['Base'], self.coad['Performance']['Gurobi'] ] self.assertEqual(should_contain, self.coad['Model']['Base'].get_children()) # Duplicates self.coad['Model']['Base'].set_children( self.coad['Performance']['Gurobi'], replace=False) self.assertEqual( 1, len(self.coad['Model']['Base'].get_children('Performance'))) # TODO: Test multiple new children of different classes that overwrites existing # TODO: Test adding new child once collection functionality is understood # TODO: Add mix of new child classes once collection functionality is understood # Children with multiple collections available filename = 'coad/test/RTS-96.xml' coad = COAD(filename) self.assertRaises(Exception, coad['Node']['101'].set_children, coad['Zone'].meta['class_id']) self.assertEqual( 178, coad['Node']['101'].get_collection_id( coad['Zone'].meta['class_id'], name="Zone")) dzone = coad['Zone'].new("Dummy Zone") coad['Node']['101'].set_children(dzone, name="Zone") def test_get_class(self): g_class = self.coad['Performance']['Gurobi'].get_class() self.assertItemsEqual(self.coad['Performance'], g_class) def test_del(self): # Existing attribute del (self.coad['Model']['Base']['Enabled']) # Make sure the db has been modified fresh_obj = ObjectDict(self.coad, self.coad['Model']['Base'].meta) #print(fresh_obj) self.assertNotIn('Enabled', fresh_obj.keys()) #self.coad.save('master_noenable.xml') def test_get_category_id(self): '''Test get category id for class ''' self.assertEqual("1", self.coad['System'].get_category_id('-')) def test_get_categories(self): '''Test class and object category retrieval ''' self.assertEqual("-", self.coad['Performance'].get_categories()[0]['name']) self.assertEqual("-", self.coad['Performance']['Gurobi'].get_category()) def test_7_400_2(self): '''Test changes related to the 7.400.2 version of master.xml ''' coad = COAD('coad/master_7.400.2.xml') # Test model first, as the horizons will attach themselves to the copied base model oldobj = coad['Model']['Base'] newobj = oldobj.copy('Test Base Model') self.assertIn('Test Base Model', coad['Model']) should_contain = [ coad['Horizon']['Base'], coad['Report']['Base'], coad['ST Schedule']['Base'] ] self.assertItemsEqual(should_contain, coad['Model']['Test Base Model'].get_children()) oldobj = coad['Horizon']['Base'] newobj = oldobj.copy('New Horizon') self.assertNotEqual(oldobj.meta['name'], newobj.meta['name']) for (k, v) in oldobj.items(): self.assertEqual(v, newobj[k]) self.assertEqual(['Base', 'New Horizon'], coad.list('Horizon')) self.assertNotEqual(coad['Horizon']['Base'].meta['GUID'], coad['Horizon']['New Horizon'].meta['GUID']) newobj = oldobj.copy() self.assertNotEqual(oldobj.meta['name'], newobj.meta['name']) def test_blank_elements(self): '''Make sure blank elements are saved properly ''' filename = 'coad/test/118-Bus_with_blanks.xml' pre = COAD(filename) cur = pre.dbcon.execute( "SELECT name FROM category WHERE category_id=49") val = cur.fetchone()[0] self.assertEqual(val, "") pre.save('coad/test/118-Bus_with_blanks_test.xml') post = COAD('coad/test/118-Bus_with_blanks_test.xml') cur = post.dbcon.execute( "SELECT name FROM category WHERE category_id=49") val = cur.fetchone()[0] self.assertEqual(val, "")
def test_set_solver(self): coad = COAD('coad/test/Solar33P.xml') set_solver(coad,'PP1 Xpress-MP') self.assertEqual(coad['Performance']['PP1 Xpress-MP'],coad['Model']['M01 Cost Need 0603'].get_children('Performance')[0])
from coad.COAD import COAD, ObjectDict import unittest # Only load the master once master_coad = COAD('coad/master.xml') class TestCOAD(unittest.TestCase): _multiprocess_can_split_ = False def test_load(self): self.assertEqual(master_coad['Performance']['Gurobi']['SOLVER'], '4') def test_list(self): self.assertEqual(set(['MOSEK', 'CPLEX', 'Xpress-MP', 'Gurobi']), set(master_coad.list('Performance'))) def test_classes(self): expected = [ "System", "Generator", "Fuel", "Fuel Contract", "Emission", "Abatement", "Storage", "Waterway", "Power Station", "Physical Contract", "Purchaser", "Reserve", "Market", "Region", "Zone", "Node", "Line", "MLF", "Transformer", "Phase Shifter", "Interface", "Contingency", "Company", "Financial Contract", "Transmission Right", "Cournot", "RSI", "Constraint", "Condition", "Data File", "Escalator", "Variable", "Timeslice", "Scenario", "Model", "Project", "Horizon", "Report", "LT Plan", "PASA", "MT Schedule", "ST Schedule", "Transmission", "Production", "Competition", "Stochastic", "Performance", "Diagnostic" ] self.assertEqual(expected, list(master_coad.keys()))
def test_save(self): master_coad.save('coad/test/master_save_sqlite.xml') newcoad = COAD('coad/test/master_save_sqlite.xml') self.assertEqual(newcoad['Performance']['Gurobi']['SOLVER'], '4')