Skip to content

Commit

Permalink
make deprecation as warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
barneydobson committed Oct 24, 2024
1 parent ad6a71a commit 2ef07ab
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
14 changes: 10 additions & 4 deletions tests/test_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

# import pytest
import unittest
import warnings
from unittest import TestCase

from wsimod.arcs.arcs import Arc
Expand Down Expand Up @@ -399,10 +400,15 @@ def test_river_overrides(self):
self.assertEqual(river.tank.capacity, v)
self.assertEqual(getattr(river, k), v)
# test runtimeerrors
self.assertRaises(RuntimeError, lambda: river.apply_overrides({"area": 75.2}))
self.assertRaises(
RuntimeError, lambda: river.apply_overrides({"capacity": 123})
)
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")
river.apply_overrides({"area": 75.2})
assert "specifying area is depreciated" in str(w[0])

with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")
river.apply_overrides({"capacity": 123})
assert "specifying capacity is depreciated" in str(w[0])

def test_riverreservoir_overrides(self):
riverreservoir = RiverReservoir(name="")
Expand Down
9 changes: 5 additions & 4 deletions wsimod/nodes/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
@author: bdobson Converted to totals on 2022-05-03
"""
import warnings
from math import exp
from typing import Any, Dict

Expand Down Expand Up @@ -507,7 +508,7 @@ def __init__(
# Set parameters
self.depth = depth
if depth != 2:
raise RuntimeError(
warnings.warn(
"warning: the depth parameter is unused by River nodes because it is \
intended for capacity to be unbounded. It may be removed in a future version."
)
Expand Down Expand Up @@ -639,13 +640,13 @@ def apply_overrides(self, overrides=Dict[str, Any]):
setattr(self, param, overrides.pop(param))

if "area" in overrides.keys():
raise RuntimeError(
"ERROR: specifying area is depreciated in overrides \
warnings.warn(
"WARNING: specifying area is depreciated in overrides \
for river, please specify length and width instead"
)
overrides["area"] = self.length * self.width
if "capacity" in overrides.keys():
raise RuntimeError(
warnings.warn(
"ERROR: specifying capacity is depreciated in overrides \
for river, it is always set as unbounded capacity"
)
Expand Down

0 comments on commit 2ef07ab

Please sign in to comment.