diff --git a/tests/conftest.py b/tests/conftest.py index 9bf453b4..e1bde992 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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 diff --git a/tests/test_epanet_res_network.py b/tests/test_epanet_res_network.py index dfa5400f..16d12f33 100644 --- a/tests/test_epanet_res_network.py +++ b/tests/test_epanet_res_network.py @@ -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 \n" - + "1 - Head \n" - + "2 - Pressure \n" - + "3 - WaterQuality <->\n" - + "4 - Flow \n" - + "5 - Velocity \n" - + "6 - HeadlossPer1000Unit \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): diff --git a/tests/test_epanet_resx_network.py b/tests/test_epanet_resx_network.py index 0775d598..cf80e39e 100644 --- a/tests/test_epanet_resx_network.py +++ b/tests/test_epanet_resx_network.py @@ -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 \n" - + "1 - Volume Percentage <%>\n" - + "2 - Pump efficiency <%>\n" - + "3 - Pump energy costs \n" - + "4 - Pump energy " - ) - assert epanet_resx_info == epanet_repr_ref + epanet_resx.info() def test_data_item_dicts(test_file): diff --git a/tests/test_network_formatting.py b/tests/test_network_formatting.py index 05f38cc2..d8a54f45 100644 --- a/tests/test_network_formatting.py +++ b/tests/test_network_formatting.py @@ -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): @@ -46,7 +52,7 @@ def test_single_node_html_repr(node): padding-left: 2em; } -
Attributes (8)
  • id: 1
  • type: Manhole
  • xcoord: -687934.6000976562
  • ycoord: -1056500.69921875
  • ground_level: 197.07000732421875
  • bottom_level: 195.0500030517578
  • critical_level: inf
  • diameter: 1.0
Quantities (1)
  • WaterLevel
""" +
Attributes (8)
  • id: 1
  • type: Manhole
  • xcoord: -687934.6000976562
  • ycoord: -1056500.69921875
  • ground_level: 197.07000732421875
  • bottom_level: 195.0500030517578
  • critical_level: inf
  • diameter: 1.0
Quantities (1)
  • Water level (m)
""" assert html_repr == expected_html_repr @@ -60,7 +66,7 @@ def test_single_catchment_html_repr(catchment): padding-left: 2em; } -
Attributes (3)
  • id: 100_16_16
  • area: 22800.0
  • type: Kinematic Wave
Quantities (5)
  • TotalRunOff
  • ActualRainfall
  • ZinkLoadRR
  • ZinkMassAccumulatedRR
  • ZinkRR
""" +
Attributes (3)
  • id: 100_16_16
  • area: 22800.0
  • type: Kinematic Wave
Quantities (5)
  • Total Runoff (m^3/s)
  • Actual Rainfall (m/s)
  • Zink, Load, RR (kg/s)
  • Zink, Mass, Accumulated, RR (kg)
  • Zink, RR (mg/l)
""" assert html_repr == expected_html_repr @@ -74,7 +80,7 @@ def test_single_reach_html_repr(river_reach): padding-left: 2em; } -
Attributes (5)
  • name: river
  • length: 2024.2276598819008
  • start_chainage: 53100.0
  • end_chainage: 55124.2276598819
  • n_gridpoints: 94
Quantities (4)
  • WaterLevel
  • ManningResistanceNumber
  • Discharge
  • FlowVelocity
""" +
Attributes (5)
  • name: river
  • length: 2024.2276598819008
  • start_chainage: 53100.0
  • end_chainage: 55124.2276598819
  • n_gridpoints: 94
Quantities (4)
  • Water level (m)
  • Manning Resistance Number (m^(1/3)/s)
  • Discharge (m^3/s)
  • Flow velocity (m/s)
""" assert html_repr == expected_html_repr @@ -88,5 +94,22 @@ def test_single_structure_html_repr(structure): padding-left: 2em; } -
Attributes (3)
  • id: 119w1
  • type: Weir
  • chainage: 0.5
Quantities (1)
  • Discharge
""" +
Attributes (3)
  • id: 119w1
  • type: Weir
  • chainage: 0.5
Quantities (1)
  • Discharge (m^3/s)
""" 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 diff --git a/tests/test_res1d_catchments.py b/tests/test_res1d_catchments.py index 2576123a..10f1aaf8 100644 --- a/tests/test_res1d_catchments.py +++ b/tests/test_res1d_catchments.py @@ -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 \n" - + "1 - ActualRainfall \n" - + "2 - ZinkLoadRR \n" - + "3 - ZinkMassAccumulatedRR \n" - + "4 - ZinkRR " - ) - assert res1d_info == res1d_info_ref + res1d.info() def test_data_item_dicts(test_file): diff --git a/tests/test_res1d_lts_chronological.py b/tests/test_res1d_lts_chronological.py index ab389877..5b8e226a 100644 --- a/tests/test_res1d_lts_chronological.py +++ b/tests/test_res1d_lts_chronological.py @@ -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 \n" - + "1 - DischargeIntegratedMonthlyCount <()>\n" - + "2 - DischargeIntegratedMonthlyDuration \n" - + "3 - Component_1TransportIntegratedMonthly \n" - + "4 - Component_1TransportIntegratedMonthlyCount <()>\n" - + "5 - Component_1TransportIntegratedMonthlyDuration \n" - + "6 - Component_2TransportIntegratedMonthly \n" - + "7 - Component_2TransportIntegratedMonthlyCount <()>\n" - + "8 - Component_2TransportIntegratedMonthlyDuration \n" - + "9 - SurchargeIntegratedMonthly \n" - + "10 - SurchargeIntegratedMonthlyCount <()>\n" - + "11 - SurchargeIntegratedMonthlyDuration \n" - + "12 - DischargeIntegratedMonthlyOutlets \n" - + "13 - DischargeIntegratedMonthlyWeirs \n" - + "14 - DischargeIntegratedMonthlyTotalOutflow \n" - + "15 - Component_1TransportIntegratedMonthlyTotalEmission \n" - + "16 - Component_2TransportIntegratedMonthlyTotalEmission \n" - + "17 - Component_1TransportIntegratedMonthlyOutlets \n" - + "18 - Component_2TransportIntegratedMonthlyOutlets \n" - + "19 - Component_1TransportIntegratedMonthlyWeirs \n" - + "20 - Component_2TransportIntegratedMonthlyWeirs " - ) - assert res1d_info == res1d_info_ref + res1d.info() def test_data_item_dicts(test_file): diff --git a/tests/test_res1d_lts_events.py b/tests/test_res1d_lts_events.py index 7d8d51c3..a35a417e 100644 --- a/tests/test_res1d_lts_events.py +++ b/tests/test_res1d_lts_events.py @@ -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 \n" - + "1 - WaterLevelMaximumTime \n" - + "2 - DischargeIntegrated \n" - + "3 - DischargeIntegratedTime \n" - + "4 - DischargeMaximum \n" - + "5 - DischargeMaximumTime \n" - + "6 - DischargeDuration \n" - + "7 - DischargeDurationTime \n" - + "8 - Component_1Maximum \n" - + "9 - Component_1MaximumTime \n" - + "10 - Component_2Maximum \n" - + "11 - Component_2MaximumTime \n" - + "12 - Component_1TransportIntegrated \n" - + "13 - Component_1TransportIntegratedTime \n" - + "14 - Component_2TransportIntegrated \n" - + "15 - Component_2TransportIntegratedTime \n" - + "16 - SurchargeMaximum \n" - + "17 - SurchargeMaximumTime \n" - + "18 - SurchargeIntegrated \n" - + "19 - SurchargeIntegratedTime \n" - + "20 - SurchargeDuration \n" - + "21 - SurchargeDurationTime \n" - + "22 - FlowVelocityMaximum \n" - + "23 - FlowVelocityMaximumTime " - ) - assert res1d_info == res1d_info_ref + res1d.info() def test_data_item_dicts(test_file): diff --git a/tests/test_res1d_network.py b/tests/test_res1d_network.py index fbee407b..32b1ff1c 100644 --- a/tests/test_res1d_network.py +++ b/tests/test_res1d_network.py @@ -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 \n" - + "1 - Discharge " - ) - assert res1d_info == res1d_info_ref + res1d.info() def test_data_item_dicts(test_file): diff --git a/tests/test_res1d_network_river.py b/tests/test_res1d_network_river.py index ee3226ca..7c2d88f0 100644 --- a/tests/test_res1d_network_river.py +++ b/tests/test_res1d_network_river.py @@ -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 \n" - + "1 - Discharge \n" - + "2 - ManningResistanceNumber \n" - + "3 - FlowVelocity \n" - + "4 - FlowVelocityInStructure \n" - + "5 - FlowAreaInStructure \n" - + "6 - DischargeInStructure \n" - + "7 - ControlStrategyId \n" - + "8 - GateLevel \n" - + "9 - Variable:TwoTimeSensorGateLevel <->\n" - + "10 - Water level:Sensor:s.h.river53745.34 \n" - + "11 - Gate level:Sensor:SensorGateLevel \n" - + "12 - Discharge:Sensor:SensorGauge1 " - ) - assert res1d_info == res1d_info_ref + res1d.info() def test_data_item_dicts(test_file): diff --git a/tests/test_swmm_network.py b/tests/test_swmm_network.py index 657bc037..472e6872 100644 --- a/tests/test_swmm_network.py +++ b/tests/test_swmm_network.py @@ -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 \n" - + "1 - SWMM_NODE_HEAD \n" - + "2 - SWMM_NODE_VOLUME \n" - + "3 - SWMM_NODE_LATFLOW \n" - + "4 - SWMM_NODE_INFLOW \n" - + "5 - SWMM_NODE_OVERFLOW \n" - + "6 - SWMM_NODE_QUAL \n" - + "7 - SWMM_LINK_FLOW \n" - + "8 - SWMM_LINK_DEPTH \n" - + "9 - SWMM_LINK_VELOCITY \n" - + "10 - SWMM_LINK_Froude_Number <()>\n" - + "11 - SWMM_LINK_CAPACITY <()>\n" - + "12 - SWMM_LINK_QUAL \n" - + "13 - SWMM_SUBCATCH_RAINFALL \n" - + "14 - SWMM_SUBCATCH_SNOWDEPTH \n" - + "15 - SWMM_SUBCATCH_EVAP \n" - + "16 - SWMM_SUBCATCH_INFIL \n" - + "17 - SWMM_SUBCATCH_RUNOFF \n" - + "18 - SWMM_SUBCATCH_GW_FLOW \n" - + "19 - SWMM_SUBCATCH_GW_ELEV \n" - + "20 - SWMM_SUBCATCH_SOIL_MOIST <()>\n" - + "21 - SWMM_SUBCATCH_WASHOFF \n" - + "22 - SWMM_SYS_TEMPERATURE \n" - + "23 - SWMM_SYS_RAINFALL \n" - + "24 - SWMM_SYS_SNOWDEPTH \n" - + "25 - SWMM_SYS_INFIL \n" - + "26 - SWMM_SYS_RUNOFF \n" - + "27 - SWMM_SYS_DWFLOW \n" - + "28 - SWMM_SYS_GWFLOW \n" - + "29 - SWMM_SYS_INFLOW \n" - + "30 - SWMM_SYS_EXFLOW \n" - + "31 - SWMM_SYS_FLOODING \n" - + "32 - SWMM_SYS_OUTFLOW \n" - + "33 - SWMM_SYS_STORAGE \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):