Skip to content

Commit

Permalink
#105: Fix existing failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
priscavdsluis committed Jun 28, 2022
1 parent ef24e08 commit 0d2f08e
Showing 1 changed file with 29 additions and 20 deletions.
49 changes: 29 additions & 20 deletions tests/io/test_structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -915,10 +915,6 @@ def default_dambreak_values(self) -> dict:
f1=22.4,
f2=44.2,
ucrit=44.22,
waterlevelupstreamlocationx=1.2,
waterlevelupstreamlocationy=2.3,
waterleveldownstreamlocationx=3.4,
waterleveldownstreamlocationy=4.5,
waterlevelupstreamnodeid="anUpstreamNodeId",
waterleveldownstreamnodeid="aDownstreamNodeId",
)
Expand Down Expand Up @@ -1020,10 +1016,6 @@ def test_given_structure_text_with_num_x_y_coordinates_parses_structure(self):
f1 = 22.4 # Factor f1.
f2 = 44.2 # Factor f2.
uCrit = 44.22 # Critical flow velocity uc for erosion [m/s].
waterLevelUpstreamLocationX = 1.2 # x-coordinate of custom upstream water level point.
waterLevelUpstreamLocationY = 2.3 # y-coordinate of custom upstream water level point.
waterLevelDownstreamLocationX = 3.4 # x-coordinate of custom downstream water level point.
waterLevelDownstreamLocationY = 4.5 # y-coordinate of custom downstream water level point.
waterLevelUpstreamNodeId = anUpstreamNodeId # Node Id of custom upstream water level point.
waterLevelDownstreamNodeId = aDownstreamNodeId # Node Id of custom downstream water level point.
"""
Expand Down Expand Up @@ -1052,6 +1044,10 @@ def test_given_structure_text_with_polylinefile_parses_structure(self):
t0 = 0.0001 # make it a boolean
dambreakLevelsAndWidths = dambreak.tim #used only in algorithm 3
materialtype = 1 #1 clay 2 sand, used only in algorithm 1
waterLevelUpstreamLocationX = 1.2 # x-coordinate of custom upstream water level point.
waterLevelUpstreamLocationY = 2.3 # y-coordinate of custom upstream water level point.
waterLevelDownstreamLocationX = 3.4 # x-coordinate of custom downstream water level point.
waterLevelDownstreamLocationY = 4.5 # y-coordinate of custom downstream water level point.
"""
)

Expand All @@ -1074,6 +1070,12 @@ def test_given_structure_text_with_polylinefile_parses_structure(self):
assert dambreak_obj.t0 == 0.0001
assert dambreak_obj.dambreaklevelsandwidths == Path("dambreak.tim")
assert dambreak_obj.dict()["materialtype"] == "1"
assert dambreak_obj.waterlevelupstreamlocationx == 1.2
assert dambreak_obj.waterlevelupstreamlocationy == 2.3
assert dambreak_obj.waterleveldownstreamlocationx == 3.4
assert dambreak_obj.waterleveldownstreamlocationy == 4.5
assert dambreak_obj.waterlevelupstreamnodeid == None
assert dambreak_obj.waterleveldownstreamnodeid == None

def parse_dambreak_from_text(self, structure_text: str) -> Dambreak:
"""
Expand Down Expand Up @@ -1121,10 +1123,10 @@ def validate_valid_default_dambreak(self, dambreak: Dambreak):
assert dambreak.numcoordinates == 2
assert dambreak.xcoordinates == [4.2, 2.4]
assert dambreak.ycoordinates == [2.4, 4.2]
assert dambreak.waterlevelupstreamlocationx == 1.2
assert dambreak.waterlevelupstreamlocationy == 2.3
assert dambreak.waterleveldownstreamlocationx == 3.4
assert dambreak.waterleveldownstreamlocationy == 4.5
assert dambreak.waterlevelupstreamlocationx == None
assert dambreak.waterlevelupstreamlocationy == None
assert dambreak.waterleveldownstreamlocationx == None
assert dambreak.waterleveldownstreamlocationy == None
assert dambreak.waterlevelupstreamnodeid == "anUpstreamNodeId"
assert dambreak.waterleveldownstreamnodeid == "aDownstreamNodeId"

Expand Down Expand Up @@ -1221,18 +1223,18 @@ class TestCheckLocation:
"dict_values",
[
pytest.param(
dict(numcoordinates=2, xcoordinates=[0, 1], ycoordinates=[2, 3]),
id="With 2 coordinates",
dict(numcoordinates=2, xcoordinates=[0, 1], ycoordinates=[2, 3], waterlevelupstreamnodeid="anUpstreamNodeId", waterleveldownstreamnodeid="aDownstreamNodeId"),
id="With 2 coordinates and waterlevelupstreamnodeid and waterleveldownstreamnodeid",
),
pytest.param(
dict(
numcoordinates=3, xcoordinates=[0, 1, 2], ycoordinates=[2, 3, 4]
numcoordinates=3, xcoordinates=[0, 1, 2], ycoordinates=[2, 3, 4], waterlevelupstreamnodeid="anUpstreamNodeId", waterleveldownstreamlocationx=3.4, waterleveldownstreamlocationy=4.5
),
id="With 3 coordinates",
id="With 3 coordinates and waterlevelupstreamnodeid and waterleveldownstreamlocationx and waterleveldownstreamlocationy",
),
pytest.param(dict(polylinefile=Path()), id="Empty path"),
pytest.param(dict(polylinefile=Path(), waterlevelupstreamlocationx=1.2, waterlevelupstreamlocationy=2.3, waterleveldownstreamnodeid="aDownstreamNodeId"), id="Empty path and waterlevelupstreamlocationx and waterlevelupstreamlocationy and waterleveldownstreamnodeid"),
pytest.param(
dict(polylinefile=Path("aFilePath")), id="Path with file name"
dict(polylinefile=Path("aFilePath"), waterlevelupstreamlocationx=1.2, waterlevelupstreamlocationy=2.3, waterleveldownstreamlocationx=3.4, waterleveldownstreamlocationy=4.5), id="Path with file name and waterlevelupstreamlocationx and waterlevelupstreamlocationy and waterleveldownstreamlocationx and waterleveldownstreamlocationy"
),
],
)
Expand All @@ -1244,17 +1246,24 @@ def test_given_valid_values_returns_values(self, dict_values: dict):
"invalid_values, expected_err",
[
pytest.param(
dict(), DambreakTestCases.check_location_err, id="Empty dict."
dict(
waterlevelupstreamnodeid="anUpstreamNodeId",
waterleveldownstreamnodeid="aDownstreamNodeId"
),
DambreakTestCases.check_location_err,
id="No locations specified"
),
pytest.param(
dict(
numcoordinates=None,
xcoordinates=None,
ycoordinates=None,
polylinefile=None,
waterlevelupstreamnodeid="anUpstreamNodeId",
waterleveldownstreamnodeid="aDownstreamNodeId"
),
DambreakTestCases.check_location_err,
id="Dict with Nones.",
id="Specified locations None",
),
],
)
Expand Down

0 comments on commit 0d2f08e

Please sign in to comment.