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_keyword_lines(source_text, actual_text, keywords_=None, skipped_keywords=None, ignore_trailing_0=True), 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_keyword_lines(test_text, actual_text, keywords_=None, skipped_keywords=None, ignore_trailing_0=True), 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_keyword_lines(test_text, actual_text, keywords_=None, skipped_keywords=None, ignore_trailing_0=True), 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_keyword_lines(test_text, actual_text, keywords_=None, skipped_keywords=None, ignore_trailing_0=True), msg)
def test_weir_divider(self): """Test divider: WEIR created according to Manual Name Elev DivLink WEIR Qmin Ht Cd (Ymax Y0 Ysur Apond) """ test_text = "NODE10 0 LK1 WEIR 0.5 2 0.7 2 0 0" my_options = DividerReader.read(test_text) actual_text = DividerWriter.as_text(my_options) msg = '\nSet:' + test_text + '\nGet:' + actual_text self.assertTrue( match_keyword_lines(test_text, actual_text, keywords_=None, skipped_keywords=None, ignore_trailing_0=True), msg)
def test_pollutant_section(self): """Test POLLUTANTS section through Project""" for source_text in self.SOURCE_TEXTS: section_from_text = self.project_reader.read_pollutants.read( source_text) actual_text = self.project_writer.write_pollutants.as_text( section_from_text) msg = '\nSet:\n' + source_text + '\nGet:\n' + actual_text self.assertTrue( match_keyword_lines(source_text, actual_text, keywords_=None, skipped_keywords=None, ignore_trailing_0=True), msg)
def test_dividers(self): """Test DIVIDERS section from Example-1b""" source_text = "[DIVIDERS]\n" \ ";;Name Elevation Diverted Link Type Parameters\n" \ ";;-------------- ---------- ---------------- ---------- ----------\n" \ "10 0 * CUTOFF 0 0 0\n" \ "NODE10 0 LK1 WEIR 0.5 2 0.7 2 0 0" section_from_text = self.project_reader.read_dividers.read(source_text) actual_text = self.project_writer.write_dividers.as_text( section_from_text) msg = '\nSet:\n' + source_text + '\nGet:\n' + actual_text self.assertTrue( match_keyword_lines(source_text, actual_text, keywords_=None, skipped_keywords=None, ignore_trailing_0=True), msg)
def test_file(self): """Test daily temperature in file daily_temperature.txt""" # Will failed if SNOW_MELT not given test_text = "[TEMPERATURE]\n" \ " ;;Parameter Fname (Start)\n" \ " FILE daily_tmperature.txt\n" \ " SNOWMELT 2 0.5 0.6 0.0 50 0\n" \ " ADC IMPERVIOUS 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0\n" \ " ADC PERVIOUS 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0" my_options = TemperatureReader.read(test_text) actual_text = TemperatureWriter.as_text(my_options) msg = '\nSet:' + test_text + '\nGet:' + actual_text keywords_ = [ "[TEMPERATURE]", "FILE", "SNOWMELT", "ADC IMPERVIOUS", "ADC PERVIOUS" ] self.assertTrue(match_keyword_lines(actual_text, test_text, keywords_), msg)
def test_timeseries(self): """Test daily temperature in time series Must have SNOW_MELT, otherwise will fail because SNOW_MELT default values are written """ test_text = "[TEMPERATURE]\n" \ " ;;Parameter TSeries\n" \ " TIMESERIES TS1\n" \ " SNOWMELT 2 0.5 0.6 0.0 50 0\n" \ " ADC IMPERVIOUS 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0\n" \ " ADC PERVIOUS 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0" my_options = TemperatureReader.read(test_text) actual_text = TemperatureWriter.as_text(my_options) msg = '\nSet:' + test_text + '\nGet:' + actual_text # self.assertTrue(match(actual_text, test_text), msg) keywords_ = [ "[TEMPERATURE]", "TIMESERIES", "SNOWMELT", "ADC IMPERVIOUS", "ADC PERVIOUS" ] self.assertTrue(match_keyword_lines(actual_text, test_text, keywords_), msg)
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_keyword_lines(source_text, actual_text, keywords_=None, skipped_keywords=None, ignore_trailing_0=True), 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""" test_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(test_text) actual_text = self.project_writer.write_xsections.as_text( section_from_text) msg = '\nSet:\n' + test_text + '\nGet:\n' + actual_text # self.assertTrue(match(actual_text, source_text), msg) self.assertTrue( match_keyword_lines(test_text, actual_text, keywords_=None, skipped_keywords=None, ignore_trailing_0=True), msg)