Skip to content

Commit

Permalink
parser.py: more robust asset kind detection
Browse files Browse the repository at this point in the history
  • Loading branch information
suvayu committed Jul 22, 2024
1 parent 2f69996 commit 94610de
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/esdl4tulipa/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,11 @@ def kinds(*assets: esdl.EnergyAsset, unique=True) -> list[str] | set[str]:
if ks == {"energynetwork", "transport"}:
res.append("energynetwork")
else:
raise RuntimeError(f"{a}: unexpected asset type {ks}")
raise RuntimeError(f"{a}: ambiguous asset type {ks}")
else:
res.extend(ks)
if len(res) == 0:
raise ValueError(f"{assets}: unknown asset")
return set(res) if unique else res


Expand Down
10 changes: 10 additions & 0 deletions tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ def test_asset_kinds(edges):
assert inferred == _kinds


def test_unknown_asset_kinds():
with pytest.raises(ValueError, match="unknown asset"):
kinds(esdl.BuildingUnit())


def test_batched():
seq = [
esdl.Pipe(),
Expand Down Expand Up @@ -159,6 +164,11 @@ def test_edge(empty_edges):
)


def test_edge_error():
with pytest.raises(ValueError, match="uncharted territory"):
edge(esdl.GasProducer(), esdl.GasNetwork(), esdl.GasNetwork(), esdl.GasDemand())


def test_find_edges(edges):
_, *gns = edges[0]
_, *expect = edges[1]
Expand Down

0 comments on commit 94610de

Please sign in to comment.