def test_is_valid(self): """Test is_valid.""" impact_functions = [ # Earthquake EarthquakeBuildingFunction(), ITBFatalityFunction(), PAGFatalityFunction(), # Generic ClassifiedPolygonHazardBuildingFunction(), ClassifiedPolygonHazardPopulationFunction(), ClassifiedRasterHazardBuildingFunction(), ClassifiedRasterHazardPopulationFunction(), ContinuousHazardPopulationFunction(), # Inundation FloodEvacuationVectorHazardFunction(), FloodPolygonRoadsFunction(), FloodRasterBuildingFunction(), FloodEvacuationRasterHazardFunction(), FloodRasterRoadsFunction(), FloodPolygonBuildingFunction(), TsunamiEvacuationFunction(), # Volcanic VolcanoPointBuildingFunction(), VolcanoPointPopulationFunction(), VolcanoPolygonBuildingFunction(), VolcanoPolygonPopulationFunction() ] for impact_function in impact_functions: valid = impact_function.metadata().is_valid() impact_function_name = impact_function.__class__.__name__ message = '%s is invalid because %s' % (impact_function_name, valid[1]) self.assertTrue(valid[0], message) if valid[0]: print '%s has a valid metadata.' % impact_function_name
def test_get_exposure_layer_constraint(self): """Test for get_exposure_layer_constraint.""" impact_function = FloodRasterBuildingFunction() expected_layer_constraint = [layer_vector_polygon, layer_vector_point] layer_constraints \ = impact_function.metadata().get_exposure_layer_constraint() message = 'Expected %s but got %s' % (expected_layer_constraint, layer_constraints) self.assertItemsEqual(expected_layer_constraint, layer_constraints, message)
def test_get_hazard_layer_constraint(self): """Test for get_hazard_layer_constraint.""" impact_function = FloodRasterBuildingFunction() expected_layer_constraint = [layer_raster_continuous] layer_constraints \ = impact_function.metadata().get_hazard_layer_constraint() message = 'Expected %s but got %s' % (expected_layer_constraint, layer_constraints) self.assertItemsEqual(expected_layer_constraint, layer_constraints, message)
def test_is_valid(self): """Test is_valid.""" impact_functions = [ # Earthquake EarthquakeBuildingFunction(), ITBFatalityFunction(), PAGFatalityFunction(), ITBBayesianFatalityFunction(), # Generic ClassifiedPolygonHazardBuildingFunction(), ClassifiedPolygonHazardLandCoverFunction(), ClassifiedPolygonHazardPopulationFunction(), ClassifiedPolygonHazardPolygonPeopleFunction(), ClassifiedRasterHazardBuildingFunction(), ClassifiedRasterHazardPopulationFunction(), ContinuousHazardPopulationFunction(), # Inundation FloodEvacuationVectorHazardFunction(), FloodPolygonRoadsFunction(), FloodRasterBuildingFunction(), FloodEvacuationRasterHazardFunction(), FloodRasterRoadsFunction(), FloodPolygonBuildingFunction(), # Tsunami TsunamiEvacuationFunction(), TsunamiRasterRoadsFunction(), TsunamiRasterLandcoverFunction(), TsunamiRasterBuildingFunction(), # Volcanic VolcanoPointBuildingFunction(), VolcanoPointPopulationFunction(), VolcanoPolygonBuildingFunction(), VolcanoPolygonPopulationFunction(), # Volcanic Ash AshRasterLandCoverFunction(), AshRasterPlacesFunction(), AshRasterPopulationFunction() ] self.assertEqual(len(impact_functions), len(EXPECTED_IF)) for impact_function in impact_functions: valid = impact_function.metadata().is_valid() impact_function_name = impact_function.__class__.__name__ message = '%s is invalid because %s' % (impact_function_name, valid[1]) self.assertTrue(valid[0], message) if valid[0]: # print '%s has a valid metadata.' % impact_function_name continue
def test_has_exposure(self): """Test for has_exposure API.""" impact_function = EarthquakeBuildingFunction() result = impact_function.metadata().has_exposure(exposure_structure) expected_result = True message = ('I expect %s but I got %s.' % (expected_result, result)) self.assertEqual(result, expected_result, message) impact_function = FloodRasterBuildingFunction() result = impact_function.metadata().has_exposure(exposure_structure) expected_result = True message = ('I expect %s but I got %s.' % (expected_result, result)) self.assertEqual(result, expected_result, message)
def test_get_exposures(self): """Test for get_exposures API.""" impact_function = EarthquakeBuildingFunction() result = impact_function.metadata().get_exposures() expected_result = [exposure_structure] message = ('I expect %s but I got %s.' % (expected_result, result)) self.assertEqual(result, expected_result, message) impact_function = FloodRasterBuildingFunction() result = impact_function.metadata().get_exposures() expected_result = [] message = ('I expect %s but I got %s.' % (expected_result, result)) self.assertNotEqual(result, expected_result, message)
def test_get_hazards(self): """Test for get_hazards API.""" impact_function = EarthquakeBuildingFunction() result = impact_function.metadata().get_hazards() expected_result = [hazard_earthquake] message = ('I expect %s but I got %s.' % (expected_result, result)) self.assertEqual(result, expected_result, message) impact_function = FloodRasterBuildingFunction() result = impact_function.metadata().get_hazards() expected_result = [hazard_flood, hazard_tsunami] message = ('I expect %s but I got %s.' % (expected_result, result)) self.assertEqual(result, expected_result, message)
def test_has_hazard_id(self): """Test for has_hazard_id API.""" impact_function = EarthquakeBuildingFunction() result = impact_function.metadata().has_hazard_id( hazard_earthquake['id']) expected_result = True message = ('I expect %s but I got %s.' % (expected_result, result)) self.assertEqual(result, expected_result, message) impact_function = FloodRasterBuildingFunction() result = impact_function.metadata().has_hazard_id( hazard_earthquake['id']) expected_result = False message = ('I expect %s but I got %s.' % (expected_result, result)) self.assertEqual(result, expected_result, message)