diff --git a/src/esdl4tulipa/parser.py b/src/esdl4tulipa/parser.py index 604c1b6..ea5a159 100644 --- a/src/esdl4tulipa/parser.py +++ b/src/esdl4tulipa/parser.py @@ -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 diff --git a/tests/test_parser.py b/tests/test_parser.py index a73cc3a..623cb16 100644 --- a/tests/test_parser.py +++ b/tests/test_parser.py @@ -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(), @@ -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]