Skip to content

Commit

Permalink
Merge branch 'fix/678_Locationtype_should_not_be_written_for_crosssec…
Browse files Browse the repository at this point in the history
…tions' of https://github.com/Deltares/HYDROLIB-core into fix/678_Locationtype_should_not_be_written_for_crosssections
  • Loading branch information
tim-vd-aardweg committed Jul 8, 2024
2 parents 5c17777 + 9feae77 commit b709e75
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 14 deletions.
4 changes: 3 additions & 1 deletion hydrolib/core/dflowfm/crosssection/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,9 @@ def validate_that_location_specification_is_correct(cls, values: Dict) -> Dict:
return validate_location_specification(
values,
config=LocationValidationConfiguration(
validate_node=False, validate_num_coordinates=False, validate_location_type=False
validate_node=False,
validate_num_coordinates=False,
validate_location_type=False,
),
fields=LocationValidationFieldNames(x_coordinates="x", y_coordinates="y"),
)
Expand Down
4 changes: 3 additions & 1 deletion hydrolib/core/dflowfm/obscrosssection/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ def validate_that_location_specification_is_correct(cls, values: Dict) -> Dict:
return validate_location_specification(
values,
config=LocationValidationConfiguration(
validate_node=False, minimum_num_coordinates=2, validate_location_type=False
validate_node=False,
minimum_num_coordinates=2,
validate_location_type=False,
),
)

Expand Down
36 changes: 24 additions & 12 deletions tests/dflowfm/ini/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ def test_default(self):
assert config.minimum_num_coordinates == 0



class TestLocationValidationFieldNames:
def test_default(self):
fields = LocationValidationFieldNames()
Expand Down Expand Up @@ -212,32 +211,45 @@ def test_correct_1d_fields_locationtype_is_added(
)
assert validated_values == expected_values

@pytest.mark.parametrize("values",
@pytest.mark.parametrize(
"values",
[
pytest.param({"nodeid": "some_nodeid"}, id="nodeId"),
pytest.param({"branchid": "some_branchid", "chainage": 123}, id="branch specification"),
]
pytest.param(
{"branchid": "some_branchid", "chainage": 123},
id="branch specification",
),
],
)
def test_validate_location_type_false_does_not_add_location_type(self, values: dict):
def test_validate_location_type_false_does_not_add_location_type(
self, values: dict
):
config = LocationValidationConfiguration(validate_location_type=False)
validated_values = validate_location_specification(values, config)

assert validated_values == values

@pytest.mark.parametrize("values",
[
pytest.param({"nodeid": "some_nodeid"}, id="nodeId"),
pytest.param({"branchid": "some_branchid", "chainage": 123}, id="branch specification"),
]
)
def test_validate_location_type_false_does_not_validate_location_type(self, values: dict):
@pytest.mark.parametrize(
"values",
[
pytest.param({"nodeid": "some_nodeid"}, id="nodeId"),
pytest.param(
{"branchid": "some_branchid", "chainage": 123},
id="branch specification",
),
],
)
def test_validate_location_type_false_does_not_validate_location_type(
self, values: dict
):
config = LocationValidationConfiguration(validate_location_type=False)
values["locationtype"] = "This is an invalid location type..."

validated_values = validate_location_specification(values, config)

assert validated_values == values


class TestGetKeyRenamingRootValidator:
class DummyModel(BaseModel):
"""Dummy model to test the validation of the location specification."""
Expand Down
1 change: 1 addition & 0 deletions tests/dflowfm/test_crosssection.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
ZWRiverCrsDef,
)
from hydrolib.core.dflowfm.friction.models import FrictionType

from ..utils import (
assert_files_equal,
test_data_dir,
Expand Down

0 comments on commit b709e75

Please sign in to comment.