Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates to support read/write of additional INP/RPT sections #219

Merged
merged 12 commits into from
Apr 21, 2024
Prev Previous commit
Next Next commit
updated inp sections test to include additional models
  • Loading branch information
kaklise committed Apr 15, 2024
commit 2dfd9e4b2447bc067ad870d6a47893cd0f4069a4
33 changes: 23 additions & 10 deletions swmmio/tests/test_dataframes.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
BUILD_INSTR_01, MODEL_XSECTION_ALT_01, df_test_coordinates_csv,
MODEL_FULL_FEATURES_XY, DATA_PATH, MODEL_XSECTION_ALT_03,
MODEL_CURVE_NUMBER, MODEL_MOD_HORTON, MODEL_GREEN_AMPT, MODEL_MOD_GREEN_AMPT,
MODEL_INFILTRAION_PARSE_FAILURE, OWA_RPT_EXAMPLE)
MODEL_INFILTRAION_PARSE_FAILURE, OWA_RPT_EXAMPLE,
MODEL_TEST_INLET_DRAINS, MODEL_PUMP_CONTROL)
from swmmio.utils.dataframes import (dataframe_from_rpt, dataframe_from_inp, dataframe_from_bi)
from swmmio.utils.text import get_inp_sections_details
from swmmio.run_models.run import run_simple
Expand Down Expand Up @@ -263,13 +264,23 @@ def test_polygons(test_model_02):
# print()

def test_inp_sections():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really like this test. My only suggestion is that we clean up the artifacts that are created after this test is run. That said, I'm fine with leaving this as is and refactoring our unit tests in a future PR.



# Additional models could be added to this test, or additional features
# could be added to the full feature model
inpfiles = [
MODEL_FULL_FEATURES_PATH,
MODEL_CURVE_NUMBER,
MODEL_MOD_HORTON,
MODEL_GREEN_AMPT,
MODEL_TEST_INLET_DRAINS,
MODEL_PUMP_CONTROL,
]

from swmmio.defs import INP_OBJECTS
all_sections = set(sec.upper() for sec in INP_OBJECTS.keys())
unsupported_sections = set()
tested_sections = set()

for inpfile in inpfiles:
print(inpfile)

Expand All @@ -287,15 +298,16 @@ def test_inp_sections():
temp_inpfile = 'temp.inp'
model = swmmio.Model(inpfile, include_rpt=False)
empty_sections = []
unsupported_sections = []
for sec in headers.keys():
try:
df = getattr(model.inp, sec.lower())
if df.empty:
empty_sections.append(sec)
if not df.empty:
tested_sections.add(sec.upper())
else:
empty_sections.append(sec.upper())
setattr(model.inp, sec, df.copy())
except:
unsupported_sections.append(sec)
unsupported_sections.add(sec.upper())
model.inp.save(temp_inpfile)
headers2 = get_inp_sections_details(temp_inpfile,
include_brackets=False)
Expand All @@ -311,9 +323,10 @@ def test_inp_sections():
assert 'MaxQ' in links2.columns
# Check that results are the same
assert_series_equal(links['MaxQ'], links2['MaxQ'])
# Print empty and unsupported INP file sections
print('Empty sections', empty_sections)
print('Unsupported sections', unsupported_sections)


# Print empty and unsupported INP file sections
print('Unsupported sections', unsupported_sections)
print('Untested sections', all_sections - unsupported_sections - tested_sections)

if __name__ == "__main__":
test_inp_sections()
Loading