コード例 #1
0
ファイル: test_is_dock.py プロジェクト: purnamabs/inasafe
    def test_ResultStyling(self):
        """Test that ouputs from a model are correctly styled (colours and
        opacity. """

        # Push OK with the left mouse button

        myButton = DOCK.pbnRunStop

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

        # Hazard layers -already set to correct entry
        # Exposure layers - set to Penduduk Jakarta
        QTest.keyClick(DOCK.cboExposure, QtCore.Qt.Key_Down)
        QTest.keyClick(DOCK.cboExposure, QtCore.Qt.Key_Down)
        QTest.keyClick(DOCK.cboExposure, QtCore.Qt.Key_Enter)

        # Choose impact function (second item in the list)
        QTest.keyClick(DOCK.cboFunction, QtCore.Qt.Key_Down)
        QTest.keyClick(DOCK.cboFunction, QtCore.Qt.Key_Down)
        QTest.keyClick(DOCK.cboFunction, QtCore.Qt.Key_Enter)
        myFunction = DOCK.cboFunction.currentText()
        myMessage = ('Incorrect function selected - expected Terdampak,'
                     ' got %s \n%s'
                     % (myFunction, combosToString(DOCK)))
        assert myFunction == 'Need evacuation', myMessage

        # Enable on-the-fly reprojection
        setCanvasCrs(GEOCRS, True)
        setJakartaGeoExtent()

        # Run manually so we can get the output layer
        DOCK.setupCalculator()
        myRunner = DOCK.calculator.getRunner()
        myRunner.run()  # Run in same thread
        myEngineImpactLayer = myRunner.impactLayer()
        myQgisImpactLayer = DOCK.readImpactLayer(myEngineImpactLayer)
        myStyle = myEngineImpactLayer.get_style_info()
        #print myStyle
        setRasterStyle(myQgisImpactLayer, myStyle)
        # simple test for now - we could test explicity for style state
        # later if needed.
        myMessage = ('Raster layer was not assigned a ColorRampShader'
                     ' as expected.')
        assert myQgisImpactLayer.colorShadingAlgorithm() == \
                QgsRasterLayer.ColorRampShader, myMessage

        myMessage = ('Raster layer was not assigned transparency'
                     'classes as expected.')
        myTransparencyList = (myQgisImpactLayer.rasterTransparency().
                transparentSingleValuePixelList())
        #print "Transparency list:" + str(myTransparencyList)
        assert (len(myTransparencyList) > 0)
コード例 #2
0
ファイル: test_is_dock.py プロジェクト: purnamabs/inasafe
    def test_runFloodPopulationImpactFunction_scaling(self):
        """Flood function runs in GUI with 5x5km population data
           Raster on raster based function runs as expected with scaling."""

        # Push OK with the left mouse button

        myButton = DOCK.pbnRunStop

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

        # Hazard layers use default - Banjir Jakarta seperti 2007

        # Exposure layers - Population Density Estimate (5kmx5km)
        QTest.keyClick(DOCK.cboExposure, QtCore.Qt.Key_Down)
        QTest.keyClick(DOCK.cboExposure, QtCore.Qt.Key_Down)
        QTest.keyClick(DOCK.cboExposure, QtCore.Qt.Key_Down)
        QTest.keyClick(DOCK.cboExposure, QtCore.Qt.Key_Enter)

        # Choose impact function Terdampak
        QTest.keyClick(DOCK.cboFunction, QtCore.Qt.Key_Down)
        QTest.keyClick(DOCK.cboFunction, QtCore.Qt.Key_Down)
        QTest.keyClick(DOCK.cboFunction, QtCore.Qt.Key_Enter)

        # Check that layers and impact function are correct
        myDict = getUiState(DOCK)

        myExpectedDict = {'Run Button Enabled': True,
                          'Impact Function': 'Flood Evacuation Function',
                          'Hazard': 'A flood in Jakarta like in 2007',
                          'Exposure': 'People'}
        myMessage = 'Got unexpected state: %s\nExpected: %s\n%s' % (
                            myDict, myExpectedDict, combosToString(DOCK))
        assert myDict == myExpectedDict, myMessage

        # Enable on-the-fly reprojection
        setCanvasCrs(GEOCRS, True)
        setJakartaGeoExtent()

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

        msg = 'Result not as expected: %s' % myResult

        # Check numbers are OK (within expected errors from resampling)
        assert '10484' in myResult, msg
        assert '977' in myResult, msg  # These are expected impact number
コード例 #3
0
ファイル: test_is_map.py プロジェクト: purnamabs/inasafe
    def test_renderTemplate(self):
        """Test that load template works"""
        #Use the template from our resources bundle
        myInPath = ':/plugins/inasafe/basic.qpt'
        myLayer, myType = loadLayer('test_shakeimpact.shp')
        del myType

        myCanvasLayer = QgsMapCanvasLayer(myLayer)
        CANVAS.setLayerSet([myCanvasLayer])
        myMap = ISMap(IFACE)
        setJakartaGeoExtent()
        myMap.setImpactLayer(myLayer)
        myOutPath = os.path.join(getTempDir(), 'outTemplate.pdf')
        if os.path.exists(myOutPath):
            os.remove(myOutPath)
        myMap.renderTemplate(myInPath, myOutPath)
        assert os.path.exists(myOutPath)
コード例 #4
0
ファイル: test_is_clipper.py プロジェクト: purnamabs/inasafe
 def test_vectorProjections(self):
     """Test that vector input data is reprojected properly during clip"""
     # Input data is OSM in GOOGLE CRS
     # We are reprojecting to GEO and expecting the output shp to be in GEO
     # see https://github.com/AIFDR/inasafe/issues/119
     # and https://github.com/AIFDR/inasafe/issues/95
     myVectorLayer = QgsVectorLayer(VECTOR_PATH2,
                                    'OSM Buildings',
                                    'ogr')
     myMessage = 'Failed to load osm buildings'
     assert myVectorLayer is not None, myMessage
     assert myVectorLayer.isValid()
     setCanvasCrs(GEOCRS, True)
     setJakartaGeoExtent()
     myClipRect = [106.52, -6.38, 107.14, -6.07]
     # Clip the vector to the bbox
     myResult = clipLayer(myVectorLayer, myClipRect)
     assert(os.path.exists(myResult))
コード例 #5
0
ファイル: test_is_dock.py プロジェクト: purnamabs/inasafe
    def test_runFloodPopulationImpactFunction(self):
        """Flood function runs in GUI with Jakarta data
           Raster on raster based function runs as expected."""

        # FIXME (Ole):
        # Temporarily disabled as it was depending on old scaling method
        # specific to this dataset. After cleaning up the 'official'
        # impact function, this one doesn't work. Use instead
        # HKV impact function in engine/impact_functions_for_testing

        # Push OK with the left mouse button

        myButton = DOCK.pbnRunStop

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

        # Hazard layers - default is already Banjir Jakarta seperti 2007
        myIndex = DOCK.cboHazard.findText('A flood in Jakarta like in 2007')
        msg = 'Jakarta 2007 flood hazard layer not found'
        assert myIndex != -1, msg
        DOCK.cboHazard.setCurrentIndex(myIndex)

        # Exposure layers - Penduduk Jakarta
        myIndex = DOCK.cboExposure.findText('Penduduk Jakarta')
        assert myIndex != -1, 'Penduduk Jakarta exposure layer not found'
        DOCK.cboExposure.setCurrentIndex(myIndex)

        # Choose impact function - HKVtest
        myIndex = DOCK.cboFunction.findText('HKVtest')
        msg = ('HKVtest impact function not '
               'found: ' + combosToString(DOCK))
        assert myIndex != -1, msg
        DOCK.cboFunction.setCurrentIndex(myIndex)

        # Exposure layers - Penduduk Jakarta
        #QTest.keyClick(DOCK.cboExposure, QtCore.Qt.Key_Down)
        #QTest.keyClick(DOCK.cboExposure, QtCore.Qt.Key_Down)
        #QTest.keyClick(DOCK.cboExposure, QtCore.Qt.Key_Enter)

        # Choose impact Terdampak
        #QTest.keyClick(DOCK.cboFunction, QtCore.Qt.Key_Down)
        #QTest.keyClick(DOCK.cboFunction, QtCore.Qt.Key_Down)
        #QTest.keyClick(DOCK.cboFunction, QtCore.Qt.Key_Enter)

        # Check that layers and impact function are correct
        myDict = getUiState(DOCK)

        myExpectedDict = {'Run Button Enabled': True,
                          'Impact Function': 'HKVtest',
                          'Hazard': 'A flood in Jakarta like in 2007',
                          'Exposure': 'Penduduk Jakarta'}
        myMessage = 'Got unexpected state: %s\nExpected: %s\n%s' % (
                            myDict, myExpectedDict, combosToString(DOCK))
        assert myDict == myExpectedDict, myMessage

        # Enable on-the-fly reprojection
        setCanvasCrs(GEOCRS, True)
        setJakartaGeoExtent()

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

        # Check that the number is as what was calculated by
        # Marco Hartman form HKV
        msg = 'Result not as expected: %s' % myResult
        assert '2480' in myResult, msg  # This is the expected impact number