class ImpactCalculatorTest(unittest.TestCase): """Test the InaSAFE plugin stub""" def setUp(self): """Create shared resources that all tests can use""" self.calculator = ImpactCalculator() self.vector_path = os.path.join(TESTDATA, 'Padang_WGS84.shp') self.vector_layer = read_safe_layer(self.vector_path) self.raster_shake_path = os.path.join( HAZDATA, 'Shakemap_Padang_2009.asc') self.raster_shake = read_safe_layer(self.raster_shake_path) # UTM projected layer fn = 'tsunami_max_inundation_depth_BB_utm.asc' self.raster_tsunami_path = os.path.join(TESTDATA, fn) self.raster_exposure_path = os.path.join( TESTDATA, 'tsunami_building_exposure.shp') self.raster_population_path = os.path.join(EXPDATA, 'glp10ag.asc') self.calculator.set_hazard_layer(self.raster_shake) self.calculator.set_exposure_layer(self.vector_layer) self.calculator.set_function('Earthquake Building Impact Function') def tearDown(self): """Tear down - destroy the QGIS app""" pass def test_properties(self): """Test if the properties work as expected.""" message = 'Vector property incorrect.' assert (self.calculator.exposure_layer() == self.vector_layer), message message = 'Raster property incorrect.' assert (self.calculator.hazard_layer() == self.raster_shake), message message = 'Function property incorrect.' assert (self.calculator.function() == 'Earthquake Building Impact Function'), message def test_run(self): """Test that run works as expected in non threading mode""" try: test_runner = self.calculator.get_runner() # run non threaded test_runner.run() message = test_runner.result() impact_layer = test_runner.impact_layer() file_name = impact_layer.get_filename() assert(file_name and not file_name == '') assert(message and not message == '') except Exception, e: # pylint: disable=W0703 message = 'Calculator run failed. %s' % str(e) assert(), message
class ImpactCalculatorTest(unittest.TestCase): """Test the InaSAFE plugin stub""" def setUp(self): """Create shared resources that all tests can use""" register_impact_functions() self.calculator = ImpactCalculator() self.vector_path = os.path.join(TESTDATA, 'Padang_WGS84.shp') self.vector_layer = read_safe_layer(self.vector_path) self.raster_shake_path = os.path.join( HAZDATA, 'Shakemap_Padang_2009.asc') self.raster_shake = read_safe_layer(self.raster_shake_path) # UTM projected layer fn = 'tsunami_max_inundation_depth_BB_utm.asc' self.raster_tsunami_path = os.path.join(TESTDATA, fn) self.raster_exposure_path = os.path.join( TESTDATA, 'tsunami_building_exposure.shp') self.raster_population_path = os.path.join(EXPDATA, 'glp10ag.asc') self.calculator.set_hazard_layer(self.raster_shake) self.calculator.set_exposure_layer(self.vector_layer) self.calculator.set_function('EarthquakeBuildingFunction') self.impact_function_manager = ImpactFunctionManager() def tearDown(self): """Tear down - destroy the QGIS app""" pass def test_properties(self): """Test if the properties work as expected.""" message = 'Vector property incorrect.' assert (self.calculator.exposure_layer() == self.vector_layer), message message = 'Raster property incorrect.' assert (self.calculator.hazard_layer() == self.raster_shake), message message = 'Function property incorrect.' self.assertEqual( self.impact_function_manager.get_function_id( self.calculator.function()), 'EarthquakeBuildingFunction', message) def test_run(self): """Test that run works as expected in non threading mode""" try: test_runner = self.calculator.get_runner() # run non threaded test_runner.run() message = test_runner.result() impact_layer = test_runner.impact_layer() file_name = impact_layer.get_filename() assert(file_name and not file_name == '') assert(message and not message == '') except Exception, e: # pylint: disable=W0703 message = 'Calculator run failed. %s' % str(e) assert(), message