Skip to content

Commit

Permalink
Clean up some assertion-checking exception raising.
Browse files Browse the repository at this point in the history
  • Loading branch information
bje- committed Nov 21, 2024
1 parent f1bcde0 commit 4887e56
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 7 deletions.
2 changes: 1 addition & 1 deletion nemo/generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions nemo/polygons.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 1 addition & 2 deletions nemo/scenarios.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
3 changes: 1 addition & 2 deletions nemo/sim.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 4887e56

Please sign in to comment.