示例#1
0
    def test_files(self):
        print('Testing no_duplicates=True files count...')
        test_filecounts = {
            'TCF': 13,
            'ECF': 4,
            'TGC': 14,
            'TBC': 2,
        }
        for key, c in self.tuflow.control_files.items():
            print('Checking model_type: ' + key + '...')
            vars = c.files()
            utils.softAssertion(len(vars), test_filecounts[key])
        print('Done')

        print('Testing no_duplicates=False files count...')
        test_filecounts = {
            'TCF': 14,
            'ECF': 4,
            'TGC': 23,
            'TBC': 4,
        }
        for key, c in self.tuflow.control_files.items():
            print('Checking model_type: ' + key + '...')
            vars = c.files(no_duplicates=False)
            utils.softAssertion(len(vars), test_filecounts[key])
        print('Done')
示例#2
0
    def test_variables(self):
        print('Testing no_duplicates=True variables count...')
        test_varcounts = {
            'TCF': 16,
            'ECF': 6,
            'TGC': 6,
            'TBC': 0,
        }
        for key, c in self.tuflow.control_files.items():
            print('Checking model_type: ' + key + '...')
            vars = c.variables()
            utils.softAssertion(len(vars), test_varcounts[key])
        print('Done')

        print('Testing no_duplciates=False variables count...')
        test_varcounts = {
            'TCF': 18,
            'ECF': 6,
            'TGC': 9,
            'TBC': 0,
        }
        for key, c in self.tuflow.control_files.items():
            print('Checking model_type: ' + key + '...')
            vars = c.variables(no_duplicates=False)
            utils.softAssertion(len(vars), test_varcounts[key])
        print('Done')
示例#3
0
    def test_datWrite(self):
        print('Test writing DatCollection model...')
        cwd = os.path.join(os.getcwd(), 'integration_tests', 'test_output')
        need_dirs = [
            cwd,
            os.path.join(cwd, 'asread'),
            os.path.join(cwd, 'asread/model1'),
            os.path.join(cwd, 'asread/model1/fmp'),
        ]
        try:
            for n in need_dirs:
                if not os.path.isdir(n):
                    os.mkdir(n)
        except IOError:
            print('\t Could not make test directeries - aborting test')
            print('\nFail!\n')

        outpath = os.path.join(need_dirs[-1],
                               self.dat.path_holder.filenameAndExtension())

        # Write the dat file once to start with - use overwrite in case it exists
        self.dat.write(outpath, overwrite=True)

        # Then hopefully this fails without overwrite set to true
        error_raised = False
        try:
            self.dat.write(outpath)
        except IOError:
            error_raised = True
        utils.softAssertion(error_raised, True)

        # Then a final check to make sure overwrite is working
        self.dat.write(outpath, overwrite=True)

        print('Done')
示例#4
0
    def test_addTcfModelFile(self):
        """Check that we can add a new file to the TCF properly.
        
        Involves adding the part to the TCF ControlFile, loading the contents
        of the actual control file on disk, and putting the contents in the
        corrent location.
        """
        print('Testing add tcf ModelFile...')

        tuflow = copy.deepcopy(self.tuflow)
        loader = TuflowLoader()
        tcf = tuflow.control_files['TCF']
        geom = tcf.contains(command='Geometry Control')[0]

        line = "Geometry Control File == ..\\model\\test_tgc2.tgc"
        tgc_part = factory.TuflowFactory.getTuflowPart(line, tcf.mainfile)[0]
        tgc_control = loader.loadControlFile(tgc_part)
        tcf.addControlFile(tgc_part, tgc_control, after=geom)

        utils.softAssertionIn(tgc_part,
                              tuflow.control_files['TGC'].control_files)

        test_part = tuflow.control_files['TGC'].contains(
            filename='shiptest_tgc2_v1_DTM_2m')
        utils.softAssertion(len(test_part), 1)

        index = tcf.parts.index(tgc_part)
        utils.softAssertion(index, tcf.parts.index(geom) + 1)
        del tuflow

        print('Done')
示例#5
0
    def test_changeActiveStatus(self):
        print('Testing update active status...')
        tuflow = copy.deepcopy(self.tuflow)
        control = tuflow.control_files['TGC']

        # Make sure we know what it is before
        zpt_part = control.contains(command="Set Zpts",
                                    variable="2",
                                    parent_filename="test_trd2")
        zln_part = control.contains(command="Z Line THIN",
                                    filename="zln_shiptest_trd_v2")
        parts = zpt_part + zln_part
        utils.softAssertion(len(parts), 3)

        trd = control.contains(filename="test_trd2")[0]
        trd.active = False

        # Then check after
        zpt_part = control.contains(command="Set Zpts",
                                    variable="2",
                                    parent_filename="test_trd2")
        zln_part = control.contains(command="Z Line THIN",
                                    filename="zln_shiptest_trd_v2")
        parts = zpt_part + zln_part
        utils.softAssertion(len(parts), 0)

        print('Done')
示例#6
0
 def loadTuflowModel(self):
     print('Loading tuflow model...')
     path = "integration_tests/test_data/model1/tuflow/runs/test_run1.tcf"
     path = os.path.normpath(os.path.join(os.getcwd(), path))
     loader = fileloader.FileLoader()
     self.tuflow = loader.loadFile(path)
     utils.softAssertion(self.tuflow.missing_model_files, [])
     print('Tuflow model load complete.')
示例#7
0
 def test_nonExistingControlFiles(self):
     """Checks that a model still loads and returns the missing files.
     
     When a TuflowModel is loaded but can't find one or more of the control
     files on disk it should finish the load and set the missing_model_files
     variables to a list with the missing file paths.
     """
     test_files = [
         os.path.normpath(
             os.path.join(self.tuflow.root,
                          "..\\model\\test_tgc_NOEXIST.tgc")),
         os.path.normpath(
             os.path.join(self.tuflow.root,
                          "..\\model\\test_tbc_NOEXIST.tbc")),
     ]
     utils.softAssertion(set(self.tuflow.missing_model_files),
                         set(test_files))
示例#8
0
    def runTests(self):

        cwd = os.getcwd()
        path1 = "integration_tests/test_data/model1/tuflow/runs/test_run1.tcf"
        path2 = "integration_tests/test_data/model1/tuflow/runs/test_run_noexist.tcf"
        main_path = os.path.normpath(os.path.join(cwd, path1))
        missing_path = os.path.normpath(os.path.join(cwd, path2))

        self.loadTuflowModel(missing_path)
        self.test_nonExistingControlFiles()
        del self.tuflow

        self.loadTuflowModel(main_path)
        utils.softAssertion(self.tuflow.missing_model_files, [])
        #         self.test_deactiveLogic()
        self.test_writeTuflowModel()
        self.test_controlFileTypes()
        self.test_allFilepaths()
        self.test_variables()
        self.test_files()
        self.test_seVals()
示例#9
0
    def test_removePartFromLogicHolder(self):
        print('Testing remove part to LogicHolder...')

        #         tuflow = copy.deepcopy(self.tuflow)
        tuflow = self.tuflow
        control = tuflow.control_files['TGC']
        tgc = None
        for c in control.control_files:
            if c.filename == 'test_tgc1': tgc = c

        part1 = control.contains(command='Timestep', variable='12')[0]
        logic1 = part1.associates.logic
        group = logic1.getGroup(part1)

        logic1.removePart(part1)

        part1_index = control.parts.index(part1)

        last_part = logic1.group_parts[-1][-1]
        last_index = control.parts.index(last_part)
        utils.softAssertion(logic1.getGroup(part1), -1)
        utils.softAssertion(part1.associates.logic, logic1, False)
        utils.softAssertion(control.parts[last_index + 1], part1)

        print('Done')
示例#10
0
    def test_seVals(self):
        print('Testing se_vals filepaths keys...')
        se_vals = self.tuflow.user_variables.seValsToDict()
        test_paths = [
            '2d_loc_shiptest_tgc_v1_L.shp', '2d_code_shiptest_tgc_v1_R.shp',
            '2d_bc_hx_shiptest_tgc_v1_R.shp',
            '2d_whatevs_shiptest_tgc_v2_P.shp', 'test_trd1.trd',
            '2d_zln_shiptest_trd_v1_L.shp', '2d_zln_shiptest_trd_v1_P.shp',
            'some_zshp_trd_v1_R.shp', 'summit_event_zln_trd_v2_L.shp',
            'test_trd2.trd', '2d_zln_shiptest_trd_v2_L.shp',
            '2d_zln_shiptest_trd_v2_P.shp', 'shiptest_tgc_v1_DTM_2m.asc',
            '2d_zln_shiptest_tgc_v1_L.shp', '2d_zln_shiptest_tgc_v1_P.shp',
            '2d_zpt_shiptest_tgc_v1_R.shp', '2d_mat_shiptest_tgc_v1_R.shp'
        ]
        paths = self.tuflow.control_files['TGC'].filepaths(se_vals=se_vals)
        utils.softAssertion(set(test_paths), set(paths))
        print('Done')

        print('Testing se_vals variables count...')
        vars = self.tuflow.control_files['TGC'].variables(se_vals=se_vals)
        utils.softAssertion(len(vars), 6)
        print('Done')
示例#11
0
 def test_allFilepaths(self):
     print('Testing all filepaths...')
     test_paths = {
         'TCF': [
             'materials_shiptest_v1.csv', '1d_nodes_shiptest_v1_P.shp',
             '1d_nwk_shiptest_v1_L.shp', '1d_WLL_shiptest_v1_L.shp',
             'bc_dbase_shiptest_v1.csv', 'test_run1.ecf', 'test_tgc1.tgc',
             'test_tbc1.tbc', 'test_tbc2.tbc',
             '2d_oz_ZoneA_shiptest_v1_R.shp', '2d_po_shiptest_v1_L.shp'
         ],
         'ECF': ['Projection.prj', 'bc_dbase_shiptest_v1.csv'],
         'TGC': [
             '2d_loc_shiptest_tgc_v1_L.shp',
             '2d_code_shiptest_tgc_v1_R.shp',
             '2d_bc_hx_shiptest_tgc_v1_R.shp',
             '2d_whatevs_shiptest_tgc_v1_P.shp',
             '2d_whatevs_shiptest_tgc_v2_P.shp', 'test_trd1.trd',
             '2d_zln_shiptest_trd_v1_L.shp', '2d_zln_shiptest_trd_v1_P.shp',
             'some_zshp_trd_v1_R.shp', 'some_zshp_trd_v2_R.shp',
             'summit_event_zln_trd_v1_L.shp',
             'summit_event_zln_trd_v2_L.shp', 'test_trd2.trd',
             '2d_zln_shiptest_trd_v2_L.shp', '2d_zln_shiptest_trd_v2_P.shp',
             'test_trd3.trd', '2d_zln_shiptest_trd_v3_L.shp',
             '2d_zln_shiptest_trd_v3_P.shp', 'shiptest_tgc_v1_DTM_2m.asc',
             '2d_zln_shiptest_tgc_v1_L.shp', '2d_zln_shiptest_tgc_v1_P.shp',
             '2d_zpt_shiptest_tgc_v1_R.shp', '2d_mat_shiptest_tgc_v1_R.shp'
         ],
         'TBC': [
             '2d_bc_hx_shiptest_tbc_v1_L.shp',
             '2d_bc_cn_shiptest_tbc_v1_L.shp',
             '2d_bc_hx_shiptest_tbc_v2_L.shp',
             '2d_bc_cn_shiptest_tbc_v2_L.shp'
         ],
     }
     for key, c in self.tuflow.control_files.items():
         filepaths = c.filepaths()
         print('Checking model_type: ' + key + '...')
         utils.softAssertion(set(test_paths[key]), set(filepaths))
     print('Done')
示例#12
0
    def test_addPartToLogicHolder(self):
        print('Testing add part to LogicHolder...')

        #         tuflow = copy.deepcopy(self.tuflow)
        tuflow = self.tuflow
        control = tuflow.control_files['TGC']
        tgc = None
        for c in control.control_files:
            if c.filename == 'test_tgc1': tgc = c

        part1 = control.contains(filename='whatevs_shiptest_tgc_v1_P')[0]
        logic1 = part1.associates.logic

        line = "Timestep == 12 ! timestep 12 comment"
        varpart = factory.TuflowFactory.getTuflowPart(line, tgc)[0]
        logic1.insertPart(varpart, part1)

        utils.softAssertion(varpart.associates.logic, part1.associates.logic)

        part1_index = control.parts.index(part1)
        utils.softAssertion(control.parts.index(varpart), part1_index + 1)

        print('Done')
示例#13
0
    def test_removeTcfModelFile(self):
        print('Testing delete tcf ModelFile...')

        tuflow = copy.deepcopy(self.tuflow)
        loader = TuflowLoader()
        tcf = tuflow.control_files['TCF']
        geom = tcf.contains(command='Geometry Control')[0]

        tcf.removeControlFile(geom)

        utils.softAssertion(len(tuflow.control_files['TGC'].parts.parts), 0)
        utils.softAssertion(len(tuflow.control_files['TGC'].control_files), 0)
        utils.softAssertion(len(tuflow.control_files['TGC'].logic.parts), 0)

        print('Done')
示例#14
0
    def test_removePartFromPartHolder(self):
        print('Testing remove part to LogicHolder...')

        #         tuflow = copy.deepcopy(self.tuflow)
        tuflow = self.tuflow
        control = tuflow.control_files['TGC']

        part1 = control.contains(command='Timestep', variable='12')[0]
        part2 = control.contains(command='Timestep', variable='22')[0]
        part3 = control.contains(command='Timestep', variable='32')[0]
        control.parts.remove(part1)
        control.parts.remove(part2)
        control.parts.remove(part3)

        index = control.parts.index(part1)
        index2 = control.parts.index(part2)
        index3 = control.parts.index(part3)
        utils.softAssertion(index, -1)
        utils.softAssertion(index2, -1)
        utils.softAssertion(index3, -1)

        print('Done')
示例#15
0
 def test_controlFileTypes(self):
     print('Testing control_files keys...')
     ckeys = self.tuflow.control_files.keys()
     test_keys = ['TCF', 'ECF', 'TGC', 'TBC']
     utils.softAssertion(set(ckeys), set(test_keys))
     print('Done')
示例#16
0
    def test_unitCounts(self):

        print('Test unit counts...')
        assert (len(self.dat.units) == 18)

        headers = self.dat.unitsByType('header')
        comments = self.dat.unitsByType('comment')
        refhs = self.dat.unitsByType('refh')
        rivers = self.dat.unitsByType('river')
        bridges = self.dat.unitsByCategory('bridge')
        junctions = self.dat.unitsByType('junction')
        spills = self.dat.unitsByType('spill')
        htbdys = self.dat.unitsByType('htbdy')
        unknowns = self.dat.unitsByType('unknown')
        ics = self.dat.unitsByType('initial_conditions')
        gis = self.dat.unitsByType('gis_info')

        utils.softAssertion(len(headers), 1)
        utils.softAssertion(len(comments), 1)
        utils.softAssertion(len(refhs), 1)
        utils.softAssertion(len(rivers), 6)
        utils.softAssertion(len(bridges), 2)
        utils.softAssertion(len(junctions), 2)
        utils.softAssertion(len(spills), 1)
        utils.softAssertion(len(htbdys), 1)
        utils.softAssertion(len(unknowns), 1)
        utils.softAssertion(len(ics), 1)
        utils.softAssertion(len(gis), 1)

        print('Done')
示例#17
0
    def test_addPartToPartHolder(self):
        print('Testing add part to PartHolder...')
        #         tuflow = copy.deepcopy(self.tuflow)
        tuflow = self.tuflow
        control = tuflow.control_files['TGC']
        tgc = None
        for c in control.control_files:
            if c.filename == 'test_tgc1': tgc = c

        line = "Timestep == 12 ! timestep 12 comment"
        varpart = factory.TuflowFactory.getTuflowPart(line, tgc)[0]
        line2 = "Timestep == 22 ! timestep 22 comment"
        varpart2 = factory.TuflowFactory.getTuflowPart(line2, tgc)[0]
        existing_part = control.contains(filename='test_trd2')[0]
        control.parts.add(varpart, after=existing_part)
        control.parts.add(varpart2, before=existing_part)

        line3 = "Timestep == 32 ! timestep 23 comment"
        varpart3 = factory.TuflowFactory.getTuflowPart(line3, existing_part)[0]
        control.parts.add(varpart3)

        found = False
        for i, p in enumerate(control.parts):
            if p == existing_part:
                found = True
                utils.softAssertion(control.parts[i + 1], varpart)
                utils.softAssertion(control.parts[i + 1].associates.logic,
                                    existing_part.associates.logic)
                utils.softAssertion(control.parts[i - 1], varpart2)
                utils.softAssertion(control.parts[i - 1].associates.logic,
                                    existing_part.associates.logic)
        if not found:
            raise TestError('Failed to add part to PartHolder')

        utils.softAssertion(control.parts[-1], varpart3, False)
        utils.softAssertion(varpart3.associates.parent, tgc, False)

        trd_index = control.parts.lastIndexOfParent(varpart3.associates.parent)
        utils.softAssertion(control.parts[trd_index], varpart3)

        print('Done')
示例#18
0
 def test_icsSetup(self):
     print('Test ics setup...')
     ics = self.dat.unit('initial_conditions')
     utils.softAssertion(
         len(ics.row_data['main']._collection[0].data_collection), 14)
     print('Done')