Skip to content

Commit

Permalink
Update some tests. Simplify info() tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
ryan-kipawa committed Sep 27, 2024
1 parent 9a0165f commit cfa49d3
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 212 deletions.
5 changes: 5 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,8 @@ def many_catchments(res1d_catchments):
@pytest.fixture
def structure(res1d_network):
return res1d_network.result_network.structures["119w1"]


@pytest.fixture
def result_quantity(node):
return node.WaterLevel
25 changes: 1 addition & 24 deletions tests/test_epanet_res_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,30 +34,7 @@ def test_quantities(test_file):

def test_info(test_file):
epanet_res = test_file
epanet_res_info = epanet_res._get_info()
epanet_res_info_ref = (
"Start time: 2022-10-13 00:00:00\n"
+ "End time: 2022-10-14 00:00:00\n"
+ "# Timesteps: 25\n"
+ "# Catchments: 0\n"
+ "# Nodes: 11\n"
+ "# Reaches: 13\n"
+ "# Globals: 0\n"
+ "0 - Demand <l/s>\n"
+ "1 - Head <m>\n"
+ "2 - Pressure <m>\n"
+ "3 - WaterQuality <->\n"
+ "4 - Flow <l/s>\n"
+ "5 - Velocity <m/s>\n"
+ "6 - HeadlossPer1000Unit <m>\n"
+ "7 - AvgWaterQuality <->\n"
+ "8 - StatusCode <->\n"
+ "9 - Setting <->\n"
+ "10 - ReactorRate <->\n"
+ "11 - FrictionFactor <->"
)

assert epanet_res_info == epanet_res_info_ref
epanet_res.info()


def test_data_item_dicts(test_file):
Expand Down
17 changes: 1 addition & 16 deletions tests/test_epanet_resx_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,7 @@ def test_quantities(test_file):

def test_info(test_file):
epanet_resx = test_file
epanet_resx_info = epanet_resx._get_info()
epanet_repr_ref = (
"Start time: 2022-10-13 00:00:00\n"
+ "End time: 2022-10-14 00:00:00\n"
+ "# Timesteps: 25\n"
+ "# Catchments: 0\n"
+ "# Nodes: 2\n"
+ "# Reaches: 1\n"
+ "# Globals: 0\n"
+ "0 - Volume <m^3>\n"
+ "1 - Volume Percentage <%>\n"
+ "2 - Pump efficiency <%>\n"
+ "3 - Pump energy costs </kWh>\n"
+ "4 - Pump energy <kW>"
)
assert epanet_resx_info == epanet_repr_ref
epanet_resx.info()


def test_data_item_dicts(test_file):
Expand Down
33 changes: 28 additions & 5 deletions tests/test_network_formatting.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
"""
Tests for the formatting of the result network objects."""
Tests for the formatting of the result network objects.
"""

import pytest

from mikeio1d.result_network import ResultQuantity
from DHI.Mike1D.Generic import IQuantity


def test_location_str_repr_header_line(node, reach, catchment, structure):
Expand Down Expand Up @@ -46,7 +52,7 @@ def test_single_node_html_repr(node):
padding-left: 2em;
}
</style>
<details><summary>Attributes (8)</summary><ul><li>id: 1</li><li>type: Manhole</li><li>xcoord: -687934.6000976562</li><li>ycoord: -1056500.69921875</li><li>ground_level: 197.07000732421875</li><li>bottom_level: 195.0500030517578</li><li>critical_level: inf</li><li>diameter: 1.0</li></ul></details><details><summary>Quantities (1)</summary><ul><li>WaterLevel</li></ul></details>"""
<details><summary>Attributes (8)</summary><ul><li>id: 1</li><li>type: Manhole</li><li>xcoord: -687934.6000976562</li><li>ycoord: -1056500.69921875</li><li>ground_level: 197.07000732421875</li><li>bottom_level: 195.0500030517578</li><li>critical_level: inf</li><li>diameter: 1.0</li></ul></details><details><summary>Quantities (1)</summary><ul><li>Water level (m)</li></ul></details>"""
assert html_repr == expected_html_repr


Expand All @@ -60,7 +66,7 @@ def test_single_catchment_html_repr(catchment):
padding-left: 2em;
}
</style>
<details><summary>Attributes (3)</summary><ul><li>id: 100_16_16</li><li>area: 22800.0</li><li>type: Kinematic Wave</li></ul></details><details><summary>Quantities (5)</summary><ul><li>TotalRunOff</li><li>ActualRainfall</li><li>ZinkLoadRR</li><li>ZinkMassAccumulatedRR</li><li>ZinkRR</li></ul></details>"""
<details><summary>Attributes (3)</summary><ul><li>id: 100_16_16</li><li>area: 22800.0</li><li>type: Kinematic Wave</li></ul></details><details><summary>Quantities (5)</summary><ul><li>Total Runoff (m^3/s)</li><li>Actual Rainfall (m/s)</li><li>Zink, Load, RR (kg/s)</li><li>Zink, Mass, Accumulated, RR (kg)</li><li>Zink, RR (mg/l)</li></ul></details>"""
assert html_repr == expected_html_repr


Expand All @@ -74,7 +80,7 @@ def test_single_reach_html_repr(river_reach):
padding-left: 2em;
}
</style>
<details><summary>Attributes (5)</summary><ul><li>name: river</li><li>length: 2024.2276598819008</li><li>start_chainage: 53100.0</li><li>end_chainage: 55124.2276598819</li><li>n_gridpoints: 94</li></ul></details><details><summary>Quantities (4)</summary><ul><li>WaterLevel</li><li>ManningResistanceNumber</li><li>Discharge</li><li>FlowVelocity</li></ul></details>"""
<details><summary>Attributes (5)</summary><ul><li>name: river</li><li>length: 2024.2276598819008</li><li>start_chainage: 53100.0</li><li>end_chainage: 55124.2276598819</li><li>n_gridpoints: 94</li></ul></details><details><summary>Quantities (4)</summary><ul><li>Water level (m)</li><li>Manning Resistance Number (m^(1/3)/s)</li><li>Discharge (m^3/s)</li><li>Flow velocity (m/s)</li></ul></details>"""
assert html_repr == expected_html_repr


Expand All @@ -88,5 +94,22 @@ def test_single_structure_html_repr(structure):
padding-left: 2em;
}
</style>
<details><summary>Attributes (3)</summary><ul><li>id: 119w1</li><li>type: Weir</li><li>chainage: 0.5</li></ul></details><details><summary>Quantities (1)</summary><ul><li>Discharge</li></ul></details>"""
<details><summary>Attributes (3)</summary><ul><li>id: 119w1</li><li>type: Weir</li><li>chainage: 0.5</li></ul></details><details><summary>Quantities (1)</summary><ul><li>Discharge (m^3/s)</li></ul></details>"""
assert html_repr == expected_html_repr


@pytest.mark.parametrize(
"latex_format, expected_str",
[
(None, "Water level (m)"),
(False, "Water level (m)"),
(True, "Water level ($\\mathrm{m}$)"),
],
)
def test_pretty_quantity_formatting(result_quantity, latex_format, expected_str):
assert isinstance(result_quantity, ResultQuantity)
m1d_quantity = result_quantity.data_item.Quantity
assert isinstance(m1d_quantity, IQuantity)

assert ResultQuantity.prettify_quantity(result_quantity, latex_format) == expected_str
assert ResultQuantity.prettify_quantity(m1d_quantity, latex_format) == expected_str
17 changes: 1 addition & 16 deletions tests/test_res1d_catchments.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,7 @@ def test_quantities(test_file):

def test_info(test_file):
res1d = test_file
res1d_info = res1d._get_info()
res1d_info_ref = (
"Start time: 1994-08-07 16:35:00\n"
+ "End time: 1994-08-07 18:35:00\n"
+ "# Timesteps: 108\n"
+ "# Catchments: 31\n"
+ "# Nodes: 0\n"
+ "# Reaches: 0\n"
+ "# Globals: 0\n"
+ "0 - TotalRunOff <m^3/s>\n"
+ "1 - ActualRainfall <m/s>\n"
+ "2 - ZinkLoadRR <kg/s>\n"
+ "3 - ZinkMassAccumulatedRR <kg>\n"
+ "4 - ZinkRR <mg/l>"
)
assert res1d_info == res1d_info_ref
res1d.info()


def test_data_item_dicts(test_file):
Expand Down
33 changes: 1 addition & 32 deletions tests/test_res1d_lts_chronological.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,38 +43,7 @@ def test_quantities(test_file):

def test_info(test_file):
res1d = test_file
res1d_info = res1d._get_info()
res1d_info_ref = (
"Start time: 1957-01-01 00:00:00\n"
+ "End time: 1963-01-01 00:00:00\n"
+ "# Timesteps: 73\n"
+ "# Catchments: 0\n"
+ "# Nodes: 16\n"
+ "# Reaches: 17\n"
+ "# Globals: 9\n"
+ "0 - DischargeIntegratedMonthly <m^3>\n"
+ "1 - DischargeIntegratedMonthlyCount <()>\n"
+ "2 - DischargeIntegratedMonthlyDuration <h>\n"
+ "3 - Component_1TransportIntegratedMonthly <kg>\n"
+ "4 - Component_1TransportIntegratedMonthlyCount <()>\n"
+ "5 - Component_1TransportIntegratedMonthlyDuration <h>\n"
+ "6 - Component_2TransportIntegratedMonthly <kg>\n"
+ "7 - Component_2TransportIntegratedMonthlyCount <()>\n"
+ "8 - Component_2TransportIntegratedMonthlyDuration <h>\n"
+ "9 - SurchargeIntegratedMonthly <m^3>\n"
+ "10 - SurchargeIntegratedMonthlyCount <()>\n"
+ "11 - SurchargeIntegratedMonthlyDuration <h>\n"
+ "12 - DischargeIntegratedMonthlyOutlets <m^3>\n"
+ "13 - DischargeIntegratedMonthlyWeirs <m^3>\n"
+ "14 - DischargeIntegratedMonthlyTotalOutflow <m^3>\n"
+ "15 - Component_1TransportIntegratedMonthlyTotalEmission <kg>\n"
+ "16 - Component_2TransportIntegratedMonthlyTotalEmission <kg>\n"
+ "17 - Component_1TransportIntegratedMonthlyOutlets <kg>\n"
+ "18 - Component_2TransportIntegratedMonthlyOutlets <kg>\n"
+ "19 - Component_1TransportIntegratedMonthlyWeirs <kg>\n"
+ "20 - Component_2TransportIntegratedMonthlyWeirs <kg>"
)
assert res1d_info == res1d_info_ref
res1d.info()


def test_data_item_dicts(test_file):
Expand Down
36 changes: 1 addition & 35 deletions tests/test_res1d_lts_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,41 +41,7 @@ def test_quantities(test_file):

def test_info(test_file):
res1d = test_file
res1d_info = res1d._get_info()
res1d_info_ref = (
"Start time: 1957-01-01 00:00:00\n"
+ "End time: 1963-01-01 00:00:00\n"
+ "# Timesteps: 10\n"
+ "# Catchments: 0\n"
+ "# Nodes: 16\n"
+ "# Reaches: 17\n"
+ "# Globals: 0\n"
+ "0 - WaterLevelMaximum <m>\n"
+ "1 - WaterLevelMaximumTime <sec>\n"
+ "2 - DischargeIntegrated <m^3>\n"
+ "3 - DischargeIntegratedTime <sec>\n"
+ "4 - DischargeMaximum <m^3/s>\n"
+ "5 - DischargeMaximumTime <sec>\n"
+ "6 - DischargeDuration <h>\n"
+ "7 - DischargeDurationTime <sec>\n"
+ "8 - Component_1Maximum <kg/m^3>\n"
+ "9 - Component_1MaximumTime <sec>\n"
+ "10 - Component_2Maximum <kg/m^3>\n"
+ "11 - Component_2MaximumTime <sec>\n"
+ "12 - Component_1TransportIntegrated <kg>\n"
+ "13 - Component_1TransportIntegratedTime <sec>\n"
+ "14 - Component_2TransportIntegrated <kg>\n"
+ "15 - Component_2TransportIntegratedTime <sec>\n"
+ "16 - SurchargeMaximum <m^3/s>\n"
+ "17 - SurchargeMaximumTime <sec>\n"
+ "18 - SurchargeIntegrated <m^3>\n"
+ "19 - SurchargeIntegratedTime <sec>\n"
+ "20 - SurchargeDuration <h>\n"
+ "21 - SurchargeDurationTime <sec>\n"
+ "22 - FlowVelocityMaximum <m/s>\n"
+ "23 - FlowVelocityMaximumTime <sec>"
)
assert res1d_info == res1d_info_ref
res1d.info()


def test_data_item_dicts(test_file):
Expand Down
14 changes: 1 addition & 13 deletions tests/test_res1d_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,7 @@ def test_quantities(test_file):

def test_info(test_file):
res1d = test_file
res1d_info = res1d._get_info()
res1d_info_ref = (
"Start time: 1994-08-07 16:35:00\n"
+ "End time: 1994-08-07 18:35:00\n"
+ "# Timesteps: 110\n"
+ "# Catchments: 0\n"
+ "# Nodes: 119\n"
+ "# Reaches: 118\n"
+ "# Globals: 0\n"
+ "0 - WaterLevel <m>\n"
+ "1 - Discharge <m^3/s>"
)
assert res1d_info == res1d_info_ref
res1d.info()


def test_data_item_dicts(test_file):
Expand Down
25 changes: 1 addition & 24 deletions tests/test_res1d_network_river.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,30 +37,7 @@ def test_quantities(test_file):

def test_repr(test_file):
res1d = test_file
res1d_info = res1d._get_info()
res1d_info_ref = (
"Start time: 2000-02-18 00:06:00\n"
+ "End time: 2000-02-18 12:06:00\n"
+ "# Timesteps: 73\n"
+ "# Catchments: 0\n"
+ "# Nodes: 18\n"
+ "# Reaches: 18\n"
+ "# Globals: 4\n"
+ "0 - WaterLevel <m>\n"
+ "1 - Discharge <m^3/s>\n"
+ "2 - ManningResistanceNumber <m^(1/3)/s>\n"
+ "3 - FlowVelocity <m/s>\n"
+ "4 - FlowVelocityInStructure <m/s>\n"
+ "5 - FlowAreaInStructure <m^2>\n"
+ "6 - DischargeInStructure <m^3/s>\n"
+ "7 - ControlStrategyId <Integer>\n"
+ "8 - GateLevel <m>\n"
+ "9 - Variable:TwoTimeSensorGateLevel <->\n"
+ "10 - Water level:Sensor:s.h.river53745.34 <m>\n"
+ "11 - Gate level:Sensor:SensorGateLevel <m>\n"
+ "12 - Discharge:Sensor:SensorGauge1 <m^3/s>"
)
assert res1d_info == res1d_info_ref
res1d.info()


def test_data_item_dicts(test_file):
Expand Down
48 changes: 1 addition & 47 deletions tests/test_swmm_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,53 +35,7 @@ def test_quantities(test_file):

def test_info(test_file):
swmm_out = test_file
swmm_out_info = swmm_out._get_info()
swmm_out_info_ref = (
"Start time: 1998-01-01 01:00:00.001000\n"
+ "End time: 1998-01-02 12:00:00.001000\n"
+ "# Timesteps: 36\n"
+ "# Catchments: 8\n"
+ "# Nodes: 14\n"
+ "# Reaches: 13\n"
+ "# Globals: 15\n"
+ "0 - SWMM_NODE_DEPTH <ft>\n"
+ "1 - SWMM_NODE_HEAD <ft>\n"
+ "2 - SWMM_NODE_VOLUME <ft^3>\n"
+ "3 - SWMM_NODE_LATFLOW <ft^3/s>\n"
+ "4 - SWMM_NODE_INFLOW <ft^3/s>\n"
+ "5 - SWMM_NODE_OVERFLOW <ft^3/s>\n"
+ "6 - SWMM_NODE_QUAL <mu-g/l>\n"
+ "7 - SWMM_LINK_FLOW <ft^3/s>\n"
+ "8 - SWMM_LINK_DEPTH <ft>\n"
+ "9 - SWMM_LINK_VELOCITY <ft/s>\n"
+ "10 - SWMM_LINK_Froude_Number <()>\n"
+ "11 - SWMM_LINK_CAPACITY <()>\n"
+ "12 - SWMM_LINK_QUAL <mu-g/l>\n"
+ "13 - SWMM_SUBCATCH_RAINFALL <in/h>\n"
+ "14 - SWMM_SUBCATCH_SNOWDEPTH <in>\n"
+ "15 - SWMM_SUBCATCH_EVAP <in>\n"
+ "16 - SWMM_SUBCATCH_INFIL <in/h>\n"
+ "17 - SWMM_SUBCATCH_RUNOFF <ft^3/s>\n"
+ "18 - SWMM_SUBCATCH_GW_FLOW <ft^3/s>\n"
+ "19 - SWMM_SUBCATCH_GW_ELEV <ft>\n"
+ "20 - SWMM_SUBCATCH_SOIL_MOIST <()>\n"
+ "21 - SWMM_SUBCATCH_WASHOFF <mu-g/l>\n"
+ "22 - SWMM_SYS_TEMPERATURE <deg F>\n"
+ "23 - SWMM_SYS_RAINFALL <in/h>\n"
+ "24 - SWMM_SYS_SNOWDEPTH <in>\n"
+ "25 - SWMM_SYS_INFIL <in/h>\n"
+ "26 - SWMM_SYS_RUNOFF <ft^3/s>\n"
+ "27 - SWMM_SYS_DWFLOW <ft^3/s>\n"
+ "28 - SWMM_SYS_GWFLOW <ft^3/s>\n"
+ "29 - SWMM_SYS_INFLOW <ft^3/s>\n"
+ "30 - SWMM_SYS_EXFLOW <ft^3/s>\n"
+ "31 - SWMM_SYS_FLOODING <ft^3/s>\n"
+ "32 - SWMM_SYS_OUTFLOW <ft^3/s>\n"
+ "33 - SWMM_SYS_STORAGE <ft^3>\n"
+ "34 - SWMM_SYS_EVAP <->\n"
+ "35 - SWMM_SYS_PET <->"
)
assert swmm_out_info == swmm_out_info_ref
swmm_out.info()


def test_data_item_dicts(test_file):
Expand Down

0 comments on commit cfa49d3

Please sign in to comment.