def test_empty_init(): a = Amply() a.load_string("param T := 4;") assert a.T == 4
def test_load_string(): a = Amply("param T:= 4; param X{foo};") a.load_string("param S := 6; param X := 1 2;") assert a.T == 4 assert a.S == 6 assert a.X[1] == 2
def test_convert_amply_to_dataframe(): config = { 'VariableCost': { 'type': 'param', 'indices': ['REGION', 'TECHNOLOGY', 'MODE_OF_OPERATION', 'YEAR'], 'dtype': 'float', 'default': 0 }, 'REGION': { 'type': 'set', 'dtype': 'str' }, 'YEAR': { 'dtype': 'int', 'type': 'set' }, 'MODE_OF_OPERATION': { 'dtype': 'int', 'type': 'set' }, 'TECHNOLOGY': { 'dtype': 'str', 'type': 'set' } } amply = Amply("""set REGION; set REGION := SIMPLICITY; set TECHNOLOGY; set TECHNOLOGY := ETHPLANT GAS_EXTRACTION; set MODE_OF_OPERATION; set MODE_OF_OPERATION := 1 2; set YEAR; set YEAR := 2014;""") amply.load_string( "param VariableCost {REGION,TECHNOLOGY,MODE_OF_OPERATION,YEAR};") # amply.load_string("""param default 0 : VariableCost := # SIMPLICITY ETHPLANT 1 2014 2.89 # SIMPLICITY ETHPLANT 2 2014 999999.0 # SIMPLICITY GAS_EXTRACTION 1 2014 7.5 # SIMPLICITY GAS_EXTRACTION 2 2014 999999.0""") amply.load_string(""" param VariableCost default 0.0001 := [SIMPLICITY,ETHPLANT,*,*]: 2014 := 1 2.89 2 999999.0 [SIMPLICITY,GAS_EXTRACTION,*,*]: 2014 := 1 7.5 2 999999.0;""") actual = convert_amply_to_dataframe(amply, config) expected = pd.DataFrame( data=[['SIMPLICITY', 'ETHPLANT', 1, 2014, 2.89], ['SIMPLICITY', 'ETHPLANT', 2, 2014, 999999.0], ['SIMPLICITY', 'GAS_EXTRACTION', 1, 2014, 7.5], ['SIMPLICITY', 'GAS_EXTRACTION', 2, 2014, 999999.0]], columns=['REGION', 'TECHNOLOGY', 'MODE_OF_OPERATION', 'YEAR', 'VALUE']) pd.testing.assert_frame_equal(actual['VariableCost'], expected)