Skip to content

Commit

Permalink
#205: Allow empty friction specification in all crossdef types
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurvd committed Jan 29, 2022
1 parent 769b56a commit 45d3d1a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 32 deletions.
7 changes: 4 additions & 3 deletions hydrolib/core/io/crosssection/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,10 @@ def validate_friction_specification(cls, values):

if frictionid == "":
if frictiontype == "" or frictionvalue == "":
raise ValueError(
f"Cross section is missing any friction specification."
)
# No validation error: frictionid will always default to some
# value (Main/FloodPlain1/FloodPlain2), but will not fill that
# default here, to keep output blank upon serialization.
pass
else:
if frictiontype != "" or frictionvalue != "":
raise ValueError(
Expand Down
57 changes: 28 additions & 29 deletions tests/io/test_crosssection.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,14 @@ def test_create_a_circlecrsdef_with_duplicate_frictionspec(self):

def test_create_a_rectanglecrsdef_without_frictionspec(self):
csdefid = "Prof1"
with pytest.raises(ValidationError) as error:
_ = RectangleCrsDef(
id=csdefid,
width=3.14,
height=2.718,
)
expected_message = f"Cross section is missing any friction specification."

assert expected_message in str(error.value)
crsdef = RectangleCrsDef(
id=csdefid,
width=3.14,
height=2.718,
)
assert crsdef.id == csdefid
assert crsdef.width == 3.14
assert crsdef.height == 2.718

def test_create_a_zwrivercrsdef_with_wrong_list_lengths(self):
csdefid = "Prof1"
Expand All @@ -157,16 +156,16 @@ def test_create_a_zwrivercrsdef_with_wrong_list_lengths(self):

def test_create_a_zwrivercrsdef_without_frictionspec(self):
csdefid = "Prof1"
with pytest.raises(ValidationError) as error:
_ = ZWRiverCrsDef(
id=csdefid,
numlevels=2,
levels=[-2, 3],
flowwidths=[11, 44],
)
expected_message = f"Cross section is missing any friction specification."

assert expected_message in str(error.value)
crsdef = ZWRiverCrsDef(
id=csdefid,
numlevels=2,
levels=[-2, 3],
flowwidths=[11, 44],
)
assert crsdef.id == csdefid
assert crsdef.numlevels == 2
assert crsdef.levels == [-2, 3]
assert crsdef.flowwidths == [11, 44]

def test_create_a_yzcrsdef_with_wrong_list_length_yz(self):
csdefid = "Prof1"
Expand Down Expand Up @@ -206,16 +205,16 @@ def test_create_a_yzcrsdef_with_wrong_list_length_frict(self):

def test_create_a_yzcrsdef_without_frictionspec(self):
csdefid = "Prof1"
with pytest.raises(ValidationError) as error:
_ = YZCrsDef(
id=csdefid,
yzcount=4,
ycoordinates=[-10, -2, 3, 12],
zcoordinates=[1, -4, -4.1, 2],
)
expected_message = f"Cross section is missing any friction specification."

assert expected_message in str(error.value)
crsdef = YZCrsDef(
id=csdefid,
yzcount=4,
ycoordinates=[-10, -2, 3, 12],
zcoordinates=[1, -4, -4.1, 2],
)
assert crsdef.id == csdefid
assert crsdef.yzcount == 4
assert crsdef.ycoordinates == [-10, -2, 3, 12]
assert crsdef.zcoordinates == [1, -4, -4.1, 2]

def test_create_a_xyzcrsdef_with_wrong_list_length_yz(self):
csdefid = "Prof1"
Expand Down

0 comments on commit 45d3d1a

Please sign in to comment.