Skip to content

Commit aaf3315

Browse files
committed
refactor tests
1 parent eab44be commit aaf3315

File tree

1 file changed

+30
-46
lines changed

1 file changed

+30
-46
lines changed

tests/tools/test_converters_source_sink.py

Lines changed: 30 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import pytest
55

6+
from hydrolib.core.dflowfm.ext.models import SourceSink
67
from hydrolib.core.dflowfm.extold.models import ExtOldForcing, ExtOldQuantity
78
from hydrolib.tools.ext_old_to_new.converters import SourceSinkConverter
89

@@ -156,6 +157,33 @@ def test_parse_tim_model_with_mdu(
156157
assert data == expected_data
157158

158159

160+
def compare_data(new_quantity_block: SourceSink):
161+
# check the converted bc_forcing
162+
bc_forcing = new_quantity_block.bc_forcing
163+
forcing_bases = bc_forcing.forcing
164+
assert [forcing_bases[i].quantityunitpair[1].quantity for i in range(4)] == [
165+
"discharge",
166+
"salinitydelta",
167+
"temperaturedelta",
168+
"initialtracer_anyname",
169+
]
170+
assert [forcing_bases[i].quantityunitpair[1].unit for i in range(4)] == [
171+
"m3/s",
172+
"ppt",
173+
"C",
174+
"Unknown",
175+
]
176+
# check the values of the data block
177+
# initialtracer_anyname
178+
assert forcing_bases[3].datablock[1] == [4.0, 4.0, 4.0, 4.0, 4.0]
179+
# temperature
180+
assert forcing_bases[2].datablock[1] == [3.0, 3.0, 3.0, 3.0, 3.0]
181+
# salinity
182+
assert forcing_bases[1].datablock[1] == [2.0, 2.0, 2.0, 2.0, 2.0]
183+
# discharge
184+
assert forcing_bases[0].datablock[1] == [1.0, 1.0, 1.0, 1.0, 1.0]
185+
186+
159187
class TestSourceSinkConverter:
160188

161189
def test_default(self):
@@ -238,29 +266,7 @@ def test_default(self):
238266
assert new_quantity_block.zsource == [-3]
239267

240268
# check the converted bc_forcing
241-
bc_forcing = new_quantity_block.bc_forcing
242-
forcing_bases = bc_forcing.forcing
243-
assert [forcing_bases[i].quantityunitpair[1].quantity for i in range(4)] == [
244-
"discharge",
245-
"salinitydelta",
246-
"temperaturedelta",
247-
"initialtracer_anyname",
248-
]
249-
assert [forcing_bases[i].quantityunitpair[1].unit for i in range(4)] == [
250-
"m3/s",
251-
"ppt",
252-
"C",
253-
"Unknown",
254-
]
255-
# check the values of the data block
256-
# initialtracer_anyname
257-
assert forcing_bases[3].datablock[1] == [4.0, 4.0, 4.0, 4.0, 4.0]
258-
# temperature
259-
assert forcing_bases[2].datablock[1] == [3.0, 3.0, 3.0, 3.0, 3.0]
260-
# salinity
261-
assert forcing_bases[1].datablock[1] == [2.0, 2.0, 2.0, 2.0, 2.0]
262-
# discharge
263-
assert forcing_bases[0].datablock[1] == [1.0, 1.0, 1.0, 1.0, 1.0]
269+
compare_data(new_quantity_block)
264270

265271
def test_4_5_columns_polyline(self):
266272
"""
@@ -319,29 +325,7 @@ def test_4_5_columns_polyline(self):
319325
assert new_quantity_block.zsource == [-3, -2.90]
320326

321327
# check the converted bc_forcing
322-
bc_forcing = new_quantity_block.bc_forcing
323-
forcing_bases = bc_forcing.forcing
324-
assert [forcing_bases[i].quantityunitpair[1].quantity for i in range(4)] == [
325-
"discharge",
326-
"salinitydelta",
327-
"temperaturedelta",
328-
"initialtracer_anyname",
329-
]
330-
assert [forcing_bases[i].quantityunitpair[1].unit for i in range(4)] == [
331-
"m3/s",
332-
"ppt",
333-
"C",
334-
"Unknown",
335-
]
336-
# check the values of the data block
337-
# initialtracer_anyname
338-
assert forcing_bases[3].datablock[1] == [4.0, 4.0, 4.0, 4.0, 4.0]
339-
# temperature
340-
assert forcing_bases[2].datablock[1] == [3.0, 3.0, 3.0, 3.0, 3.0]
341-
# salinity
342-
assert forcing_bases[1].datablock[1] == [2.0, 2.0, 2.0, 2.0, 2.0]
343-
# discharge
344-
assert forcing_bases[0].datablock[1] == [1.0, 1.0, 1.0, 1.0, 1.0]
328+
compare_data(new_quantity_block)
345329

346330
def test_no_temperature_no_salinity(self):
347331
"""

0 commit comments

Comments
 (0)