Skip to content

Commit

Permalink
#511 resolve issue regarding failing test linked to union of timmodel…
Browse files Browse the repository at this point in the history
… and forcingmodel
  • Loading branch information
MRVermeulenDeltares committed Apr 13, 2023
1 parent 998c104 commit 2573d74
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 0 deletions.
8 changes: 8 additions & 0 deletions hydrolib/core/dflowfm/tim/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,11 @@ def _read_time_series_data(

time, *values = line.split()

TimParser._raise_error_if_values_empty(values, line_index)

timrecord = {"time": time, "data": values}
timeseries.append(timrecord)

return timeseries

@staticmethod
Expand All @@ -92,3 +95,8 @@ def _raise_error_if_contains_comment(line: str, line_index: int) -> None:
raise ValueError(
f"Line {line_index}: comments are only supported at the start of the file, before the time series data."
)

@staticmethod
def _raise_error_if_values_empty(values: List[str], line_index: int) -> None:
if len(values) == 0:
raise ValueError(f"Line {line_index}: Time series cannot be empty.")
23 changes: 23 additions & 0 deletions tests/data/input/tim/bc_file_is_incorrect.bc
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[forcing]
Name = global
Function = timeseries
Time-interpolation = linear
Quantity = time
Unit = minutes since 2006-12-25 0:00:00
Quantity = rainfall_rate
Unit = mm day-1
0.000000 0.0000000
120.000000 0.0000000
240.000000 10.0000000
360.000000 31.6000000
480.000000 100.0000000
600.000000 120.0000000
720.000000 100.0000000
840.000000 70.0000000
960.000000 0.0000000
960.000000 54.0000000
1080.000000 70.0000000
1200.000000 35.0000000
1320.000000 0.0000000
1440.000000 0.0000000
3000.000000 0.0000000
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
10
20
30
31 changes: 31 additions & 0 deletions tests/dflowfm/test_tim.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,3 +314,34 @@ def test_parse_data_throws_exception_error_parsing_tim_file_comments_between_dat

expected_error_msg = f"Line {5}: comments are only supported at the start of the file, before the time series data."
assert expected_error_msg in str(error.value)


@pytest.mark.parametrize(
"input_path",
[
pytest.param(
Path(
test_input_dir
/ "tim"
/ "triple_data_for_timeseries_with_empty_data.tim"
),
id="triple_data_for_timeseries_with_empty_data",
),
pytest.param(
Path(
test_input_dir
/ "tim"
/ "bc_file_is_incorrect.bc"
),
id="bc_file_is_incorrect",
),
],
)
def test_parse_data_throws_exception_error_parsing_tim_file_values_is_empty(
self, input_path
):
with pytest.raises(ValueError) as error:
TimParser.parse(input_path)

expected_error_msg = f"Line {0}: Time series cannot be empty."
assert expected_error_msg in str(error.value)

0 comments on commit 2573d74

Please sign in to comment.