def test_all_options(self): """Test all options of FILE section""" self.my_options = Files() test_all_opts = """ [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 """ self.my_options.set_text(test_all_opts) assert self.my_options.use_rainfall == "rainfall_u.txt" assert self.my_options.save_rainfall == None assert self.my_options.use_runoff == "runoff_u.txt" assert self.my_options.save_runoff == None assert self.my_options.use_hotstart == "hotstart_u.txt" assert self.my_options.save_hotstart == "hotstart_s.txt" assert self.my_options.use_rdii == "rdii_u.txt" assert self.my_options.save_rdii == None assert self.my_options.use_inflows == "inflows_u.txt" assert self.my_options.save_outflows == "outflows_s.txt" assert self.my_options.matches(test_all_opts) actual_text = self.my_options.get_text() self.my_options.set_text(actual_text) assert self.my_options.matches(test_all_opts)
def test_default(self): """Test default""" #20160407xw: if default, all nones, therefore no text self.my_options = Files() name = self.my_options.SECTION_NAME assert name == "[FILES]" actual_text = self.my_options.get_text() assert actual_text == ""
def test_filename_with_path(self): """Test filename with path""" self.my_options = Files() TEST_TEXT = "[FILES]\n"\ ";;Interfacing Files\n"\ "SAVE OUTFLOWS .\My Documents\save_outflows.txt" self.my_options.set_text(TEST_TEXT) assert self.my_options.use_rainfall is None assert self.my_options.save_outflows == ".\My Documents\save_outflows.txt" assert self.my_options.matches(TEST_TEXT)
def test_space_in_filename(self): """Test space in file name """ self.my_options = Files() TEST_TEXT = "[FILES]\n"\ ";;Interfacing Files\n"\ "SAVE OUTFLOWS save outflows.txt" self.my_options.set_text(TEST_TEXT) assert self.my_options.use_rainfall is None assert self.my_options.save_outflows == "save outflows.txt" # ---Space in file name assert self.my_options.matches(TEST_TEXT)
def test_more_space(self): """Test more spaces beyond [:19]""" self.my_options = Files() TEST_TEXT = "[FILES]\n"\ ";;Interfacing Files\n"\ "SAVE OUTFLOWS save_outflows.txt" self.my_options.set_text(TEST_TEXT) assert self.my_options.use_rainfall is None assert self.my_options.save_outflows == "save_outflows.txt" assert self.my_options.matches(TEST_TEXT)
def test_space_delimited(self): """normal space delimited keyword and parameter""" self.my_options = Files() TEST_TEXT = "[FILES]\n"\ ";;Interfacing Files\n"\ "USE RAINFALL use_rainfall.txt" self.my_options.set_text(TEST_TEXT) assert self.my_options.use_rainfall == "use_rainfall.txt" assert self.my_options.save_rainfall is None assert self.my_options.save_outflows is None assert self.my_options.matches(TEST_TEXT)
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_interface_files(self): """Test FILES options using the Section class""" self.my_options = Files() name = self.my_options.SECTION_NAME assert name == "[FILES]" actual_text = self.my_options.get_text() # Expect blank section when there are no contents for the section assert actual_text == '' self.my_options.save_outflows = "save_outflows.txt" expected_text = self.my_options.SECTION_NAME + '\n' + self.my_options.comment expected_text += "\nSAVE OUTFLOWS \tsave_outflows.txt" actual_text = self.my_options.get_text() assert Section.match_omit(actual_text, expected_text, " \t-")
def test_interface_files(self): """Test FILES options using the Section class""" my_options = Files() name = my_options.SECTION_NAME assert name == "[FILES]" actual_text = self.write_files.as_text(my_options) # Expect blank section when there are no contents for the section assert actual_text == '' my_options.save_outflows = "save_outflows.txt" expected_text = my_options.SECTION_NAME + '\n' + my_options.comment expected_text += "\nSAVE OUTFLOWS \tsave_outflows.txt" my_options = self.read_files.read(expected_text) actual_text = self.write_files.as_text(my_options) msg = '\nSet:' + expected_text + '\nGet:' + actual_text self.assertTrue(match(actual_text, expected_text), msg)
class OptionsInterfaceFilesTest(unittest.TestCase): def __init__(self): unittest.TestCase.__init__(self) self.my_options = Files() def setUp(self): self.my_options = files.Files() def runTest(self): name = self.my_options.SECTION_NAME assert name == "[FILES]" expected_text = self.my_options.SECTION_NAME + '\n' + self.my_options.comment actual_text = self.my_options.get_text() assert actual_text == expected_text self.my_options.save_outflows = "save_outflows.txt" expected_text += "\nSAVE OUTFLOWS \tsave_outflows.txt" actual_text = self.my_options.get_text() assert actual_text.replace(' ', '') == expected_text.replace(' ', '')
def __init__(self): """Define the fields of a SWMM Project by creating an empty placeholder for each section""" ProjectBase.__init__(self) self.title = Title() # TITLE project title self.options = General() # OPTIONS analysis options self.report = Report() # REPORT output reporting instructions self.files = Files() # FILES interface file options self.backdrop = BackdropOptions( ) # BACKDROP bounding rectangle and file name of backdrop image self.map = MapOptions( ) # MAP map's bounding rectangle and units self.raingages = SectionAsList( "[RAINGAGES]" ) # (list of RainGage) # RAINGAGES rain gage information self.hydrographs = SectionAsList( "[HYDROGRAPHS]") # (list of UnitHydrograph) # unit hydrograph data used to construct RDII inflows self.evaporation = Evaporation() # EVAPORATION evaporation data self.temperature = Temperature( ) # TEMPERATURE air temperature and snow melt data self.adjustments = Adjustments( ) # ADJUSTMENTS monthly climate adjustments self.subcatchments = SectionAsList( "[SUBCATCHMENTS]") # (list of Subcatchment) # basic subcatchment information # self.subareas = [Section] # SUBAREAS subcatchment impervious/pervious sub-area data self.infiltration = SectionAsList("[INFILTRATION]") # (list of str) # subcatchment infiltration parameters self.lid_controls = SectionAsList( "[LID_CONTROLS]") # (list of LIDControl) # low impact development control information self.lid_usage = SectionAsList("[LID_USAGE]") # (list of LIDUsage) # assignment of LID controls to subcatchments self.aquifers = SectionAsList("[AQUIFERS]") # (list of Aquifer) # groundwater aquifer parameters self.groundwater = SectionAsList( "[GROUNDWATER]") # (list of Groundwater) # subcatchment groundwater parameters self.snowpacks = SectionAsList("[SNOWPACKS]") # (list of SnowPack) # subcatchment snow pack parameters self.junctions = SectionAsList("[JUNCTIONS]") # (list of Junction) # junction node information self.outfalls = SectionAsList("[OUTFALLS]") # (list of Outfall) # outfall node information self.dividers = SectionAsList("[DIVIDERS]") # (list of Divider) # flow divider node information self.storage = SectionAsList("[STORAGE]") # (list of StorageUnit) # storage node information self.conduits = SectionAsList("[CONDUITS]") # (list of Conduit) # conduit link information self.pumps = SectionAsList("[PUMPS]") # (list of Pump) # pump link information self.orifices = SectionAsList("[ORIFICES]") # (list of Orifice) # orifice link information self.weirs = SectionAsList("[WEIRS]") # (list of Weir) # weir link information self.outlets = SectionAsList("[OUTLETS]") # (list of Outlet) # outlet link information self.xsections = SectionAsList("[XSECTIONS]") # (list of CrossSection) # conduit, orifice, and weir cross-section geometry self.transects = Transects( ) # transect geometry for conduits with irregular cross-sections self.controls = Controls() # rules that control pump and regulator operation self.events = SectionAsList("[EVENTS]") # (list of Events) self.landuses = SectionAsList( "[LANDUSES]") # (list of Landuse) # land use categories self.buildup = SectionAsList("[BUILDUP]") # (list of Buildup) # buildup functions for pollutants and land uses self.washoff = SectionAsList("[WASHOFF]") # (list of Washoff) # washoff functions for pollutants and land uses self.pollutants = SectionAsList("[POLLUTANTS]") # (list of Pollutant) # pollutant information self.coverages = Coverages( ) # COVERAGES assignment of land uses to subcatchments self.treatment = SectionAsList("[TREATMENT]") # (list of Treatment) # pollutant removal functions at conveyance system nodes self.inflows = SectionAsList("[INFLOWS]") # (list of DirectInflow) # INFLOWS # external hydrograph/pollutograph inflow at nodes self.dwf = SectionAsList("[DWF]") # (list of DryWeatherInflow) # baseline dry weather sanitary inflow at nodes self.patterns = SectionAsList("[PATTERNS]") # (list of Pattern) # periodic variation in dry weather inflow self.rdii = SectionAsList("[RDII]") # (list of RDIInflow) # rainfall-dependent I/I information at nodes self.loadings = InitialLoadings() # initial pollutant loads on subcatchments self.curves = SectionAsList("[CURVES]") # (list of Curve) # CURVES x-y tabular data referenced in other sections self.timeseries = SectionAsList("[TIMESERIES]") # (list of TimeSeries) # time series data referenced in other sections self.labels = SectionAsList("[LABELS]") # (list of Label) # X, Y coordinates and text of labels self.subcentroids = SectionAsList( "[SUBCENTROIDS]") # (list of subcentroids) # X, Y coordinates and text of subcentroids self.sublinks = SectionAsList("[SUBLINKS]") # (list of sublinks) # sublinks information self.sections = [ self.title, self.options, self.evaporation, self.raingages, self.subcatchments, self.infiltration, self.junctions, self.dividers, self.storage, self.outfalls, self.conduits, self.pumps, self.orifices, self.weirs, self.outlets, self.xsections, self.landuses, self.coverages, self.pollutants, self.timeseries, self.patterns, self.curves, self.dwf, self.rdii, self.loadings, self.buildup, self.washoff, self.report, self.events, self.files, self.backdrop, self.map, self.hydrographs, self.temperature, self.adjustments, self.lid_controls, self.lid_usage, self.aquifers, self.groundwater, self.snowpacks, self.transects, self.controls, self.treatment, self.inflows, self.labels, self.subcentroids, self.sublinks ] # Start with a sensible order of sections. self.add_sections_from_attributes( ) # Add any sections not added in the line above, should not be any left.
def __init__(self): unittest.TestCase.__init__(self) self.my_options = Files()
class SimpleFilesTest(unittest.TestCase): """Test FILES section""" def test_default(self): """Test default""" #20160407xw: if default, all nones, therefore no text self.my_options = Files() name = self.my_options.SECTION_NAME assert name == "[FILES]" actual_text = self.my_options.get_text() assert actual_text == "" def test_space_delimited(self): """normal space delimited keyword and parameter""" self.my_options = Files() TEST_TEXT = "[FILES]\n"\ ";;Interfacing Files\n"\ "USE RAINFALL use_rainfall.txt" self.my_options.set_text(TEST_TEXT) assert self.my_options.use_rainfall == "use_rainfall.txt" assert self.my_options.save_rainfall is None assert self.my_options.save_outflows is None assert self.my_options.matches(TEST_TEXT) def test_more_space(self): """Test more spaces beyond [:19]""" self.my_options = Files() TEST_TEXT = "[FILES]\n"\ ";;Interfacing Files\n"\ "SAVE OUTFLOWS save_outflows.txt" self.my_options.set_text(TEST_TEXT) assert self.my_options.use_rainfall is None assert self.my_options.save_outflows == "save_outflows.txt" assert self.my_options.matches(TEST_TEXT) def test_space_in_filename(self): """Test space in file name """ self.my_options = Files() TEST_TEXT = "[FILES]\n"\ ";;Interfacing Files\n"\ "SAVE OUTFLOWS save outflows.txt" self.my_options.set_text(TEST_TEXT) assert self.my_options.use_rainfall is None assert self.my_options.save_outflows == "save outflows.txt" # ---Space in file name assert self.my_options.matches(TEST_TEXT) def test_filename_with_path(self): """Test filename with path""" self.my_options = Files() TEST_TEXT = "[FILES]\n"\ ";;Interfacing Files\n"\ "SAVE OUTFLOWS .\My Documents\save_outflows.txt" self.my_options.set_text(TEST_TEXT) assert self.my_options.use_rainfall is None assert self.my_options.save_outflows == ".\My Documents\save_outflows.txt" assert self.my_options.matches(TEST_TEXT) def test_all_options(self): """Test all options of FILE section""" self.my_options = Files() test_all_opts = """ [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 """ self.my_options.set_text(test_all_opts) assert self.my_options.use_rainfall == "rainfall_u.txt" assert self.my_options.save_rainfall == None assert self.my_options.use_runoff == "runoff_u.txt" assert self.my_options.save_runoff == None assert self.my_options.use_hotstart == "hotstart_u.txt" assert self.my_options.save_hotstart == "hotstart_s.txt" assert self.my_options.use_rdii == "rdii_u.txt" assert self.my_options.save_rdii == None assert self.my_options.use_inflows == "inflows_u.txt" assert self.my_options.save_outflows == "outflows_s.txt" assert self.my_options.matches(test_all_opts) actual_text = self.my_options.get_text() self.my_options.set_text(actual_text) assert self.my_options.matches(test_all_opts) def test_interface_files(self): """Test FILES options using the Section class""" self.my_options = Files() name = self.my_options.SECTION_NAME assert name == "[FILES]" actual_text = self.my_options.get_text() # Expect blank section when there are no contents for the section assert actual_text == '' self.my_options.save_outflows = "save_outflows.txt" expected_text = self.my_options.SECTION_NAME + '\n' + self.my_options.comment expected_text += "\nSAVE OUTFLOWS \tsave_outflows.txt" actual_text = self.my_options.get_text() assert Section.match_omit(actual_text, expected_text, " \t-")
def __init__(self): """Define the fields of a SWMM Project by creating an empty placeholder for each section""" self.title = Title() # TITLE project title self.options = General() # OPTIONS analysis options self.report = Report() # REPORT output reporting instructions self.files = Files() # FILES interface file options self.backdrop = BackdropOptions( ) # BACKDROP bounding rectangle and file name of backdrop image self.map = MapOptions( ) # MAP map's bounding rectangle and units # self.raingages = [RainGage] # RAINGAGES rain gage information self.hydrographs = SectionAsListGroupByID( "[HYDROGRAPHS]", UnitHydrograph, ";;Hydrograph \tRain Gage/Month \tResponse\tR \tT \tK \tDmax \tDrecov \tDinit \n" ";;--------------\t----------------\t--------\t--------\t--------\t--------\t--------\t--------\t--------" ) # unit hydrograph data used to construct RDII inflows self.evaporation = Evaporation() # EVAPORATION evaporation data self.temperature = Temperature( ) # TEMPERATURE air temperature and snow melt data self.adjustments = Adjustments( ) # ADJUSTMENTS monthly climate adjustments self.subcatchments = SectionAsListOf( "[SUBCATCHMENTS]", Subcatchment, ";;Name \tRain Gage \tOutlet \tArea \t%Imperv \tWidth \t%Slope \tCurbLen \tSnowPack \n" ";;--------------\t----------------\t----------------\t--------\t--------\t--------\t--------\t--------\t----------------" ) # basic subcatchment information # self.subareas = [Section] # SUBAREAS subcatchment impervious/pervious sub-area data self.infiltration = SectionAsListOf("[INFILTRATION]", basestring) # This is set to SectionAsListOf HortonInfiltration or GreenAmptInfiltration or CurveNumberInfiltration on read # subcatchment infiltration parameters self.lid_controls = SectionAsListGroupByID( "[LID_CONTROLS]", LIDControl, ";;Name \tType/Layer\tParameters\n" ";;--------------\t----------\t----------") # low impact development control information self.lid_usage = SectionAsListOf( "[LID_USAGE]", LIDUsage, ";;Subcatchment \tLID Process \tNumber \tArea \tWidth \tInitSat \tFromImp \tToPerv \tRptFile \tDrainTo\n" ";;--------------\t----------------\t-------\t----------\t----------\t----------\t----------\t----------\t------------------------\t----------------" ) # assignment of LID controls to subcatchments self.aquifers = SectionAsListOf( "[AQUIFERS]", Aquifer, ";;Aquifer \tPhi \tWP \tFC \tHydCon\tKslope\tTslope\tUEF \tLED \tLGLR \tBEL \tWTEL \tUZM \tUEF Pat\n" ";;--------------\t------\t------\t------\t------\t------\t------\t------\t------\t------\t------\t------\t------\t-------" ) # groundwater aquifer parameters self.groundwater = SectionAsListOf( "[GROUNDWATER]", Groundwater, ";;Subcatchment \tAquifer \tNode \tEsurf \tA1 \tB1 \tA2 \tB2 \tA3 \tDsw \tEgwt \tEbot \tWgr \tUmc \n" ";;--------------\t----------------\t----------------\t------\t------\t------\t------\t------\t------\t------\t------\t------\t------\t------" ) # subcatchment groundwater parameters self.snowpacks = SectionAsListGroupByID( "[SNOWPACKS]", SnowPack, ";;Name \tSurface \tParameters\n" ";;--------------\t----------\t----------") # subcatchment snow pack parameters self.junctions = SectionAsListOf( "[JUNCTIONS]", Junction, ";;Name \tElevation \tMaxDepth \tInitDepth \tSurDepth \tAponded\n" ";;--------------\t----------\t----------\t----------\t----------\t----------" ) # junction node information # self.outfalls = [Outfall] # OUTFALLS # outfall node information # self.dividers = [Divider] # DIVIDERS # flow divider node information # self.storage = [StorageUnit] # STORAGE # storage node information self.conduits = SectionAsListOf( "[CONDUITS]", Conduit, ";;Name \tFrom Node \tTo Node \tLength \tRoughness \tInOffset \tOutOffset \tInitFlow \tMaxFlow \n" ";;--------------\t----------------\t----------------\t----------\t----------\t----------\t----------\t----------\t----------" ) # conduit link information self.pumps = SectionAsListOf( "[PUMPS]", Pump, ";;Name \tFrom Node \tTo Node \tPump Curve \tStatus \tStartup \tShutoff \n" ";;--------------\t----------------\t----------------\t----------------\t--------\t--------\t--------" ) # pump link information # self.orifices = [Orifice] # ORIFICES # orifice link information # self.weirs = [Weir] # WEIRS # weir link information # self.outlets = [Outlet] # OUTLETS # outlet link information self.xsections = SectionAsListOf( "[XSECTIONS]", CrossSection, ";;Link \tShape \tGeom1 \tGeom2 \tGeom3 \tGeom4 \tBarrels \tCulvert \n" ";;--------------\t------------\t----------------\t----------\t----------\t----------\t----------\t----------" ) # conduit, orifice, and weir cross-section geometry self.transects = Transects( ) # TRANSECTS # transect geometry for conduits with irregular cross-sections # self.losses = [Section] # LOSSES # conduit entrance/exit losses and flap valves self.controls = SectionAsListOf( "[CONTROLS]", basestring) # rules that control pump and regulator operation self.landuses = SectionAsListOf( "[LANDUSES]", Landuse, ";; \tSweeping \tFraction \tLast\n" ";;Name \tInterval \tAvailable \tSwept\n" ";;--------------\t----------\t----------\t----------") # land use categories self.buildup = SectionAsListOf( "[BUILDUP]", Buildup, ";;Land Use \tPollutant \tFunction \tCoeff1 \tCoeff2 \tCoeff3 \tPer Unit\n" ";;--------------\t----------------\t----------\t----------\t----------\t----------\t----------" ) # buildup functions for pollutants and land uses self.washoff = SectionAsListOf( "[WASHOFF]", Washoff, ";;Land Use \tPollutant \tFunction \tCoeff1 \tCoeff2 \tSweepRmvl \tBmpRmvl\n" ";;--------------\t----------------\t----------\t----------\t----------\t----------\t----------" ) # washoff functions for pollutants and land uses self.pollutants = SectionAsListOf( "[POLLUTANTS]", Pollutant, ";;Name \tUnits \tCrain \tCgw \tCrdii \tKdecay \tSnowOnly \tCo-Pollutant \tCo-Frac \tCdwf \tCinit\n" ";;--------------\t------\t----------\t----------\t----------\t----------\t----------\t----------------\t----------\t----------\t----------" ) # pollutant information self.coverages = Coverages( ) # COVERAGES # assignment of land uses to subcatchments self.treatment = SectionAsListOf( "[TREATMENT]", Treatment, ";;Node \tPollutant \tFunction\n" ";;--------------\t----------------\t--------") # pollutant removal functions at conveyance system nodes self.inflows = SectionAsListOf( "[INFLOWS]", DirectInflow, ";;Node \tConstituent \tTime Series \tType \tMfactor \tSfactor \tBaseline\tPattern\n" ";;--------------\t----------------\t----------------\t--------\t--------\t--------\t--------\t--------" ) # INFLOWS # external hydrograph/pollutograph inflow at nodes self.dwf = SectionAsListOf( "[DWF]", DryWeatherInflow, ";;Node \tConstituent \tBaseline \tPatterns \n" ";;--------------\t----------------\t----------\t----------") # baseline dry weather sanitary inflow at nodes self.patterns = SectionAsListGroupByID( "[PATTERNS]", Pattern, ";;Name \tType \tMultipliers\n" ";;--------------\t----------\t-----------") # PATTERNS periodic variation in dry weather inflow self.rdii = SectionAsListOf( "[RDII]", RDIInflow, ";;Node \tUnit Hydrograph \tSewer Area\n" ";;--------------\t----------------\t----------") # rainfall-dependent I/I information at nodes self.loadings = SectionAsListOf( "[LOADINGS]", InitialLoading, ";;Subcatchment \tPollutant \tBuildup\n" ";;--------------\t----------------\t----------") # initial pollutant loads on subcatchments self.curves = SectionAsListGroupByID( "[CURVES]", Curve, ";;Name \tType \tX-Value \tY-Value \n" ";;--------------\t----------\t----------\t----------") # CURVES x-y tabular data referenced in other sections self.timeseries = SectionAsListGroupByID( "[TIMESERIES]", TimeSeries, ";;Name \tDate \tTime \tValue\n" ";;--------------\t----------\t----------\t----------") # time series data referenced in other sections # self.polygons = [Section] # POLYGONS # X,Y coordinates for each vertex of subcatchment polygons # self.coordinates = [Section] # COORDINATES # X,Y coordinates for nodes # self.vertices = [Section] # VERTICES # X,Y coordinates for each interior vertex of polyline links # self.labels = [Section] # LABELS # X,Y coordinates and text of labels # self.symbols = [Section] # SYMBOLS # X,Y coordinates for rain gages # X,Y coordinates of the bounding rectangle and file name of the backdrop image. # [TAGS] InputFile.__init__( self ) # Do this after setting attributes so they will all get added to sections[]