From 2f69996d1a5f40fca9abd9190f3a095eb0d7b95f Mon Sep 17 00:00:00 2001 From: Suvayu Ali Date: Mon, 22 Jul 2024 16:06:30 +0200 Subject: [PATCH] tests: integration tests for the esdl parser --- tests/data/esdl/Tiny.esdl | 65 + tests/data/esdl/eye_simulation.esdl | 3943 +++++++++++++++++++++ tests/data/esdl/mesido.esdl | 375 ++ tests/data/esdl/vehicle_charging_etc.esdl | 144 + tests/test_parser.py | 36 +- 5 files changed, 4558 insertions(+), 5 deletions(-) create mode 100644 tests/data/esdl/Tiny.esdl create mode 100644 tests/data/esdl/eye_simulation.esdl create mode 100644 tests/data/esdl/mesido.esdl create mode 100644 tests/data/esdl/vehicle_charging_etc.esdl diff --git a/tests/data/esdl/Tiny.esdl b/tests/data/esdl/Tiny.esdl new file mode 100644 index 0000000..a67b54f --- /dev/null +++ b/tests/data/esdl/Tiny.esdl @@ -0,0 +1,65 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/data/esdl/eye_simulation.esdl b/tests/data/esdl/eye_simulation.esdl new file mode 100644 index 0000000..b705702 --- /dev/null +++ b/tests/data/esdl/eye_simulation.esdl @@ -0,0 +1,3943 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/data/esdl/mesido.esdl b/tests/data/esdl/mesido.esdl new file mode 100644 index 0000000..8ea28e6 --- /dev/null +++ b/tests/data/esdl/mesido.esdl @@ -0,0 +1,375 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/data/esdl/vehicle_charging_etc.esdl b/tests/data/esdl/vehicle_charging_etc.esdl new file mode 100644 index 0000000..54015cd --- /dev/null +++ b/tests/data/esdl/vehicle_charging_etc.esdl @@ -0,0 +1,144 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/test_parser.py b/tests/test_parser.py index 697ae75..a73cc3a 100644 --- a/tests/test_parser.py +++ b/tests/test_parser.py @@ -122,7 +122,7 @@ def test_merge_assets_err(edges): a2.lifetime = 20 hdr = f"{a1.name} != {a2.name}" body = f"lifetime.+{a1.lifetime}.+{a2.lifetime}" - with pytest.raises(ValueError, match=f"{hdr}[\s\S]+{body}"): + with pytest.raises(ValueError, match=rf"{hdr}[\s\S]+{body}"): assert merge_assets(a1, a2) @@ -173,6 +173,7 @@ def test_find_edges(edges): ) +## integration tests def test_parse_graph(): # TODO: test more meaningful things ensys = debug("tests/data/esdl/norse-mythology-good.esdl") @@ -181,8 +182,33 @@ def test_parse_graph(): assert len(assets) < len(assets_all) -def test_load(): +@pytest.mark.parametrize( + "fname, nflows, nassets", + [ + ("Tiny.esdl", 4, 5), + ("norse-mythology-good.esdl", 35, 29), + ("vehicle_charging_etc.esdl", 13, 12), + ], +) +def test_load(fname, nflows, nassets): # TODO: test more meaningful things - flows, assets = load("tests/data/esdl/norse-mythology-good.esdl") - assert len(flows) == 35 - assert len(assets) == 29 + flows, assets = load(f"tests/data/esdl/{fname}") + assert len(flows) == nflows + assert len(assets) == nassets + + +@pytest.mark.parametrize( + "fname, exc, msg", + [ + ( + "norse-mythology-bad.esdl", + ValueError, + r"mismatching assets.+[\s\S]+.+_cost.+[\s\S]+.+_cost", + ), + ("eye_simulation.esdl", ValueError, "unsupported node"), + ("mesido.esdl", ValueError, r"why am I here.+depth"), + ], +) +def test_load_errors(fname, exc, msg): + with pytest.raises(exc, match=msg): + load(f"tests/data/esdl/{fname}")