Skip to content

Commit

Permalink
Add edge autoincrement test.
Browse files Browse the repository at this point in the history
  • Loading branch information
evetion committed Aug 20, 2024
1 parent 67252fd commit d549ba9
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
2 changes: 1 addition & 1 deletion python/ribasim/ribasim/input_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ def tableschema(cls) -> TableT:
def columns(cls) -> list[str]:
"""Retrieve column names."""
T = cls.tableschema()
return list(T.to_schema().columns.keys()) + [T.to_schema().index.name]
return list(T.to_schema().columns.keys())

def __repr__(self) -> str:
# Make sure not to return just "None", because it gets extremely confusing
Expand Down
29 changes: 28 additions & 1 deletion python/ribasim/tests/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from pydantic import ValidationError
from ribasim import Model, Node, Solver
from ribasim.nodes import basin, pump, user_demand
from ribasim.utils import UsedIDs
from shapely.geometry import Point


Expand Down Expand Up @@ -132,7 +133,33 @@ def test_extra_spatial_columns():
model.edge.add(model.basin[1], model.user_demand[2], foo=1)


def test_autoincrement():
def test_edge_autoincrement(basic):
model = basic
model.edge.df = model.edge.df.iloc[0:0] # clear the table
model.edge._used_edge_ids = UsedIDs() # and reset the counter

model.edge.add(model.basin[1], model.manning_resistance[2], edge_id=20)
assert model.edge.df.index[-1] == 20

model.edge.add(model.manning_resistance[2], model.basin[3])
assert model.edge.df.index[-1] == 21

# Can use any remaining positive integer
model.edge.add(model.basin[3], model.tabulated_rating_curve[8], edge_id=1)
assert model.edge.df.index[-1] == 1

with pytest.raises(
ValueError,
match="Edge IDs have to be unique, but 1 already exists.",
):
model.edge.add(
model.linear_resistance[10],
model.level_boundary[17],
edge_id=1,
)


def test_node_autoincrement():
model = Model(
starttime="2020-01-01",
endtime="2021-01-01",
Expand Down

0 comments on commit d549ba9

Please sign in to comment.