From 4887e56be28970b210ffc84bdad06f27a569a6a2 Mon Sep 17 00:00:00 2001 From: Ben Elliston Date: Thu, 21 Nov 2024 22:16:16 +1100 Subject: [PATCH] Clean up some assertion-checking exception raising. --- nemo/generators.py | 2 +- nemo/polygons.py | 4 ++-- nemo/scenarios.py | 3 +-- nemo/sim.py | 3 +-- 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/nemo/generators.py b/nemo/generators.py index 3968ef94..0fe6afe6 100644 --- a/nemo/generators.py +++ b/nemo/generators.py @@ -184,7 +184,7 @@ def charge_capacity(self, gen, hour): except KeyError: return gen.capacity if result < 0 and isclose(result, 0, abs_tol=1e-6): - result = 0 + result = 0 # pragma: no cover if result < 0: raise AssertionError return result diff --git a/nemo/polygons.py b/nemo/polygons.py index 7eb89150..60033759 100644 --- a/nemo/polygons.py +++ b/nemo/polygons.py @@ -586,7 +586,7 @@ def dist(poly1, poly2): (33, 39, 500), (39, 33, 1300), (34, 39, 1000), (39, 34, 1300), (39, 38, 2500), (38, 39, 6400), (38, 41, 450), (41, 38, 600)]: if p1 not in list(net[p2].keys()): - raise ValueError(p2, p1) + raise AssertionError(p2, p1) if p2 not in list(net[p1].keys()): - raise ValueError(p1, p2) + raise AssertionError(p1, p2) existing_net[p1, p2] = limit diff --git a/nemo/scenarios.py b/nemo/scenarios.py index 45ba3a7e..e7935f23 100644 --- a/nemo/scenarios.py +++ b/nemo/scenarios.py @@ -141,8 +141,7 @@ def re100(context): elif g in [Biofuel, PV1Axis, CentralReceiver, Wind]: result += _every_poly(g) else: - msg = 'unhandled generator type' - raise UnreachableError(msg) + raise UnreachableError context.generators = result diff --git a/nemo/sim.py b/nemo/sim.py index 017ab827..e0a76f3b 100644 --- a/nemo/sim.py +++ b/nemo/sim.py @@ -75,8 +75,7 @@ def _store_spills(context, hour, gen, generators, spl): if spl < 0 and isclose(spl, 0, abs_tol=1e-6): spl = 0 if spl < 0: - msg = 'negative spill' - raise RuntimeWarning(msg) + raise AssertionError(spl) # energy stored <= energy transferred, according to store's RTE logging.info('STORE: %s -> %s (%.1f)', gen, other, stored)