Esempio n. 1
0
    def test_Issue71(self):
        """Test issue #71 in github - cbo changes should update ok button."""
        # See https://github.com/AIFDR/inasafe/issues/71
        # Push OK with the left mouse button
        print 'Using QGIS: %s' % qgisVersion()
        self.tearDown()
        myButton = DOCK.pbnRunStop
        # First part of scenario should have enabled run
        myFileList = [join(HAZDATA,
                           'Flood_Current_Depth_Jakarta_geographic.asc'),
                      join(TESTDATA,
                           'Population_Jakarta_geographic.asc')]
        myHazardLayerCount, myExposureLayerCount = loadLayers(myFileList,
                                                              DIR=None)

        myMessage = ('Incorrect number of Hazard layers: expected 1 got %s'
                     % myHazardLayerCount)
        assert myHazardLayerCount == 1, myMessage

        myMessage = ('Incorrect number of Exposure layers: expected 1 got %s'
                     % myExposureLayerCount)
        assert myExposureLayerCount == 1, myMessage
        myMessage = 'Run button was not enabled'
        assert myButton.isEnabled(), myMessage

        # Second part of scenario - run disabled when adding invalid layer
        # and select it - run should be disabled
        myFileList = ['issue71.tif']  # This layer has incorrect keywords
        myClearFlag = False
        myHazardLayerCount, myExposureLayerCount = (
            loadLayers(myFileList, myClearFlag))
        # set exposure to : Population Density Estimate (5kmx5km)
        QTest.keyClick(DOCK.cboExposure, QtCore.Qt.Key_Down)
        QTest.keyClick(DOCK.cboExposure, QtCore.Qt.Key_Enter)
        myDict = getUiState(DOCK)
        myExpectedDict = {'Run Button Enabled': False,
                          'Impact Function': '',
                          'Hazard': 'A flood in Jakarta like in 2007',
                          'Exposure': 'Population density (5kmx5km)'}
        myMessage = ('Run button was not disabled when exposure set to \n%s'
                     '\nUI State: \n%s\nExpected State:\n%s\n%s') % (
            DOCK.cboExposure.currentText(),
            myDict,
            myExpectedDict,
            combosToString(DOCK))

        assert myExpectedDict == myDict, myMessage

        # Now select again a valid layer and the run button
        # should be enabled
        QTest.keyClick(DOCK.cboExposure, QtCore.Qt.Key_Up)
        QTest.keyClick(DOCK.cboExposure, QtCore.Qt.Key_Enter)
        myMessage = 'Run button was not enabled when exposure set to \n%s' % \
            DOCK.cboExposure.currentText()
        assert myButton.isEnabled(), myMessage
Esempio n. 2
0
    def areKeywordsFileBased(self, theLayer):
        """Find out if keywords should be read/written to file or our keywords
          db.

        Args:
            * theLayer - A QGIS QgsMapLayer instance.

        Returns:
            True if keywords are storedin a file next to the dataset,
            else False if the dataset is remove e.g. a database.
        Raises:
            None
        """
        # determine which keyword lookup system to use (file base or cache db)
        # based on the layer's provider type. True indicates we should use the
        # datasource as a file and look for a keywords file, false and we look
        # in the keywords db.
        myProviderType = None
        myVersion = qgisVersion()
        # check for old raster api with qgis < 1.8
        # ..todo:: Add test for plugin layers too
        if (myVersion < 10800 and theLayer.type() == QgsMapLayer.RasterLayer):
            myProviderType = str(theLayer.providerKey())
        else:
            myProviderType = str(theLayer.providerType())

        myProviderDict = {
            'ogr': True,
            'gdal': True,
            'gpx': False,
            'wms': False,
            'spatialite': False,
            'delimitedtext': True,
            'postgres': False
        }
        myFileBasedKeywords = False
        if myProviderType in myProviderDict:
            myFileBasedKeywords = myProviderDict[myProviderType]
        return myFileBasedKeywords
Esempio n. 3
0
 def test_getQgisVersion(self):
     """Test we can get the version of QGIS"""
     myVersion = qgisVersion()
     myMessage = 'Got version %s of QGIS, but at least 107000 is needed'
     assert myVersion > 10700, myMessage
Esempio n. 4
0
    def test_issue_160(self):
        """Test that multipart features can be used in a scenario - issue #160
        """
        myTestDataDir = os.path.join(os.path.dirname(__file__), '..',
                                     'unit_test_data')
        myExposure = os.path.join('exposure', 'buildings_osm_4326.shp')
        myHazard = os.path.join('hazard', 'multipart_polygons_osm_4326.shp')
                # See https://github.com/AIFDR/inasafe/issues/71
        # Push OK with the left mouse button
        print 'Using QGIS: %s' % qgisVersion()
        self.tearDown()
        myButton = DOCK.pbnRunStop
        # First part of scenario should have enabled run
        myFileList = [myHazard, myExposure]
        myHazardLayerCount, myExposureLayerCount = loadLayers(myFileList,
                                                            DIR=myTestDataDir)

        myMessage = ('Incorrect number of Hazard layers: expected 1 got %s'
                     % myHazardLayerCount)
        assert myHazardLayerCount == 1, myMessage

        myMessage = ('Incorrect number of Exposure layers: expected 1 got %s'
                     % myExposureLayerCount)
        assert myExposureLayerCount == 1, myMessage

        myMessage = 'Run button was not enabled'
        assert myButton.isEnabled(), myMessage

        # Second part of scenario - run disabled when adding invalid layer
        # and select it - run should be disabled
        myFileList = ['issue71.tif']  # This layer has incorrect keywords
        myClearFlag = False
        myHazardLayerCount, myExposureLayerCount = (
            loadLayers(myFileList, myClearFlag))
        # Hazard layers  -multipart_polygons_4326
        myIndex = DOCK.cboHazard.findText('multipart_polygons_osm_4326')
        assert myIndex != -1, 'multipart_polygons_4326 hazard layer not found'
        DOCK.cboHazard.setCurrentIndex(myIndex)
        # Exposure layers - buildings_osm_4326
        myIndex = DOCK.cboExposure.findText('buildings_osm_4326')
        assert myIndex != -1, 'buildings_osm_4326 exposure layer not found'
        DOCK.cboExposure.setCurrentIndex(myIndex)
        myDict = getUiState(DOCK)
        myExpectedDict = {'Run Button Enabled': True,
                          'Impact Function': 'Flood Building Impact Function',
                          'Hazard': 'multipart_polygons_osm_4326',
                          'Exposure': 'buildings_osm_4326'}
        myMessage = ('Run button was not disabled when exposure set to \n%s'
                     '\nUI State: \n%s\nExpected State:\n%s\n%s') % (
            DOCK.cboExposure.currentText(),
            myDict,
            myExpectedDict,
            combosToString(DOCK))

        assert myExpectedDict == myDict, myMessage

        # Enable on-the-fly reprojection
        setCanvasCrs(GEOCRS, True)
        IFACE.mapCanvas().setExtent(
                                QgsRectangle(106.788, -6.193, 106.853, -6.167))

        # Press RUN
        QTest.mouseClick(myButton, QtCore.Qt.LeftButton)
        myResult = DOCK.wvResults.page().currentFrame().toPlainText()

        myMessage = 'Result not as expected: %s' % myResult
        assert '68' in myResult, myMessage