def test_create_set_dimension(): s = GAMSSet(SET2) assert s.dimension == 2
def test_set_with_associated_texts(): s = GAMSSet(SET1, assoc_texts=SET1_ASSOC_TEXTS) assert s.assoc_texts == SET1_ASSOC_TEXTS
def test_set_with_associated_texts_fail(): with pytest.raises(ValueError): GAMSSet(SET1, assoc_texts=['alpha'])
def test_create_set_with_domain(): domain = ['super'] s = GAMSSet(SET1, domain) assert s.domain == domain
def test_create_set_expl_text(): s = GAMSSet(SET1, expl_text=SET1_TEXT) assert s.expl_text == SET1_TEXT
def test_try_write_when_reading(example_gdx): with pytest.raises(IOError): example_gdx['set1'] = GAMSSet(SET1, expl_text=SET1_TEXT)
def test_create_set_without_domain(): s = GAMSSet(SET1) assert s.domain is None
def test_create_set(): s = GAMSSet(SET1) assert s.elements == SET1
def test_set_as_list(): s = GAMSSet(SET1) assert list(s) == SET1
def test_interpret_dimensiom_from_domain(): domain = ['set1', 'set1'] empty_set = GAMSSet(list(), domain=domain) assert empty_set.dimension == len(domain)
def test_empty_symbol_with_domain(): domain = ['set1', 'set1'] empty_set = GAMSSet(list(), domain=domain) assert empty_set.domain == domain
def test_empty_set(): empty_set = GAMSSet(list()) assert not list(empty_set)
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_write_set_with_domain(tmp_path): filepath = tmp_path / 'test.gdx' with GdxFile(filepath, mode='w') as gdx: gdx['set2'] = GAMSSet(SET2, SET2_DOMAIN, expl_text=SET1_TEXT) with GdxFile(filepath, mode='r') as gdx: assert gdx['set2'].domain == SET2_DOMAIN
def test_multidim_set_length(): s = GAMSSet(SET2) assert len(s) == len(SET2)
def test_set_length(): s = GAMSSet(SET1) assert len(s) == len(SET1)
def test_create_set_multidim(): s = GAMSSet(SET2) assert s.elements == SET2
def test_write_same_again(tmp_path): filepath = tmp_path / 'test.gdx' with GdxFile(filepath, mode='w') as gdx: gdx['set1'] = GAMSSet(SET1, expl_text=SET1_TEXT) with pytest.raises(NotImplementedError): gdx['set1'] = GAMSSet(SET1, expl_text=SET1_TEXT)