def test_cboAggregationToggle(self): """Aggregation Combobox toggles on and off as expected.""" # With aggregation layer myResult, myMessage = setup_scenario( DOCK, hazard='A flood in Jakarta like in 2007', exposure='People', function='Need evacuation', function_id='Flood Evacuation Function', aggregation_layer='kabupaten jakarta singlepart', aggregation_enabled_flag=True) myMessage += ' when an aggregation layer is defined.' assert myResult, myMessage # With no aggregation layer myLayer = DOCK.get_aggregation_layer() myId = myLayer.id() QgsMapLayerRegistry.instance().removeMapLayer(myId) myResult, myMessage = setup_scenario( DOCK, hazard='A flood in Jakarta like in 2007', exposure='People', function='Need evacuation', function_id='Flood Evacuation Function', aggregation_enabled_flag=False) myMessage += ' when no aggregation layer is defined.' assert myResult, myMessage
def test_cboAggregationToggle(self): """Aggregation Combobox toggles on and off as expected.""" # With aggregation layer myResult, myMessage = setup_scenario( DOCK, hazard='A flood in Jakarta like in 2007', exposure='People', function='Need evacuation', function_id='Flood Evacuation Function', aggregation_layer='kabupaten jakarta singlepart', aggregation_enabled_flag=True) myMessage += ' when an aggregation layer is defined.' assert myResult, myMessage # With no aggregation layer myLayer = DOCK.get_aggregation_layer() myId = myLayer.id() QgsMapLayerRegistry.instance().removeMapLayer(myId) myResult, myMessage = setup_scenario( DOCK, hazard='A flood in Jakarta like in 2007', exposure='People', function='Need evacuation', function_id='Flood Evacuation Function', aggregation_enabled_flag=False) myMessage += ' when no aggregation layer is defined.' assert myResult, myMessage
def test_hasParametersButtonEnabled(self): """Function configuration button is enabled when layers are compatible. """ set_canvas_crs(GEOCRS, True) set_jakarta_extent() setup_scenario(DOCK, hazard='A flood in Jakarta like in 2007', exposure='Penduduk Jakarta', function='Need evacuation', function_id='Flood Evacuation Function') myToolButton = DOCK.toolFunctionOptions myFlag = myToolButton.isEnabled() assert myFlag, 'Expected configuration options button to be enabled'
def Xtest_extentsChanged(self): """Memory requirements are calculated correctly when extents change. """ set_canvas_crs(GEOCRS, True) set_jakarta_extent() setup_scenario(DOCK, hazard='A flood in Jakarta like in 2007', exposure='Penduduk Jakarta', function='Need evacuation', function_id='Flood Evacuation Function') myResult = DOCK.checkMemoryUsage() myMessage = 'Expected "3mb" to apear in : %s' % myResult assert myResult is not None, 'Check memory reported None' assert '3mb' in myResult, myMessage
def test_hasParametersButtonEnabled(self): """Function configuration button is enabled when layers are compatible. """ set_canvas_crs(GEOCRS, True) set_jakarta_extent() setup_scenario( DOCK, hazard='A flood in Jakarta like in 2007', exposure='Penduduk Jakarta', function='Need evacuation', function_id='Flood Evacuation Function') myToolButton = DOCK.toolFunctionOptions myFlag = myToolButton.isEnabled() assert myFlag, 'Expected configuration options button to be enabled'
def Xtest_extentsChanged(self): """Memory requirements are calculated correctly when extents change. """ set_canvas_crs(GEOCRS, True) set_jakarta_extent() setup_scenario( DOCK, hazard='A flood in Jakarta like in 2007', exposure='Penduduk Jakarta', function='Need evacuation', function_id='Flood Evacuation Function') myResult = DOCK.checkMemoryUsage() myMessage = 'Expected "3mb" to apear in : %s' % myResult assert myResult is not None, 'Check memory reported None' assert '3mb' in myResult, myMessage
def Xtest_runnerIsNone(self): """Test for none runner exceptions""" myResult, myMessage = setup_scenario( DOCK, hazard='A flood in Jakarta like in 2007', exposure='People', function='None returner', function_id='None Returning Impact Function', aggregation_enabled_flag=True) assert myResult, myMessage # Enable on-the-fly reprojection set_canvas_crs(GEOCRS, True) set_jakarta_extent() # Press RUN # noinspection PyCallByClass,PyTypeChecker DOCK.accept() # DOCK.runtimeKeywordsDialog.accept() myExpectedResult = """Error: An exception occurred when calculating the results Problem: AttributeError : 'NoneType' object has no attribute 'keywords' Click for Diagnostic Information: """ myResult = DOCK.wvResults.page_to_text() myMessage = ('The result message should be:\n%s\nFound:\n%s' % (myExpectedResult, myResult)) self.assertEqual(myExpectedResult, myResult, myMessage)
def test_postProcessorOutput(self): """Check that the post processor does not add spurious report rows.""" myRunButton = DOCK.pbnRunStop # with KAB_NAME aggregation attribute defined in .keyword using # kabupaten_jakarta_singlepart.shp myResult, myMessage = setup_scenario( DOCK, hazard='A flood in Jakarta like in 2007', exposure='People', function='Need evacuation', function_id='Flood Evacuation Function') # Enable on-the-fly reprojection set_canvas_crs(GEOCRS, True) set_jakarta_extent() assert myResult, myMessage # Press RUN # noinspection PyCallByClass,PyTypeChecker QTest.mouseClick(myRunButton, QtCore.Qt.LeftButton) myMessage = 'Spurious 0 filled rows added to post processing report.' myResult = DOCK.wvResults.page().currentFrame().toPlainText() for line in myResult.split('\n'): if 'Entire area' in line: myTokens = str(line).split('\t') myTokens = myTokens[1:] mySum = 0 for myToken in myTokens: mySum += float(myToken.replace(',', '.')) assert mySum != 0, myMessage
def test_issue306(self): """Issue306: CANVAS doesnt add generated layers in tests See https://github.com/AIFDR/inasafe/issues/306""" result, message = setup_scenario( DOCK, hazard='A flood in Jakarta like in 2007', exposure='Penduduk Jakarta', function='HKVtest', function_id='HKVtest') self.assertTrue(result, message) LOGGER.info("Canvas list before:\n%s" % canvas_list()) # Enable on-the-fly reprojection set_canvas_crs(GOOGLECRS, True) set_jakarta_google_extent() before_count = len(CANVAS.layers()) #print 'Before count %s' % before_count # Press RUN DOCK.accept() # test issue #306 after_count = len(CANVAS.layers()) LOGGER.info("Canvas list after:\n%s" % canvas_list()) message = ('Layer was not added to canvas (%s before, %s after)' % ( before_count, after_count)) #print 'After count %s' % after_count self.assertTrue(before_count == after_count - 1, message)
def test_runCategorisedHazardPopulationImpactFunction(self): """Flood function runs in GUI with Flood in Jakarta hazard data Uses Penduduk Jakarta as exposure data.""" result, message = setup_scenario( DOCK, hazard='Flood in Jakarta', exposure='Penduduk Jakarta', function='Be impacted', function_id='Categorised Hazard Population Impact Function') self.assertTrue(result, message) # Enable on-the-fly reprojection set_canvas_crs(GEOCRS, True) set_jakarta_extent() # Press RUN DOCK.accept() result = DOCK.wvResults.page_to_text() message = ('Result not as expected: %s' % result) # This is the expected number of population might be affected self.assertTrue(format_int(30938000) in result, message) # high #self.assertTrue(format_int(68280000) in result, message) #self.assertTrue(format_int(157551000) in result, message) # The 2 asserts above are not valid anymore after the fix we made to # CategorisedHazardPopulationImpactFunction # Look at the fix here: # (https://github.com/AIFDR/inasafe/commit/aa5b3d72145c031c91f4d101b830 # 8228915c248d#diff-378093670f4ebd60b4487af9b7c2e164) # New Asserts self.assertTrue(format_int(0) in result, message) # medium self.assertTrue(format_int(256769000) in result, message) # low
def test_runFloodPopulationImpactFunction_scaling(self): """Flood function runs in GUI with 5x5km population data Raster on raster based function runs as expected with scaling.""" result, message = setup_scenario( DOCK, hazard='A flood in Jakarta like in 2007', exposure='People', function='Need evacuation', function_id='Flood Evacuation Function') self.assertTrue(result, message) # Enable on-the-fly reprojection set_canvas_crs(GEOCRS, True) set_jakarta_extent() # Press RUN button = DOCK.pbnRunStop button.click() result = DOCK.wvResults.page_to_text() message = 'Result not as expected: %s' % result # Check numbers are OK (within expected errors from resampling) # These are expected impact number self.assertTrue(format_int(10473000) in result, message) self.assertTrue(format_int(978000) in result, message)
def Xtest_runnerExceptions(self): """Test runner exceptions""" result, message = setup_scenario( DOCK, hazard='A flood in Jakarta like in 2007', exposure='People', function='Exception riser', function_id='Exception Raising Impact Function', aggregation_enabled_flag=True) self.assertTrue(result, message) # Enable on-the-fly reprojection set_canvas_crs(GEOCRS, True) set_jakarta_extent() # Press RUN # noinspection PyCallByClass,PyTypeChecker DOCK.accept() # DOCK.runtime_keywords_dialog.accept() expected_result = """Error: An exception occurred when calculating the results Problem: Exception : AHAHAH I got you Click for Diagnostic Information: """ result = DOCK.wvResults.page_to_text() message = ( 'The result message should be:\n%s\nFound:\n%s' % (expected_result, result)) self.assertEqual(expected_result, result, message)
def test_full_run_pyzstats(self): """Aggregation results correct using our own python zonal stats code. """ file_list = ['kabupaten_jakarta.shp'] load_layers(file_list, clear_flag=False, data_directory=BOUNDDATA) result, message = setup_scenario( DOCK, hazard='A flood in Jakarta like in 2007', exposure='People', function='Need evacuation', function_id='Flood Evacuation Function', aggregation_layer='kabupaten jakarta', aggregation_enabled_flag=True) self.assertTrue(result, message) # Enable on-the-fly reprojection set_canvas_crs(GEOCRS, True) set_jakarta_extent() # Press RUN # noinspection PyCallByClass,PyTypeChecker DOCK.accept() result = DOCK.wvResults.page_to_text() expected_result = open( TEST_FILES_DIR + '/test-full-run-results.txt', 'r').readlines() result = result.replace( '</td> <td>', ' ').replace('</td><td>', ' ') for line in expected_result: line = line.replace('\n', '') self.assertIn(line, result)
def test_post_processor_output(self): """Check that the post processor does not add spurious report rows.""" # with KAB_NAME aggregation attribute defined in .keyword using # kabupaten_jakarta_singlepart.shp result, message = setup_scenario( DOCK, hazard='A flood in Jakarta like in 2007', exposure='People', function_id='Flood Evacuation Function') # Enable on-the-fly reprojection set_canvas_crs(GEOCRS, True) set_jakarta_extent() assert result, message # Press RUN DOCK.accept() message = 'Spurious 0 filled rows added to post processing report.' result = DOCK.wvResults.page().currentFrame().toPlainText() for line in result.split('\n'): if 'Entire area' in line: tokens = str(line).split('\t') tokens = tokens[1:] total = 0 for token in tokens: total += float(token.replace(',', '.')) assert total != 0, message
def test_issue581(self): """Test issue #581 in github - Humanize can produce IndexError : list index out of range """ # See https://github.com/AIFDR/inasafe/issues/581 myResult, myMessage = setup_scenario( DOCK, hazard='A flood in Jakarta like in 2007', exposure='People', function='Need evacuation', function_id='Flood Evacuation Function') assert myResult, myMessage # Enable on-the-fly reprojection set_canvas_crs(GEOCRS, True) set_small_jakarta_extent() # Press RUN DOCK.accept() myResult = DOCK.wvResults.page().currentFrame().toPlainText() myMessage = 'Result not as expected: %s' % myResult assert 'IndexError' not in myResult, myMessage assert 'It appears that no People are affected by A flood in ' \ 'Jakarta like in 2007. You may want to consider:' in myResult
def test_checkAggregationAttribute1Attr(self): """Aggregation attribute is chosen correctly when there is only one attr available.""" myFileList = ['kabupaten_jakarta_singlepart_1_good_attr.shp'] #add additional layers load_layers(myFileList, clear_flag=False, data_directory=TESTDATA) myAttrKey = breakdown_defaults('AGGR_ATTR_KEY') # with 1 good aggregation attribute using # kabupaten_jakarta_singlepart_1_good_attr.shp myResult, myMessage = setup_scenario( DOCK, hazard='A flood in Jakarta like in 2007', exposure='People', function='Need evacuation', function_id='Flood Evacuation Function', aggregation_layer='kabupaten jakarta singlepart 1 good attr') assert myResult, myMessage # Press RUN # noinspection PyCallByClass,PyTypeChecker DOCK.accept() DOCK.runtimeKeywordsDialog.accept() print myAttrKey print DOCK.aggregator.attributes myAttribute = DOCK.aggregator.attributes[myAttrKey] myMessage = ('The aggregation should be KAB_NAME. Found: %s' % myAttribute) self.assertEqual(myAttribute, 'KAB_NAME', myMessage)
def test_runEarthquakeBuildingImpactFunction(self): """Earthquake function runs in GUI with An earthquake in Yogyakarta like in 2006 hazard data uses OSM Building Polygons exposure data.""" myResult, myMessage = setup_scenario( DOCK, hazard='An earthquake in Yogyakarta like in 2006', exposure='OSM Building Polygons', function='Be affected', function_id='Earthquake Building Impact Function') assert myResult, myMessage # Enable on-the-fly reprojection set_canvas_crs(GEOCRS, True) set_geo_extent([101, -12, 119, -4]) # Press RUN DOCK.accept() myResult = DOCK.wvResults.page_to_text() LOGGER.debug(myResult) myMessage = 'Result not as expected: %s' % myResult # This is the expected number of building might be affected assert format_int(786) in myResult, myMessage assert format_int(15528) in myResult, myMessage assert format_int(177) in myResult, myMessage
def Xtest_printMap(self): """Test print map, especially on Windows.""" myResult, myMessage = setup_scenario( DOCK, hazard='Flood in Jakarta', exposure='Essential buildings', function='Be affected', function_id='Categorised Hazard Building Impact Function') assert myResult, myMessage # Enable on-the-fly reprojection set_canvas_crs(GEOCRS, True) set_jakarta_extent() # Press RUN myButton = DOCK.pbnRunStop # noinspection PyCallByClass,PyTypeChecker QTest.mouseClick(myButton, QtCore.Qt.LeftButton) printButton = DOCK.pbnPrint try: # noinspection PyCallByClass,PyTypeChecker QTest.mouseClick(printButton, QtCore.Qt.LeftButton) except OSError: LOGGER.debug('OSError') # pass except Exception, e: raise Exception('Exception is not expected, %s' % e)
def test_runCategorizedHazardBuildingImpact(self): """Flood function runs in GUI with Flood in Jakarta hazard data Uses DKI buildings exposure data.""" myResult, myMessage = setup_scenario( DOCK, hazard='Flood in Jakarta', exposure='Essential buildings', function='Be affected', function_id='Categorised Hazard Building Impact Function') assert myResult, myMessage # Enable on-the-fly reprojection set_canvas_crs(GEOCRS, True) set_jakarta_extent() # Press RUN DOCK.accept() myResult = DOCK.wvResults.page_to_text() myMessage = 'Result not as expected: %s' % myResult # This is the expected number of building might be affected assert format_int(535) in myResult, myMessage assert format_int(453) in myResult, myMessage assert format_int(436) in myResult, myMessage
def test_runCategorisedHazardPopulationImpactFunction(self): """Flood function runs in GUI with Flood in Jakarta hazard data Uses Penduduk Jakarta as exposure data.""" myResult, myMessage = setup_scenario( DOCK, hazard='Flood in Jakarta', exposure='Penduduk Jakarta', function='Be impacted', function_id='Categorised Hazard Population Impact Function') assert myResult, myMessage # Enable on-the-fly reprojection set_canvas_crs(GEOCRS, True) set_jakarta_extent() # Press RUN DOCK.accept() myResult = DOCK.wvResults.page_to_text() myMessage = 'Result not as expected: %s' % myResult # This is the expected number of population might be affected assert format_int(30938000) in myResult, myMessage assert format_int(68280000) in myResult, myMessage assert format_int(157551000) in myResult, myMessage
def test_runFloodPopulationImpactFunction(self): """Flood function runs in GUI with Jakarta data Raster on raster based function runs as expected.""" # Push OK with the left mouse button myButton = DOCK.pbnRunStop myMessage = 'Run button was not enabled' assert myButton.isEnabled(), myMessage myResult, myMessage = setup_scenario( DOCK, hazard='A flood in Jakarta like in 2007', exposure='Penduduk Jakarta', function='HKVtest', function_id='HKVtest') assert myResult, myMessage # Enable on-the-fly reprojection set_canvas_crs(GEOCRS, True) set_jakarta_extent() # Press RUN DOCK.accept() myResult = DOCK.wvResults.page_to_text() # Check that the number is as what was calculated by # Marco Hartman form HKV myMessage = 'Result not as expected: %s' % myResult # This is the expected impact number assert format_int(2480) in myResult, myMessage
def test_runFloodPopulationImpactFunction_scaling(self): """Flood function runs in GUI with 5x5km population data Raster on raster based function runs as expected with scaling.""" myResult, myMessage = setup_scenario( DOCK, hazard='A flood in Jakarta like in 2007', exposure='People', function='Need evacuation', function_id='Flood Evacuation Function') assert myResult, myMessage # Enable on-the-fly reprojection set_canvas_crs(GEOCRS, True) set_jakarta_extent() # Press RUN myButton = DOCK.pbnRunStop # noinspection PyCallByClass,PyTypeChecker QTest.mouseClick(myButton, QtCore.Qt.LeftButton) myResult = DOCK.wvResults.page_to_text() myMessage = 'Result not as expected: %s' % myResult # Check numbers are OK (within expected errors from resampling) # These are expected impact number assert format_int(10484) in myResult, myMessage assert format_int(977) in myResult, myMessage
def test_fullRunResults(self): """Aggregation results are correct.""" myExpectedResult = open( TEST_FILES_DIR + '/test-full-run-results.txt', 'r').read() myResult, myMessage = setup_scenario( DOCK, hazard='A flood in Jakarta like in 2007', exposure='People', function='Need evacuation', function_id='Flood Evacuation Function', aggregation_layer='kabupaten jakarta singlepart', aggregation_enabled_flag=True) assert myResult, myMessage # Enable on-the-fly reprojection set_canvas_crs(GEOCRS, True) set_jakarta_extent() # Press RUN # noinspection PyCallByClass,PyTypeChecker DOCK.accept() DOCK.runtimeKeywordsDialog.accept() myResult = DOCK.wvResults.page_to_text() myMessage = ('The aggregation report should be:\n%s\n\nFound:\n\n%s' % (myExpectedResult, myResult)) self.assertEqual(myResult, myExpectedResult, myMessage)
def test_runEarthquakeFatalityFunction_small(self): """Padang 2009 fatalities estimated correctly (small extent).""" # Push OK with the left mouse button set_canvas_crs(GEOCRS, True) set_padang_extent() myResult, myMessage = setup_scenario( DOCK, hazard=PADANG2009_title, exposure='People', function='Earthquake Fatality Function', function_id='Earthquake Fatality Function') assert myResult, myMessage DOCK.accept() myResult = DOCK.wvResults.page_to_text() # Check against expected output myMessage = ('Unexpected result returned for Earthquake Fatality ' 'Function Expected: fatality count of ' '116 , received: \n %s' % myResult) assert format_int(116) in myResult, myMessage myMessage = ('Unexpected result returned for Earthquake Fatality ' 'Function Expected: total population count of ' '847529 , received: \n %s' % myResult) assert format_int(847529) in myResult, myMessage
def test_runEarthQuakeGuidelinesFunction(self): """GUI runs with Shakemap 2009 and Padang Buildings""" # Push OK with the left mouse button set_canvas_crs(GEOCRS, True) set_padang_extent() myResult, myMessage = setup_scenario( DOCK, hazard=PADANG2009_title, exposure='Padang WGS84', function='Earthquake Guidelines Function', function_id='Earthquake Guidelines Function') assert myResult, myMessage DOCK.accept() myResult = DOCK.wvResults.page_to_text() # Expected output: #Buildings Total #All: 3160 #Low damage (10-25%): 0 #Medium damage (25-50%): 0 #Pre merge of clip on steroids branch: #High damage (50-100%): 3160 # Post merge of clip on steoids branch: #High damage (50-100%): 2993 myMessage = ('Unexpected result returned for Earthquake guidelines' 'function. Expected:\n "All" count of 2993, ' 'received: \n %s' % myResult) assert format_int(2993) in myResult, myMessage
def test_issue45(self): """Points near the edge of a raster hazard layer are interpolated OK""" myButton = DOCK.pbnRunStop set_canvas_crs(GEOCRS, True) set_yogya_extent() myMessage = 'Run button was not enabled' assert myButton.isEnabled(), myMessage myResult, myMessage = setup_scenario( DOCK, hazard='An earthquake in Yogyakarta like in 2006', exposure='OSM Building Polygons', function='Earthquake Guidelines Function', function_id='Earthquake Guidelines Function') assert myResult, myMessage # This is the where nosetest sometims hangs when running the # guitest suite (Issue #103) # The QTest.mouseClick call some times never returns when run # with nosetest, but OK when run normally. # noinspection PyCallByClass,PyTypeChecker DOCK.accept() myResult = DOCK.wvResults.page_to_text() # Check that none of these get a NaN value: self.assertIn('Unknown', myResult) myMessage = ('Some buildings returned by Earthquake guidelines ' 'function ' 'had NaN values. Result: \n %s' % myResult) assert 'Unknown (NaN): 196' not in myResult, myMessage
def test_checkAggregationAttribute1Attr(self): """Aggregation attribute is chosen correctly when there is only one attr available.""" myRunButton = DOCK.pbnRunStop myFileList = ['kabupaten_jakarta_singlepart_1_good_attr.shp'] #add additional layers load_layers(myFileList, clear_flag=False, data_directory=TESTDATA) myAttrKey = defaults('AGGR_ATTR_KEY') # with 1 good aggregation attribute using # kabupaten_jakarta_singlepart_1_good_attr.shp myResult, myMessage = setup_scenario( DOCK, hazard='A flood in Jakarta like in 2007', exposure='People', function='Need evacuation', function_id='Flood Evacuation Function', aggregation_layer='kabupaten jakarta singlepart 1 good attr') assert myResult, myMessage # Press RUN # noinspection PyCallByClass,PyTypeChecker QTest.mouseClick(myRunButton, QtCore.Qt.LeftButton) DOCK.runtimeKeywordsDialog.accept() print myAttrKey print DOCK.aggregator.attributes myAttribute = DOCK.aggregator.attributes[myAttrKey] myMessage = ('The aggregation should be KAB_NAME. Found: %s' % myAttribute) self.assertEqual(myAttribute, 'KAB_NAME', myMessage)
def test_issue45(self): """Points near the edge of a raster hazard layer are interpolated OK""" myButton = DOCK.pbnRunStop set_canvas_crs(GEOCRS, True) set_yogya_extent() myMessage = 'Run button was not enabled' assert myButton.isEnabled(), myMessage myResult, myMessage = setup_scenario( DOCK, hazard='An earthquake in Yogyakarta like in 2006', exposure='OSM Building Polygons', function='Earthquake Guidelines Function', function_id='Earthquake Guidelines Function') assert myResult, myMessage # This is the where nosetest sometims hangs when running the # guitest suite (Issue #103) # The QTest.mouseClick call some times never returns when run # with nosetest, but OK when run normally. # noinspection PyCallByClass,PyTypeChecker DOCK.accept() myResult = DOCK.wvResults.page_to_text() # Check that none of these get a NaN value: self.assertIn('Unknown', myResult) myMessage = ('Some buildings returned by Earthquake guidelines ' 'function ' 'had NaN values. Result: \n %s' % myResult) assert 'Unknown (NaN): 196' not in myResult, myMessage
def test_runCategorizedHazardBuildingImpact(self): """Flood function runs in GUI with Flood in Jakarta hazard data Uses DKI buildings exposure data.""" myResult, myMessage = setup_scenario( DOCK, hazard='Flood in Jakarta', exposure='Essential buildings', function='Be affected', function_id='Categorised Hazard Building Impact Function') assert myResult, myMessage # Enable on-the-fly reprojection set_canvas_crs(GEOCRS, True) set_jakarta_extent() # Press RUN DOCK.accept() myResult = DOCK.wvResults.page_to_text() myMessage = 'Result not as expected: %s' % myResult # This is the expected number of building might be affected assert format_int(535) in myResult, myMessage assert format_int(453) in myResult, myMessage assert format_int(436) in myResult, myMessage
def test_post_processor_output(self): """Check that the post processor does not add spurious report rows.""" # with KAB_NAME aggregation attribute defined in .keyword using # kabupaten_jakarta_singlepart.shp result, message = setup_scenario( DOCK, hazard='A flood in Jakarta like in 2007', exposure='People', function='Need evacuation', function_id='Flood Evacuation Function') # Enable on-the-fly reprojection set_canvas_crs(GEOCRS, True) set_jakarta_extent() assert result, message # Press RUN DOCK.accept() message = 'Spurious 0 filled rows added to post processing report.' result = DOCK.wvResults.page().currentFrame().toPlainText() for line in result.split('\n'): if 'Entire area' in line: tokens = str(line).split('\t') tokens = tokens[1:] total = 0 for token in tokens: total += float(token.replace(',', '.')) assert total != 0, message
def test_runCategorisedHazardPopulationImpactFunction(self): """Flood function runs in GUI with Flood in Jakarta hazard data Uses Penduduk Jakarta as exposure data.""" myResult, myMessage = setup_scenario( DOCK, hazard='Flood in Jakarta', exposure='Penduduk Jakarta', function='Be impacted', function_id='Categorised Hazard Population Impact Function') assert myResult, myMessage # Enable on-the-fly reprojection set_canvas_crs(GEOCRS, True) set_jakarta_extent() # Press RUN DOCK.accept() myResult = DOCK.wvResults.page_to_text() myMessage = 'Result not as expected: %s' % myResult # This is the expected number of population might be affected assert format_int(30938000) in myResult, myMessage assert format_int(68280000) in myResult, myMessage assert format_int(157551000) in myResult, myMessage
def test_runEarthQuakeGuidelinesFunction(self): """GUI runs with Shakemap 2009 and Padang Buildings""" # Push OK with the left mouse button set_canvas_crs(GEOCRS, True) set_padang_extent() myResult, myMessage = setup_scenario( DOCK, hazard=PADANG2009_title, exposure='Padang WGS84', function='Earthquake Guidelines Function', function_id='Earthquake Guidelines Function') assert myResult, myMessage DOCK.accept() myResult = DOCK.wvResults.page_to_text() # Expected output: #Buildings Total #All: 3160 #Low damage (10-25%): 0 #Medium damage (25-50%): 0 #Pre merge of clip on steroids branch: #High damage (50-100%): 3160 # Post merge of clip on steoids branch: #High damage (50-100%): 2993 myMessage = ('Unexpected result returned for Earthquake guidelines' 'function. Expected:\n "All" count of 2993, ' 'received: \n %s' % myResult) assert format_int(2993) in myResult, myMessage
def test_check_aggregation_single_attribute(self): """Aggregation attribute is chosen correctly when there is only one attr available.""" file_list = ['kabupaten_jakarta_singlepart_1_good_attr.shp'] #add additional layers load_layers(file_list, clear_flag=False) attribute_key = breakdown_defaults('AGGR_ATTR_KEY') # with 1 good aggregation attribute using # kabupaten_jakarta_singlepart_1_good_attr.shp result, message = setup_scenario( DOCK, hazard='A flood in Jakarta like in 2007', exposure='People', function='Need evacuation', function_id='Flood Evacuation Function', aggregation_layer='kabupaten jakarta singlepart 1 good attr') assert result, message # Press RUN # noinspection PyCallByClass,PyTypeChecker DOCK.accept() DOCK.runtime_keywords_dialog.accept() print attribute_key print DOCK.aggregator.attributes attribute = DOCK.aggregator.attributes[attribute_key] message = ('The aggregation should be KAB_NAME. Found: %s' % attribute) self.assertEqual(attribute, 'KAB_NAME', message)
def test_issue581(self): """Test issue #581 in github - Humanize can produce IndexError : list index out of range """ # See https://github.com/AIFDR/inasafe/issues/581 myResult, myMessage = setup_scenario( DOCK, hazard='A flood in Jakarta like in 2007', exposure='People', function='Need evacuation', function_id='Flood Evacuation Function') assert myResult, myMessage # Enable on-the-fly reprojection set_canvas_crs(GEOCRS, True) set_small_jakarta_extent() # Press RUN DOCK.accept() myResult = DOCK.wvResults.page().currentFrame().toPlainText() myMessage = 'Result not as expected: %s' % myResult assert 'IndexError' not in myResult, myMessage assert 'It appears that no People are affected by A flood in ' \ 'Jakarta like in 2007. You may want to consider:' in myResult
def test_checkAggregationAttributeNoneAttr(self): """Aggregation attribute is chosen correctly when there None in the kezwords""" myRunButton = DOCK.pbnRunStop myFileList = ['kabupaten_jakarta_singlepart_with_None_keyword.shp'] #add additional layers load_layers(myFileList, clear_flag=False, data_directory=TESTDATA) myAttrKey = defaults('AGGR_ATTR_KEY') # with None aggregation attribute defined in .keyword using # kabupaten_jakarta_singlepart_with_None_keyword.shp myResult, myMessage = setup_scenario( DOCK, hazard='A flood in Jakarta like in 2007', exposure='People', function='Need evacuation', function_id='Flood Evacuation Function', aggregation_layer='kabupaten jakarta singlepart with None ' 'keyword') assert myResult, myMessage # Press RUN # noinspection PyCallByClass,PyTypeChecker QTest.mouseClick(myRunButton, QtCore.Qt.LeftButton) DOCK.runtimeKeywordsDialog.accept() myAttribute = DOCK.aggregator.attributes[myAttrKey] myMessage = ('The aggregation should be None. Found: %s' % myAttribute) assert myAttribute is None, myMessage
def Xtest_printMap(self): """Test print map, especially on Windows.""" myResult, myMessage = setup_scenario( DOCK, hazard='Flood in Jakarta', exposure='Essential buildings', function='Be affected', function_id='Categorised Hazard Building Impact Function') assert myResult, myMessage # Enable on-the-fly reprojection set_canvas_crs(GEOCRS, True) set_jakarta_extent() # Press RUN myButton = DOCK.pbnRunStop # noinspection PyCallByClass,PyTypeChecker QTest.mouseClick(myButton, QtCore.Qt.LeftButton) printButton = DOCK.pbnPrint try: # noinspection PyCallByClass,PyTypeChecker QTest.mouseClick(printButton, QtCore.Qt.LeftButton) except OSError: LOGGER.debug('OSError') # pass except Exception, e: raise Exception('Exception is not expected, %s' % e)
def test_checkAggregationAttributeInKW(self): """Aggregation attribute is chosen correctly when present in kezwords.""" myRunButton = DOCK.pbnRunStop myAttrKey = defaults('AGGR_ATTR_KEY') # with KAB_NAME aggregation attribute defined in .keyword using # kabupaten_jakarta_singlepart.shp myResult, myMessage = setup_scenario( DOCK, hazard='A flood in Jakarta like in 2007', exposure='People', function='Need evacuation', function_id='Flood Evacuation Function', aggregation_layer='kabupaten jakarta singlepart', aggregation_enabled_flag=True) assert myResult, myMessage # Press RUN # noinspection PyCallByClass,PyTypeChecker QTest.mouseClick(myRunButton, QtCore.Qt.LeftButton) DOCK.runtimeKeywordsDialog.accept() myAttribute = DOCK.aggregator.attributes[myAttrKey] myMessage = ('The aggregation should be KAB_NAME. Found: %s' % myAttribute) self.assertEqual(myAttribute, 'KAB_NAME', myMessage)
def test_postProcessorOutput(self): """Check that the post processor does not add spurious report rows.""" myRunButton = DOCK.pbnRunStop # with KAB_NAME aggregation attribute defined in .keyword using # kabupaten_jakarta_singlepart.shp myResult, myMessage = setup_scenario( DOCK, hazard='A flood in Jakarta like in 2007', exposure='People', function='Need evacuation', function_id='Flood Evacuation Function') # Enable on-the-fly reprojection set_canvas_crs(GEOCRS, True) set_jakarta_extent() assert myResult, myMessage # Press RUN # noinspection PyCallByClass,PyTypeChecker QTest.mouseClick(myRunButton, QtCore.Qt.LeftButton) myMessage = 'Spurious 0 filled rows added to post processing report.' myResult = DOCK.wvResults.page().currentFrame().toPlainText() for line in myResult.split('\n'): if 'Entire area' in line: myTokens = str(line).split('\t') myTokens = myTokens[1:] mySum = 0 for myToken in myTokens: mySum += float(myToken.replace(',', '.')) assert mySum != 0, myMessage
def test_check_aggregation_single_attribute(self): """Aggregation attribute is chosen correctly when there is only one attr available.""" file_list = ['kabupaten_jakarta_singlepart_1_good_attr.shp'] # add additional layers load_layers(file_list, clear_flag=False) attribute_key = get_defaults('AGGR_ATTR_KEY') # with 1 good aggregation attribute using # kabupaten_jakarta_singlepart_1_good_attr.shp result, message = setup_scenario( DOCK, hazard='A flood in Jakarta like in 2007', exposure='People', function_id='Flood Evacuation Function', aggregation_layer='kabupaten jakarta singlepart 1 good attr') set_jakarta_extent(dock=DOCK) assert result, message # Press RUN # noinspection PyCallByClass,PyTypeChecker DOCK.accept() DOCK.runtime_keywords_dialog.accept() print attribute_key print DOCK.aggregator.attributes attribute = DOCK.aggregator.attributes[attribute_key] message = ( 'The aggregation should be KAB_NAME. Found: %s' % attribute) self.assertEqual(attribute, 'KAB_NAME', message)
def test_fullRunResults(self): """Aggregation results are correct.""" myExpectedResult = open(TEST_FILES_DIR + '/test-full-run-results.txt', 'r').read() myResult, myMessage = setup_scenario( DOCK, hazard='A flood in Jakarta like in 2007', exposure='People', function='Need evacuation', function_id='Flood Evacuation Function', aggregation_layer='kabupaten jakarta singlepart', aggregation_enabled_flag=True) assert myResult, myMessage # Enable on-the-fly reprojection set_canvas_crs(GEOCRS, True) set_jakarta_extent() # Press RUN # noinspection PyCallByClass,PyTypeChecker DOCK.accept() DOCK.runtimeKeywordsDialog.accept() myResult = DOCK.wvResults.page_to_text() myMessage = ('The aggregation report should be:\n%s\n\nFound:\n\n%s' % (myExpectedResult, myResult)) self.assertEqual(myResult, myExpectedResult, myMessage)
def test_runFloodPopulationImpactFunction_scaling(self): """Flood function runs in GUI with 5x5km population data Raster on raster based function runs as expected with scaling.""" myResult, myMessage = setup_scenario( DOCK, hazard='A flood in Jakarta like in 2007', exposure='People', function='Need evacuation', function_id='Flood Evacuation Function') assert myResult, myMessage # Enable on-the-fly reprojection set_canvas_crs(GEOCRS, True) set_jakarta_extent() # Press RUN myButton = DOCK.pbnRunStop # noinspection PyCallByClass,PyTypeChecker QTest.mouseClick(myButton, QtCore.Qt.LeftButton) myResult = DOCK.wvResults.page_to_text() myMessage = 'Result not as expected: %s' % myResult # Check numbers are OK (within expected errors from resampling) # These are expected impact number assert format_int(10484) in myResult, myMessage assert format_int(977) in myResult, myMessage
def test_runEarthquakeBuildingImpactFunction(self): """Earthquake function runs in GUI with An earthquake in Yogyakarta like in 2006 hazard data uses OSM Building Polygons exposure data.""" myResult, myMessage = setup_scenario( DOCK, hazard='An earthquake in Yogyakarta like in 2006', exposure='OSM Building Polygons', function='Be affected', function_id='Earthquake Building Impact Function') assert myResult, myMessage # Enable on-the-fly reprojection set_canvas_crs(GEOCRS, True) set_geo_extent([101, -12, 119, -4]) # Press RUN DOCK.accept() myResult = DOCK.wvResults.page_to_text() LOGGER.debug(myResult) myMessage = 'Result not as expected: %s' % myResult # This is the expected number of building might be affected assert format_int(786) in myResult, myMessage assert format_int(15528) in myResult, myMessage assert format_int(177) in myResult, myMessage
def test_runEarthquakeFatalityFunction_small(self): """Padang 2009 fatalities estimated correctly (small extent).""" # Push OK with the left mouse button set_canvas_crs(GEOCRS, True) set_padang_extent() myResult, myMessage = setup_scenario( DOCK, hazard=PADANG2009_title, exposure='People', function='Earthquake Fatality Function', function_id='Earthquake Fatality Function') assert myResult, myMessage DOCK.accept() myResult = DOCK.wvResults.page_to_text() # Check against expected output myMessage = ('Unexpected result returned for Earthquake Fatality ' 'Function Expected: fatality count of ' '116 , received: \n %s' % myResult) assert format_int(116) in myResult, myMessage myMessage = ('Unexpected result returned for Earthquake Fatality ' 'Function Expected: total population count of ' '847529 , received: \n %s' % myResult) assert format_int(847529) in myResult, myMessage
def test_runFloodPopulationImpactFunction(self): """Flood function runs in GUI with Jakarta data Raster on raster based function runs as expected.""" # Push OK with the left mouse button myButton = DOCK.pbnRunStop myMessage = 'Run button was not enabled' assert myButton.isEnabled(), myMessage myResult, myMessage = setup_scenario( DOCK, hazard='A flood in Jakarta like in 2007', exposure='Penduduk Jakarta', function='HKVtest', function_id='HKVtest') assert myResult, myMessage # Enable on-the-fly reprojection set_canvas_crs(GEOCRS, True) set_jakarta_extent() # Press RUN DOCK.accept() myResult = DOCK.wvResults.page_to_text() # Check that the number is as what was calculated by # Marco Hartman form HKV myMessage = 'Result not as expected: %s' % myResult # This is the expected impact number assert format_int(2480) in myResult, myMessage
def Xtest_runnerIsNone(self): """Test for none runner exceptions""" myResult, myMessage = setup_scenario( DOCK, hazard='A flood in Jakarta like in 2007', exposure='People', function='None returner', function_id='None Returning Impact Function', aggregation_enabled_flag=True) assert myResult, myMessage # Enable on-the-fly reprojection set_canvas_crs(GEOCRS, True) set_jakarta_extent() # Press RUN # noinspection PyCallByClass,PyTypeChecker DOCK.accept() # DOCK.runtimeKeywordsDialog.accept() myExpectedResult = """Error: An exception occurred when calculating the results Problem: AttributeError : 'NoneType' object has no attribute 'keywords' Click for Diagnostic Information: """ myResult = DOCK.wvResults.page_to_text() myMessage = ('The result message should be:\n%s\nFound:\n%s' % (myExpectedResult, myResult)) self.assertEqual(myExpectedResult, myResult, myMessage)
def test_issue160(self): """Test that multipart features can be used in a scenario - issue #160 """ exposure = os.path.join( UNITDATA, 'exposure', 'buildings_osm_4326.shp') hazard = os.path.join( UNITDATA, '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' % qgis_version() self.tearDown() button = DOCK.pbnRunStop # First part of scenario should have enabled run file_list = [hazard, exposure] hazard_layer_count, exposure_layer_count = load_layers(file_list) message = ( 'Incorrect number of Hazard layers: expected 1 got %s' % hazard_layer_count) self.assertTrue(hazard_layer_count == 1, message) message = ( 'Incorrect number of Exposure layers: expected 1 got %s' % exposure_layer_count) self.assertTrue(exposure_layer_count == 1, message) message = 'Run button was not enabled' self.assertTrue(button.isEnabled(), message) # Second part of scenario - run disabled when adding invalid layer # and select it - run should be disabled file_list = ['issue71.tif'] # This layer has incorrect keywords clear_flag = False _, _ = load_layers(file_list, clear_flag) result, message = setup_scenario( DOCK, hazard='multipart_polygons_osm_4326', exposure='buildings_osm_4326', function='Be flooded', function_id='Flood Building Impact Function') self.assertTrue(result, message) # Enable on-the-fly reprojection set_canvas_crs(GEOCRS, True) IFACE.mapCanvas().setExtent( QgsRectangle(106.788, -6.193, 106.853, -6.167)) # Press RUN # noinspection PyCallByClass,PyCallByClass,PyTypeChecker DOCK.accept() result = DOCK.wvResults.page_to_text() message = 'Result not as expected: %s' % result self.assertTrue(format_int(68) in result, message)
def test_hasParametersButtonDisabled(self): """Function configuration button is disabled when layers not compatible.""" set_canvas_crs(GEOCRS, True) #add additional layers #myResult, myMessage = setupScenario( # heHazard='An earthquake in Yogyakarta like in 2006', # theExposure = 'Essential Buildings', # theFunction = 'Be damaged depending on building type', # theFunctionId = 'ITB Earthquake Building Damage Function') setup_scenario(DOCK, hazard='An earthquake in Yogyakarta like in 2006', exposure='Essential Buildings', function='Be damaged depending on building type', function_id='ITB Earthquake Building Damage Function') myToolButton = DOCK.toolFunctionOptions myFlag = myToolButton.isEnabled() assert not myFlag, ('Expected configuration options ' 'button to be disabled')
def test_save_scenario(self): """Test saving Current scenario.""" result, message = setup_scenario( DOCK, hazard='Flood in Jakarta', exposure='Penduduk Jakarta', function='Be impacted', function_id='Categorised Hazard Population Impact Function') self.assertTrue(result, message) # Enable on-the-fly reprojection set_canvas_crs(GEOCRS, True) set_jakarta_extent(dock=DOCK) # create unique file scenario_file = unique_filename( prefix='scenarioTest', suffix='.txt', dir=temp_dir('test')) self.save_scenario_dialog.save_scenario( scenario_file_path=scenario_file) with open(scenario_file) as f: data = f.readlines() title = data[0][:-1] exposure = data[1][:-1] hazard = data[2][:-1] function = data[3][:-1] extent = data[4][:-1] self.assertTrue( os.path.exists(scenario_file), 'File %s does not exist' % scenario_file) self.assertTrue(title == '[Flood in Jakarta]', 'Title is not the same') self.assertTrue( exposure.startswith('exposure =') and exposure.endswith( 'Population_Jakarta_geographic.asc'), 'Exposure is not the same') self.assertTrue( hazard.startswith('hazard =') and hazard.endswith( 'jakarta_flood_category_123.asc'), 'Hazard is not the same') self.assertTrue( function == ( 'function = Categorised Hazard Population Impact Function'), 'Impact function is not same') # TODO: figure out why this changed between releases if qgis_version() < 20400: # For QGIS 2.0 expected_extent = ( 'extent = 106.313333, -6.380000, 107.346667, -6.070000') self.assertEqual(expected_extent, extent) else: # for QGIS 2.4 expected_extent = ( 'extent = 106.287500, -6.380000, 107.372500, -6.070000') self.assertEqual(expected_extent, expected_extent)
def test_save_scenario(self): """Test saving Current scenario.""" result, message = setup_scenario( DOCK, hazard='Flood in Jakarta', exposure='Penduduk Jakarta', function='Be impacted', function_id='Categorised Hazard Population Impact Function') self.assertTrue(result, message) # Enable on-the-fly reprojection set_canvas_crs(GEOCRS, True) set_jakarta_extent() # create unique file scenario_file = unique_filename( prefix='scenarioTest', suffix='.txt', dir=temp_dir('test')) self.save_scenario_dialog.save_scenario( scenario_file_path=scenario_file) with open(scenario_file) as f: data = f.readlines() title = data[0][:-1] exposure = data[1][:-1] hazard = data[2][:-1] function = data[3][:-1] extent = data[4][:-1] self.assertTrue( os.path.exists(scenario_file), 'File %s does not exist' % scenario_file) self.assertTrue(title == '[Flood in Jakarta]', 'Title is not the same') self.assertTrue( exposure.startswith('exposure =') and exposure.endswith( 'Population_Jakarta_geographic.asc'), 'Exposure is not the same') self.assertTrue( hazard.startswith('hazard =') and hazard.endswith( 'jakarta_flood_category_123.asc'), 'Hazard is not the same') self.assertTrue( function == ( 'function = Categorised Hazard Population Impact Function'), 'Impact function is not same') # TODO: figure out why this changed between releases if qgis_version() < 20400: # For QGIS 2.0 expected_extent = ( 'extent = 106.313333, -6.380000, 107.346667, -6.070000') self.assertEqual(expected_extent, extent) else: # for QGIS 2.4 expected_extent = ( 'extent = 106.287500, -6.380000, 107.372500, -6.070000') self.assertEqual(expected_extent, expected_extent)
def test_issue160(self): """Test that multipart features can be used in a scenario - issue #160 """ myExposure = os.path.join(UNITDATA, 'exposure', 'buildings_osm_4326.shp') myHazard = os.path.join(UNITDATA, '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' % qgis_version() self.tearDown() myButton = DOCK.pbnRunStop # First part of scenario should have enabled run myFileList = [myHazard, myExposure] myHazardLayerCount, myExposureLayerCount = load_layers(myFileList) 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 _, _ = load_layers(myFileList, myClearFlag) myResult, myMessage = setup_scenario( DOCK, hazard='multipart_polygons_osm_4326', exposure='buildings_osm_4326', function='Be flooded', function_id='Flood Building Impact Function') assert myResult, myMessage # Enable on-the-fly reprojection set_canvas_crs(GEOCRS, True) IFACE.mapCanvas().setExtent( QgsRectangle(106.788, -6.193, 106.853, -6.167)) # Press RUN # noinspection PyCallByClass,PyCallByClass,PyTypeChecker DOCK.accept() myResult = DOCK.wvResults.page_to_text() myMessage = 'Result not as expected: %s' % myResult assert format_int(68) in myResult, myMessage
def test_hasParametersButtonDisabled(self): """Function configuration button is disabled when layers not compatible.""" set_canvas_crs(GEOCRS, True) #add additional layers #myResult, myMessage = setupScenario( # heHazard='An earthquake in Yogyakarta like in 2006', # theExposure = 'Essential Buildings', # theFunction = 'Be damaged depending on building type', # theFunctionId = 'ITB Earthquake Building Damage Function') setup_scenario( DOCK, hazard='An earthquake in Yogyakarta like in 2006', exposure='Essential Buildings', function='Be damaged depending on building type', function_id='ITB Earthquake Building Damage Function') myToolButton = DOCK.toolFunctionOptions myFlag = myToolButton.isEnabled() assert not myFlag, ('Expected configuration options ' 'button to be disabled')
def test_issue317(self): """Points near the edge of a raster hazard layer are interpolated OK""" set_canvas_crs(GEOCRS, True) set_jakarta_extent() myResult, myMessage = setup_scenario( DOCK, hazard='A flood in Jakarta like in 2007', exposure='OSM Building Polygons', function='Be flooded', function_id='Flood Building Impact Function') DOCK.get_functions() assert myResult, myMessage
def test_issue317(self): """Points near the edge of a raster hazard layer are interpolated OK""" set_canvas_crs(GEOCRS, True) set_jakarta_extent() myResult, myMessage = setup_scenario( DOCK, hazard='A flood in Jakarta like in 2007', exposure='OSM Building Polygons', function='Be flooded', function_id='Flood Building Impact Function') DOCK.get_functions() assert myResult, myMessage
def test_checkPostProcessingLayersVisibility(self): """Generated layers are not added to the map registry.""" myRunButton = DOCK.pbnRunStop # with KAB_NAME aggregation attribute defined in .keyword using # kabupaten_jakarta_singlepart.shp myResult, myMessage = setup_scenario( DOCK, hazard='A flood in Jakarta like in 2007', exposure='People', function='Need evacuation', function_id='Flood Evacuation Function', aggregation_layer='kabupaten jakarta singlepart') assert myResult, myMessage LOGGER.info("Registry list before:\n%s" % QgsMapLayerRegistry.instance().mapLayers()) #one layer (the impact) should have been added myExpectedCount = len(CANVAS.layers()) + 1 # Press RUN # noinspection PyCallByClass,PyTypeChecker QTest.mouseClick(myRunButton, QtCore.Qt.LeftButton) DOCK.runtimeKeywordsDialog.accept() myAfterCount = len(CANVAS.layers()) LOGGER.info("Registry list after:\n%s" % QgsMapLayerRegistry.instance().mapLayers()) myMessage = ('Expected %s items in canvas, got %s' % (myExpectedCount, myAfterCount)) assert myExpectedCount == myAfterCount, myMessage # Now run again showing intermediate layers DOCK.showIntermediateLayers = True # Press RUN # noinspection PyCallByClass,PyTypeChecker QTest.mouseClick(myRunButton, QtCore.Qt.LeftButton) DOCK.runtimeKeywordsDialog.accept() #one layer (the impact) should have been added myExpectedCount += 2 myAfterCount = len(CANVAS.layers()) LOGGER.info("Canvas list after:\n %s" % canvas_list()) myMessage = ('Expected %s items in canvas, got %s' % (myExpectedCount, myAfterCount)) # We expect two more since we enabled showing intermedate layers assert myExpectedCount == myAfterCount, myMessage
def test_check_postprocessing_layers_visibility(self): """Generated layers are not added to the map registry.""" # Explicitly disable showing intermediate layers DOCK.show_intermediate_layers = False # with KAB_NAME aggregation attribute defined in .keyword using # kabupaten_jakarta_singlepart.shp result, message = setup_scenario( DOCK, hazard='A flood in Jakarta like in 2007', exposure='People', function_id='Flood Evacuation Function', aggregation_layer='kabupaten jakarta singlepart') set_jakarta_extent(dock=DOCK) assert result, message # LOGGER.info("Registry list before:\n%s" % # QgsMapLayerRegistry.instance().mapLayers()) # one layer (the impact) should have been added expected_count = len(CANVAS.layers()) + 1 # # Press RUN DOCK.accept() # no KW dialog will popuo due to complete keywords after_count = len(CANVAS.layers()) # LOGGER.info("Registry list after:\n%s" % # QgsMapLayerRegistry.instance().mapLayers()) message = ('Expected %s items in canvas, got %s' % (expected_count, after_count)) assert expected_count == after_count, message # Now run again showing intermediate layers DOCK.show_intermediate_layers = True # Press RUN DOCK.accept() # no KW dialog will popup due to complete keywords # one layer (the impact) should have been added expected_count += 2 after_count = len(CANVAS.layers()) LOGGER.info("Canvas list after:\n %s" % canvas_list()) message = ('Expected %s items in canvas, got %s' % (expected_count, after_count)) # We expect two more since we enabled showing intermediate layers assert expected_count == after_count, message
def test_validate_input(self): """Test validate input.""" # Valid Case result, message = setup_scenario( DOCK, hazard='Flood in Jakarta', exposure='Penduduk Jakarta', function='Be impacted', function_id='Categorised Hazard Population Impact Function') self.assertTrue(result, message) is_valid, message = self.save_scenario_dialog.validate_input() self.assertTrue(is_valid) self.assertIsNone(message) # Change the hazard layer to None self.save_scenario_dialog.dock.cboHazard.setCurrentIndex(-1) is_valid, message = self.save_scenario_dialog.validate_input() self.assertFalse(is_valid) self.assertIsNotNone(message)
def test_preprocessing(self): """Preprocessing results are correct. TODO - this needs to be fixed post dock refactor. """ # See qgis project in test data: vector_preprocessing_test.qgs #add additional layers myFileList = ['jakarta_crosskabupaten_polygons.shp'] load_layers(myFileList, clear_flag=False, data_directory=TESTDATA) myFileList = ['kabupaten_jakarta.shp'] load_layers(myFileList, clear_flag=False, data_directory=BOUNDDATA) myRunButton = DOCK.pbnRunStop myResult, myMessage = setup_scenario( DOCK, hazard='jakarta_crosskabupaten_polygons', exposure='People', function='Need evacuation', function_id='Flood Evacuation Function Vector Hazard', aggregation_layer='kabupaten jakarta', aggregation_enabled_flag=True) assert myResult, myMessage # Enable on-the-fly reprojection set_canvas_crs(GEOCRS, True) set_jakarta_extent() # Press RUN # noinspection PyTypeChecker,PyCallByClass QTest.mouseClick(myRunButton, QtCore.Qt.LeftButton) DOCK.runtimeKeywordsDialog.accept() myExpectedFeatureCount = 20 myMessage = ('The preprocessing should have generated %s features, ' 'found %s' % (myExpectedFeatureCount, DOCK.aggregator.preprocessedFeatureCount)) self.assertEqual(myExpectedFeatureCount, DOCK.aggregator.preprocessedFeatureCount, myMessage)
def test_runTsunamiBuildingImpactFunction(self): """Tsunami function runs in GUI as expected.""" # Push OK with the left mouse button myButton = DOCK.pbnRunStop myMessage = 'Run button was not enabled' assert myButton.isEnabled(), myMessage myResult, myMessage = setup_scenario( DOCK, hazard='Tsunami Max Inundation', exposure='Tsunami Building Exposure', function='Be flooded', function_id='Flood Building Impact Function') assert myResult, myMessage set_canvas_crs(GEOCRS, True) set_batemans_bay_extent() # Press RUN DOCK.accept() myResult = DOCK.wvResults.page_to_text() #print myResult # Post clip on steroids refactor # < 1 m: 1923 # 1 - 3 m: 89 # > 3 m: 0 # Post replacement of Batemans Bay dataset #< 1 m: 10 #1 - 3 m: 7 #> 3 m: 0 # Post rewrite of impact function #Building type closed Total #All 7 17 myMessage = 'Result not as expected: %s' % myResult assert format_int(17) in myResult, myMessage assert format_int(7) in myResult, myMessage