def test_write_and_read(tmp_path): filepath = tmp_path / 'test.gdx' with GdxFile(filepath, mode='w') as gdx: gdx['set1'] = GAMSSet(SET1, expl_text=SET1_TEXT) gdx['set2'] = GAMSSet(SET2, SET2_DOMAIN, expl_text=SET1_TEXT) gdx['scalar'] = GAMSScalar(CONSTANT) gdx['par1'] = GAMSParameter(PAR1, domain=PAR1_DOMAIN, expl_text=PAR1_TEXT) gdx['par2'] = GAMSParameter(PAR2, domain=PAR2_DOMAIN, expl_text=PAR2_TEXT) gdx['par3'] = GAMSParameter(PAR3) with GdxFile(filepath, mode='r') as gdx: assert float(gdx['scalar']) == CONSTANT assert compare_elements(gdx, 'set1', SET1) assert compare_elements(gdx, 'set2', SET2) assert compare_values(gdx, 'par1', PAR1) assert compare_values(gdx, 'par2', PAR2)
def test_multi_index(self): ts = pd.Series(PAR2) assert ts.to_dict() == dict(GAMSParameter(ts))
def test_series(self): ts = pd.Series(PAR1) assert ts.to_dict() == dict(GAMSParameter(ts))
def test_parameter_keys(): par = GAMSParameter(PAR1) assert set(par.keys()) == set(PAR1.keys())
def test_create_parameter(): par = GAMSParameter(PAR1, expl_text=PAR1_TEXT) assert par.expl_text == PAR1_TEXT
def test_empty_parameter(): empty_par = GAMSParameter(dict()) assert not dict(empty_par)
def test_parameter_to_dict(): par = GAMSParameter(PAR1) assert dict(par) == PAR1
def test_write_empty(tmp_path): filepath = tmp_path / 'test.gdx' with GdxFile(filepath, mode='w') as gdx: gdx['set1'] = GAMSSet(list()) gdx['par1'] = GAMSParameter(dict())
def test_multidim_parameter_values(): par = GAMSParameter(PAR2) assert set(par.values()) == set(PAR2.values())
def test_multidim_parameter_keys(): par = GAMSParameter(PAR2) assert set(par.keys()) == set(PAR2.keys())
def test_create_multidim_parameter(): par = GAMSParameter(PAR2) assert par.dimension == 2
def test_parameter_values_get(): par = GAMSParameter(PAR1) key = list(PAR1.keys())[0] assert par[key] == PAR1[key]
def test_parameter_values(): par = GAMSParameter(PAR1) assert set(par.values()) == set(PAR1.values())
def test_write_series(self, tmp_path): filepath = tmp_path / 'test.gdx' ts = pd.Series(PAR1) with GdxFile(filepath, mode='w') as gdx: gdx['ts'] = GAMSParameter(ts)
def test_series_from_parameter(self): ts = pd.Series(PAR1) par = GAMSParameter(PAR1) assert par.to_pandas().equals(ts)
def test_series_name(self): par = GAMSParameter(PAR1, expl_text=PAR1_TEXT) assert par.to_pandas().name == PAR1_TEXT
def test_multidim_parameter_values_get(): par = GAMSParameter(PAR2) key = list(PAR2.keys())[0] assert par[key] == PAR2[key]