def test_writer(self): """Test BackdropOptionsWriter by specify attributes""" my_backdrop = backdrop.BackdropOptions() assert my_backdrop.SECTION_NAME == "[BACKDROP]" my_backdrop.file = "BackdropFilename" expected_text = "[BACKDROP]\n" \ "FILE BackdropFilename\n" \ "DIMENSIONS 0.0 0.0 10000.0 10000.0\n" \ "UNITS NONE\n" \ "OFFSET 0.0 0.0" actual_text = BackdropOptionsWriter.as_text(my_backdrop) msg = '\nSet:' + expected_text + '\nGet:' + actual_text self.assertTrue(match(actual_text, expected_text), msg) my_backdrop.dimensions = ("1.0", "2.0", "30000.0", "40000.0") my_backdrop.units = backdrop.BackdropUnits.METERS my_backdrop.offset = ("1.1", "2.2") expected_text = "[BACKDROP]\n" \ "FILE BackdropFilename\n" \ "DIMENSIONS 1.0 2.0 30000.0 40000.0\n" \ "UNITS METERS\n" \ "OFFSET 1.1 2.2" actual_text = BackdropOptionsWriter.as_text(my_backdrop) msg = '\nSet:' + expected_text + '\nGet:' + actual_text self.assertTrue(match(actual_text, expected_text), msg)
def test_writer(self): """Test EnergyOptionsWriter""" my_energy = energy.EnergyOptions() assert match(EnergyOptionsWriter.as_text(my_energy), SimpleEnergyTest.TEST_TEXTS[2][0]) my_energy.global_efficiency = "87.6" my_energy.global_price = "1.23" my_energy.demand_charge = "2.34" actual_text1 = EnergyOptionsWriter.as_text(my_energy) my_energy2 = EnergyOptionsReader.read(actual_text1) actual_text2 = EnergyOptionsWriter.as_text(my_energy2) assert actual_text1 == actual_text2 assert my_energy2.global_efficiency == "87.6" assert my_energy2.global_price == "1.23" assert my_energy2.demand_charge == "2.34" expected_text = "[ENERGY]\n" + \ " Global Efficiency 87.6\n" + \ " Global Price 1.23\n" + \ " Demand Charge 2.34" msg = '\nSet:\n' + expected_text + '\nGet:\n' + actual_text2 self.assertTrue(match(actual_text2, expected_text), msg)
def test_get(self): """Test get_text of quality sections""" my_quality = quality.QualityOptions() my_quality.quality = quality.QualityAnalysisType.CHEMICAL my_quality.chemical_name = "DummyChemical" my_quality.mass_units = "mg/L" my_quality.diffusivity = 1.0 my_quality.trace_node = "" my_quality.tolerance = 0.01 name = my_quality.SECTION_NAME assert name == "[OPTIONS]" # assert self.my_HydraulicsOptions.get_text() == "[OPTIONS]", 'incorrect options block' expected_text = " Quality DummyChemical mg/L\n" + \ " Diffusivity 1.0\n" + \ " Tolerance 0.01\n" actual_text = QualityOptionsWriter.as_text(my_quality) msg = '\nSet:'+expected_text+'\nGet:'+actual_text self.assertTrue(match(actual_text, expected_text), msg) my_quality.quality = quality.QualityAnalysisType.TRACE my_quality.diffusivity = 2.0 my_quality.trace_node = "XX" my_quality.tolerance = 0.02 my_quality.mass_units = "" expected_text = " Quality Trace XX\n" + \ " Diffusivity 2.0\n" + \ " Tolerance 0.02\n" actual_text = QualityOptionsWriter.as_text(my_quality) msg = '\nSet:'+expected_text+'\nGet:'+actual_text self.assertTrue(match(actual_text, expected_text), msg)
def test_bare(self): """Bare section""" test_text = "[TITLE]" my_title = Title() # default_text = self.my_title.get_text() default_text = TitleWriter.as_text(my_title) msg = '\nSet:' + test_text + '\nGet:' + default_text self.assertTrue(match(default_text, test_text), msg) my_title = TitleReader.read(test_text) actual_text = TitleWriter.as_text(my_title) # assert actual_text == test_text msg = '\nSet:' + test_text + '\nGet:' + actual_text self.assertTrue(match(actual_text, test_text), msg)
def test_geom_barrel(self): """Predefined shapes with Geoms and Barrel only""" test_text = r"""C1 TRAPEZOIDAL 3 5 5 5 1""" my_options = CrossSectionReader.read(test_text) actual_text = CrossSectionWriter.as_text(my_options) msg = '\nSet:' + test_text + '\nGet:' + actual_text self.assertTrue(match(actual_text, test_text), msg)
def test_lead(self): """Lead removal 20% of TSS removal""" test_text = "Node23 Lead R = 0.2 * R_TSS" my_options = TreatmentReader.read(test_text) actual_text = TreatmentWriter.as_text(my_options) msg = '\nSet:' + test_text + '\nGet:' + actual_text self.assertTrue(match(actual_text, test_text), msg)
def test_lid_usage(self): """Test aquifer parameters from SWMM 5.1 manual""" test_text = " S2 Swale 1 10000 50 0 0 0 'swale.rpt' " my_options = LIDUsageReader.read(test_text) actual_text = LIDUsageWriter.as_text(my_options) msg = '\nSet:' + test_text + '\nGet:' + actual_text self.assertTrue(match(actual_text, test_text), msg)
def test_empty_wo_return(self): """Empty section read/write wo ending carriage return""" test_text = "[TITLE]\n" + "SWMM Project" my_title = TitleReader.read(test_text) actual_text = TitleWriter.as_text(my_title) msg = '\nSet:'+test_text+'\nGet:'+actual_text self.assertTrue(match(actual_text, test_text), msg)
def test_one_raingage(self): """Test one rain gage""" for test_text in self.TEST_TEXTS: my_options = RainGageReader.read(test_text) actual_text = RainGageWriter.as_text(my_options) msg = '\nSet:' + test_text + '\nGet:' + actual_text self.assertTrue(match(actual_text, test_text), msg)
def test_file(self): """Use external file, Created based on SWMM 5.1 manual Page335""" test_text = "TS1 FILE myfile.txt" my_options = TimeSeriesReader.read(test_text) actual_text = TimeSeriesWriter.as_text(my_options) msg = '\nSet:' + test_text + '\nGet:' + actual_text self.assertTrue(match(actual_text, test_text), msg)
def test_default(self): """Test default of one Landuse""" test_text = " Residential_1 " my_options = LanduseReader.read(test_text) actual_text = LanduseWriter.as_text(my_options) msg = '\nSet:' + test_text + '\nGet:' + actual_text self.assertTrue(match(actual_text, test_text), msg)
def test_all_options(self): """Test all options of FILE section""" my_options = Files() test_text = """ [FILES] ;;Interfacing Files USE RAINFALL rainfall_u.txt USE RUNOFF runoff_u.txt USE RDII rdii_u.txt USE HOTSTART hotstart_u.txt SAVE HOTSTART hotstart_s.txt USE INFLOWS inflows_u.txt SAVE OUTFLOWS outflows_s.txt """ my_options = self.read_files.read(test_text) actual_text = self.write_files.as_text(my_options) msg = '\nSet:' + test_text + '\nGet:' + actual_text self.assertTrue(match(actual_text, test_text), msg) assert my_options.use_rainfall == "rainfall_u.txt" assert my_options.save_rainfall is None assert my_options.use_runoff == "runoff_u.txt" assert my_options.save_runoff is None assert my_options.use_hotstart == "hotstart_u.txt" assert my_options.save_hotstart == "hotstart_s.txt" assert my_options.use_rdii == "rdii_u.txt" assert my_options.save_rdii is None assert my_options.use_inflows == "inflows_u.txt" assert my_options.save_outflows == "outflows_s.txt"
def test_inflows_flowts(self): """Test INFLOWS section with FLOW TS type""" source_text = r""" [INFLOWS] ;;Node Constituent Time Series Type Mfactor Sfactor Baseline Pattern ;;-------------- ---------------- ---------------- -------- -------- -------- -------- -------- Inlet FLOW Inflow FLOW 1.0 1.0 """ section_from_text = self.project_reader.read_inflows.read(source_text) actual_text = self.project_writer.write_inflows.as_text( section_from_text) msg = '\nSet:\n' + source_text + '\nGet:\n' + actual_text self.assertTrue(match(actual_text, source_text), msg) project_section = section_from_text msg = "Expected 1 item in INFLOWS, found " + str( len(project_section.value)) self.assertTrue(len(project_section.value) == 1, msg) inflow = project_section.value[0] msg = "Expected INFLOW node Inlet, found " + inflow.node self.assertTrue(inflow.node == "Inlet", msg) msg = "Expected INFLOW Parameter FLOW, found " + inflow.constituent self.assertTrue(inflow.constituent == "FLOW", msg) msg = "Expected INFLOW Time Series Inflow, found " + inflow.timeseries self.assertTrue(inflow.timeseries == "Inflow", msg) msg = "Expected INFLOW Conversion Factor 1.0, found " + inflow.conversion_factor self.assertTrue(inflow.conversion_factor == "1.0", msg) msg = "Expected INFLOW Scaling Factor 1.0, found " + inflow.scale_factor self.assertTrue(inflow.scale_factor == "1.0", msg)
def test_xsections_section(self): """Test XSECTIONS: example 3""" source_text = """[XSECTIONS] ;;Link Shape Geom1 Geom2 Geom3 Geom4 Barrels ;;-------------- ------------ ---------------- ---------- ---------- ---------- ---------- C1 TRAPEZOIDAL 3 5 5 5 1 C2 TRAPEZOIDAL 1 0 0.0001 25 1 C3 CIRCULAR 2.25 0 0 0 1 C4 TRAPEZOIDAL 3 5 5 5 1 C5 TRAPEZOIDAL 3 5 5 5 1 C6 TRAPEZOIDAL 3 5 5 5 1 C7 CIRCULAR 3.5 0 0 0 1 C8 TRAPEZOIDAL 3 5 5 5 1 C9 TRAPEZOIDAL 3 5 5 5 1 C10 TRAPEZOIDAL 3 5 5 5 1 C11 CIRCULAR 4.75 0 0 0 1 C_out CIRCULAR 4.75 0 0 0 1 Or1 RECT_CLOSED 0.3 0.25 0 0 Or2 RECT_CLOSED 0.5 2 0 0 Or3 RECT_CLOSED 0.25 0.35 0 0 W1 RECT_OPEN 2.83 1.75 0 0 ;;Link Shape Geom1 Geom2 Geom3 Geom4 Barrels Culvert ;;-------------- ------------ ---------------- ---------- ---------- ---------- ---------- ---------- Culvert CIRCULAR 3 0 0 0 2 4 Channel TRAPEZOIDAL 9 10 2 2 1 Roadway RECT_OPEN 50 200 0 0 """ section_from_text = self.project_reader.read_xsections.read(source_text) actual_text = self.project_writer.write_xsections.as_text(section_from_text) msg = '\nSet:\n' + source_text + '\nGet:\n' + actual_text self.assertTrue(match(actual_text, source_text), msg)
def test_custom_curve(self): """CUSTOM with Curve only""" test_text = r"""W1 CUSTOM 1.0 Curve1""" my_options = CrossSectionReader.read(test_text) actual_text = CrossSectionWriter.as_text(my_options) msg = '\nSet:' + test_text + '\nGet:' + actual_text self.assertTrue(match(actual_text, test_text), msg)
def test_geom(self): """Predefined shapes with Geoms only""" test_text = r"""W1 RECT_OPEN 2.83 1.75 0 0""" my_options = CrossSectionReader.read(test_text) actual_text = CrossSectionWriter.as_text(my_options) msg = '\nSet:' + test_text + '\nGet:' + actual_text self.assertTrue(match(actual_text, test_text), msg)
def test_more(self): """Test Report options regarding subcatchments, nodes, links and LID lists""" test_text = "[REPORT]\n" \ "INPUT NO\n" \ "CONTINUITY NO\n" \ "FLOWSTATS NO\n" \ "CONTROLS NO\n" \ "SUBCATCHMENTS S1 S2 S3\n" \ "NODES J1\n" \ "LINKS C1 C2\n" \ "LID L1 S1 L1SUB1.txt L2 S1 L2SUB1.txt" my_report = ReportReader.read(test_text) assert my_report.input == False assert my_report.continuity == False assert my_report.flow_stats == False assert my_report.controls == False assert my_report.subcatchments == ['S1', 'S2', 'S3'] assert my_report.nodes == ['J1'] assert my_report.links == ['C1', 'C2'] assert my_report.lids == [ 'L1', 'S1', 'L1SUB1.txt', 'L2', 'S1', 'L2SUB1.txt' ] actual_text = ReportWriter.as_text(my_report) msg = '\nSet:' + test_text + '\nGet:' + actual_text self.assertTrue(match(actual_text, test_text), msg)
def test_get(self): """Test get_text""" my_times = times.TimesOptions() my_times.duration = "24:00" my_times.hydraulic_timestep = "1:00" # hours:minutes my_times.quality_timestep = "0:05" # hours:minutes my_times.rule_timestep = "0:05" # hours:minutes my_times.pattern_timestep = "1:00" # hours:minutes my_times.pattern_start = "0:00" # hours:minutes my_times.report_timestep = "1:00" # hours:minutes my_times.report_start = "0:00" # hours:minutes my_times.start_clocktime = "12 am" # hours:minutes AM/PM my_times.statistic = times.StatisticOptions.AVERAGED # NONE/AVERAGED/MINIMUM/MAXIMUM/RANGE name = my_times.SECTION_NAME assert name == "[TIMES]" expected_text = "[TIMES]\n" + \ " Report Start 0:00\n" + \ " Quality Timestep 0:05\n" + \ " Report Timestep 1:00\n" + \ " Hydraulic Timestep 1:00\n" + \ " Pattern Timestep 1:00\n" + \ " Duration 24:00\n" + \ " Start ClockTime 12 am\n" + \ " Statistic AVERAGED\n" + \ " Pattern Start 0:00\n" + \ " Rule Timestep 0:05" actual_text = TimesOptionsWriter.as_text(my_times) msg = '\nSet:'+expected_text+'\nGet:'+actual_text self.assertTrue(match(actual_text, expected_text), msg)
def test_conduit_section(self): """Test CONDUIT section using Project class, data from Example 7""" source_text = "[CONDUITS]\n" \ " ;; Inlet Outlet Manning Inlet Outlet Init. Max.\n" \ " ;;Name Node Node Length N Offset Offset Flow Flow\n" \ " ;;-------------- ---------------- ---------------- ---------- ---------- ---------- ---------- ---------- ----------\n" \ " C2a J2a J2 157.48 0.016 4 4 0 0\n" \ " C2 J2 J11 526.0 0.016 4 6 0 0\n" \ " C3 J3 J4 109.0 0.016 0 6 0 0\n" \ " C4 J4 J5 133.0 0.05 6 4 0 0\n" \ " C5 J5 J6 207.0 0.05 4 0 0 0\n" \ " C6 J7 J6 140.0 0.05 8 0 0 0\n" \ " C7 J6 J8 95.0 0.016 0 0 0 0\n" \ " C8 J8 J9 166.0 0.05 0 0 0 0\n" \ " C9 J9 J10 320.0 0.05 0 6 0 0\n" \ " C10 J10 J11 145.0 0.05 6 6 0 0\n" \ " C11 J11 O1 89.0 0.016 0 0 0 0\n" \ " C_Aux1 Aux1 J1 377.31 0.016 0 4 0 0\n" \ " C_Aux2 Aux2 J2a 239.41 0.016 0 4 0 0\n" \ " C_Aux1to2 J1 Aux2 286.06 0.016 4 0 0 0\n" \ " C_Aux3 Aux3 J3 444.75 0.05 6 0 0 0\n" \ " P1 J1 J5 185.39 0.016 0 0 0 0\n" \ " P2 J2a J2 157.48 0.016 0 0 0 0\n" \ " P3 J2 J11 529.22 0.016 0 0 0 0\n" \ " P4 Aux3 J4 567.19 0.016 0 0 0 0\n" \ " P5 J5 J4 125.98 0.016 0 0 0 0\n" \ " P6 J4 J7 360.39 0.016 0 0 0 0\n" \ " P7 J7 J10 507.76 0.016 0 0 0 0\n" \ " P8 J10 J11 144.50 0.016 0 0 0 0" section_from_text = self.project_reader.read_conduits.read(source_text) actual_text = self.project_writer.write_conduits.as_text( section_from_text) msg = '\nSet:' + source_text + '\nGet:' + actual_text self.assertTrue(match(actual_text, source_text), msg)
def test_example8(self): """Test one set of DWI from example 8""" test_text = r"""J1 FLOW 0.008 """ my_options = DryWeatherInflowReader.read(test_text) actual_text = DryWeatherInflowWriter.as_text(my_options) msg = '\nSet:' + test_text + '\nGet:' + actual_text self.assertTrue(match(actual_text, test_text), msg)
def test_get(self): """Test ReactionsWriter through match()""" my_reactions = reactions.Reactions() my_reactions.order_bulk = 1.1 my_reactions.order_wall = 1.2 my_reactions.order_tank = 1.3 my_reactions.global_bulk = 2.1 my_reactions.global_wall = 2.2 my_reactions.limiting_potential = 0.1 my_reactions.roughness_correlation = 0.2 name = my_reactions.SECTION_NAME assert name == "[REACTIONS]" expected_text = "[REACTIONS]\n" \ " Order Tank 1.3\n" \ " Global Wall 2.2\n" \ " Roughness Correlation 0.2\n" \ " Limiting Potential 0.1\n" \ " Global Bulk 2.1\n" \ " Order Bulk 1.1\n" \ " Order Wall 1.2" actual_text = ReactionsWriter.as_text(my_reactions) msg = '\nSet:' + expected_text + '\nGet:' + actual_text self.assertTrue(match(actual_text, expected_text), msg)
def test_all_opts(self): """Test junction with all options""" test_text = " J1 2.0 0.1 0.2 0.3 0.4" my_options = JunctionReader.read(test_text) actual_text = JunctionWriter.as_text(my_options) msg = '\nSet:' + test_text + '\nGet:' + actual_text self.assertTrue(match(actual_text, test_text), msg)
def test_setget(self): """Test both set_text and get_text of Options, data from Net1.inp""" test_text = """ [OPTIONS] Units GPM Headloss H-W Specific Gravity 1.0 Viscosity 1.0 Trials 40 Accuracy 0.001 CHECKFREQ 2 MAXCHECK 10 DAMPLIMIT 0 Unbalanced Continue 10 Pattern 1 Demand Multiplier 1.0 Emitter Exponent 0.5 Quality Chlorine mg/L Diffusivity 1.0 Tolerance 0.01 """ my_options = OptionsReader.read(test_text) actual_text = OptionsWriter.as_text(my_options) msg = '\nSet:\n' + test_text + '\nGet:\n' + actual_text self.assertTrue(match(actual_text, test_text), msg)
def test_selected_parameters(self): """Test junction omit some parameters""" test_text = " J1 2.0 " my_options = JunctionReader.read(test_text) actual_text = JunctionWriter.as_text(my_options) msg = '\nSet:' + test_text + '\nGet:' + actual_text self.assertTrue(match(actual_text, test_text), msg)
def test_bod(self): """BOD first order decay, from SWMM 5.1 manual""" test_text = "Node23 BOD C = BOD * exp(-0.05*HRT) " my_options = TreatmentReader.read(test_text) actual_text = TreatmentWriter.as_text(my_options) msg = '\nSet:' + test_text + '\nGet:' + actual_text self.assertTrue(match(actual_text, test_text), msg)
def test_junctions(self): """Test JUNCTIONS section through Project class""" source_text = r""" [JUNCTIONS] ;; Invert Max. Init. Surcharge Ponded ;;Name Elev. Depth Depth Depth Area ;;-------------- ---------- ---------- ---------- ---------- ---------- J1 4973 0 0 0 0 J2 4969 0 0 0 0 J3 4973 0 0 0 0 J4 4971 0 0 0 0 J5 4969.8 0 0 0 0 J6 4969 0 0 0 0 J7 4971.5 0 0 0 0 J8 4966.5 0 0 0 0 J9 4964.8 0 0 0 0 J10 4963.8 0 0 0 0 J11 4963 0 0 0 0 J12 4973.8 0 0 0 0 J13 4970.7 0 0 0 0 J14 4972.9 0 0 0 0 J15 4974.5 0 0 0 0 J16 4973.5 0 0 0 0 J17 4973.5 0 0 0 0 """ section_from_text = self.project_reader.read_junctions.read( source_text) actual_text = self.project_writer.write_junctions.as_text( section_from_text) msg = '\nSet:\n' + source_text + '\nGet:\n' + actual_text self.assertTrue(match(actual_text, source_text), msg)
def test_gwf(self): """Test one set of GWF parameters""" test_text = "CA-11 DEEP 0.01*Hgs" my_options = GWFReader.read(test_text) actual_text = GWFWriter.as_text(my_options) # display purpose msg = '\nSet:' + test_text + '\nGet:' + actual_text self.assertTrue(match(actual_text, test_text), msg)
def test_reader_writer(self): """Test Simple ReportReader and ReportWriter""" test_text = "[REPORT]\n" + \ ";;Reporting Options\n" + \ " CONTINUITY YES\n" + \ " FLOWSTATS YES\n" + \ " AVERAGES NO\n" + \ " SUBCATCHMENTS NONE\n" + \ " LINKS NONE\n" + \ " INPUT NO\n" + \ " NODES NONE\n" + \ " CONTROLS NO" my_report = Report() # Write default for debugging my_report = ReportReader.read(test_text) assert my_report.input == False # Individual inputs: assert my_report.continuity == True assert my_report.flow_stats == True assert my_report.controls == False assert my_report.subcatchments == ['NONE'] assert my_report.nodes == ['NONE'] assert my_report.links == ['NONE'] assert my_report.lids == [] actual_text = ReportWriter.as_text(my_report) msg = '\nSet:' + test_text + '\nGet:' + actual_text self.assertTrue(match(actual_text, test_text), msg)
def test_geom_barrel_culvert(self): """Predefined shapes with Geoms, Barrel and culvert""" test_text = r"""Culvert CIRCULAR 3 0 0 0 2 4""" my_options = CrossSectionReader.read(test_text) actual_text = CrossSectionWriter.as_text(my_options) msg = '\nSet:' + test_text + '\nGet:' + actual_text self.assertTrue(match(actual_text, test_text), msg)
def test_empty(self): """Empty section read/write""" test_text = "[TITLE]\n" my_title = TitleReader.read(test_text) actual_text = TitleWriter.as_text(my_title) msg = '\nSet:' + test_text + '\nGet:' + actual_text self.assertTrue(match(actual_text, test_text), msg)