def test_allowed_units(self): """Test for allowed_units API.""" impact_function = EarthquakeBuildingFunction() result = impact_function.metadata() .allowed_units( 'structure', 'polygon') expected_result = [unit_building_type_type, unit_building_generic] message = ('I expect %s but I got %s.' % (expected_result, result)) self.assertItemsEqual(result, expected_result, message) result = impact_function.metadata() .allowed_units( 'structure', 'continuous') expected_result = [] message = ('I expect %s but I got %s.' % (expected_result, result)) self.assertEqual(result, expected_result, message) impact_function = FloodRasterBuildingFunction result = impact_function.metadata().allowed_units( 'structure', 'polygon') expected_result = [unit_building_type_type, unit_building_generic] message = ('I expect %s but I got %s.' % (expected_result, result)) self.assertItemsEqual(result, expected_result, message) result = impact_function.metadata()\ .allowed_units('flood', 'continuous') expected_result = [unit_metres_depth, unit_feet_depth] message = ('I expect %s but I got %s.' % (expected_result, result)) self.assertEqual(result, expected_result, message)
def test_allowed_units(self): """Test for allowed_units API.""" impact_function = EarthquakeBuildingFunction() result = impact_function.metadata().allowed_units( 'structure', 'polygon') expected_result = [unit_building_type_type, unit_building_generic] message = ('I expect %s but I got %s.' % (expected_result, result)) self.assertItemsEqual(result, expected_result, message) result = impact_function.metadata().allowed_units( 'structure', 'continuous') expected_result = [] message = ('I expect %s but I got %s.' % (expected_result, result)) self.assertEqual(result, expected_result, message) impact_function = FloodRasterBuildingFunction result = impact_function.metadata().allowed_units( 'structure', 'polygon') expected_result = [unit_building_type_type, unit_building_generic] message = ('I expect %s but I got %s.' % (expected_result, result)) self.assertItemsEqual(result, expected_result, message) result = impact_function.metadata()\ .allowed_units('flood', 'continuous') expected_result = [unit_metres_depth, unit_feet_depth] message = ('I expect %s but I got %s.' % (expected_result, result)) self.assertEqual(result, expected_result, message)
def test_allowed_subcategories(self): """Test for allowed_subcategories API.""" impact_function = EarthquakeBuildingFunction() result = impact_function.metadata().allowed_subcategories( category='hazard') expected_result = [hazard_earthquake] message = ('I expect %s but I got %s.' % (expected_result, result)) self.assertEqual(result, expected_result, message) result = impact_function.metadata().allowed_subcategories( category='exposure') expected_result = [exposure_structure] message = ('I expect %s but I got %s.' % (expected_result, result)) self.assertEqual(result, expected_result, message) result = impact_function.metadata().allowed_subcategories() expected_result = [exposure_structure, hazard_earthquake] message = ('I expect %s but I got %s.' % (expected_result, result)) self.assertEqual(result, expected_result, message) impact_function = ContinuousHazardPopulationFunction() result = impact_function.metadata().allowed_subcategories( category='hazard') expected_result = hazard_all message = ('I expect %s but I got %s.' % (expected_result, result)) self.assertEqual(result, expected_result, message)
def test_exposures_for_layer(self): """Test exposures_for_layer.""" impact_function = EarthquakeBuildingFunction() exposures = impact_function.metadata().exposures_for_layer('polygon') expected = [exposure_structure] self.assertItemsEqual(exposures, expected) exposures = impact_function.metadata().exposures_for_layer('raster') expected = [] self.assertItemsEqual(exposures, expected)
def test_inner_class(self): """Test call inner class.""" impact_function = EarthquakeBuildingFunction() # call from an object metadata = impact_function.metadata() metadata_dictionary = metadata.as_dict() assert isinstance(metadata_dictionary, dict), 'I did not got a dict' # call from the class metadata = impact_function.metadata() metadata_dictionary = metadata.as_dict() assert isinstance(metadata_dictionary, dict), 'I did not got a dict'
def test_allowed_data_types(self): """Test for allowed_data_types API.""" impact_function = EarthquakeBuildingFunction() result = impact_function.metadata().allowed_data_types('structure') expected_result = ['polygon', 'point'] message = ('I expect %s but I got %s.' % (expected_result, result)) self.assertItemsEqual(result, expected_result, message) result = impact_function.metadata().allowed_data_types('earthquake') expected_result = ['continuous'] message = ('I expect %s but I got %s.' % (expected_result, result)) self.assertItemsEqual(result, expected_result, message)
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)
def test_subcategories_for_layer(self): """Test for subcategories_for_layer API.""" impact_function = EarthquakeBuildingFunction() result = impact_function.metadata().subcategories_for_layer( category='hazard', layer_type='raster', data_type='continuous') expected_result = [hazard_earthquake] message = ('I expect %s but I got %s.' % (expected_result, result)) self.assertEqual(result, expected_result, message) impact_function = EarthquakeBuildingFunction() result = impact_function.metadata().subcategories_for_layer( category='exposure', layer_type='vector', data_type='polygon') expected_result = [exposure_structure] message = ('I expect %s but I got %s.' % (expected_result, result)) self.assertEqual(result, expected_result, message)
def test_hazards_for_layer(self): """Test hazards_for_layer""" impact_function = EarthquakeBuildingFunction() hazards = impact_function.metadata().hazards_for_layer( 'raster', 'single_event') expected = [hazard_earthquake] self.assertItemsEqual(hazards, expected) hazards = impact_function.metadata().hazards_for_layer('raster', ) expected = [hazard_earthquake] self.assertItemsEqual(hazards, expected) hazards = impact_function.metadata().hazards_for_layer( 'polygon', 'single_event') expected = [] self.assertItemsEqual(hazards, expected)
def test_hazards_for_layer(self): """Test hazards_for_layer""" impact_function = EarthquakeBuildingFunction() hazards = impact_function.metadata().hazards_for_layer( 'raster', 'single_event') expected = [hazard_earthquake] self.assertItemsEqual(hazards, expected) hazards = impact_function.metadata().hazards_for_layer('raster',) expected = [hazard_earthquake] self.assertItemsEqual(hazards, expected) hazards = impact_function.metadata().hazards_for_layer( 'polygon', 'single_event') expected = [] self.assertItemsEqual(hazards, expected)
def test_purposes_for_layer(self): """Test for purposes_for_layer.""" impact_function = EarthquakeBuildingFunction() layer_purpose = impact_function.metadata().purposes_for_layer( 'polygon') self.assertIsNotNone(layer_purpose) expected_result = [layer_purpose_exposure] self.assertItemsEqual(layer_purpose, expected_result)
def test_hazard_categories_for_layer(self): """Test for hazard_categories_for_layer""" impact_function = EarthquakeBuildingFunction() hazard_categories = impact_function.metadata()\ .hazard_categories_for_layer('raster') expected = [ hazard_category_single_event, hazard_category_multiple_event] self.assertItemsEqual(hazard_categories, expected) hazard_categories = impact_function.metadata() \ .hazard_categories_for_layer('raster', 'earthquake') expected = [ hazard_category_single_event, hazard_category_multiple_event] self.assertItemsEqual(hazard_categories, expected) hazard_categories = impact_function.metadata() \ .hazard_categories_for_layer('polygon') expected = [] self.assertItemsEqual(hazard_categories, expected)
def test_allowed_layer_constraints(self): """Test for allowed_layer_constraints API.""" impact_function = EarthquakeBuildingFunction() result = impact_function.metadata().allowed_layer_constraints() expected_result = [layer_raster_continuous, layer_vector_polygon, layer_vector_point] message = ('I expect %s but I got %s.' % (expected_result, result)) self.assertEqual(result, expected_result, message) result = impact_function.metadata().allowed_layer_constraints( 'hazard') expected_result = [layer_raster_continuous] message = ('I expect %s but I got %s.' % (expected_result, result)) self.assertEqual(result, expected_result, message) result = impact_function.metadata().allowed_layer_constraints( 'exposure') expected_result = [layer_vector_polygon, layer_vector_point] message = ('I expect %s but I got %s.' % (expected_result, result)) self.assertEqual(result, expected_result, message)
def test_allowed_layer_constraints(self): """Test for allowed_layer_constraints API.""" impact_function = EarthquakeBuildingFunction() result = impact_function.metadata().allowed_layer_constraints() expected_result = [ layer_raster_continuous, layer_vector_polygon, layer_vector_point ] message = ('I expect %s but I got %s.' % (expected_result, result)) self.assertEqual(result, expected_result, message) result = impact_function.metadata().allowed_layer_constraints('hazard') expected_result = [layer_raster_continuous] message = ('I expect %s but I got %s.' % (expected_result, result)) self.assertEqual(result, expected_result, message) result = impact_function.metadata().allowed_layer_constraints( 'exposure') expected_result = [layer_vector_polygon, layer_vector_point] message = ('I expect %s but I got %s.' % (expected_result, result)) self.assertEqual(result, expected_result, message)
def test_units_for_layer(self): """Test for units_for_layer API.""" impact_function = EarthquakeBuildingFunction() result = impact_function.metadata().units_for_layer( subcategory='earthquake', layer_type='raster', data_type='continuous') expected_result = [unit_mmi] message = ('I expect %s but I got %s.' % (expected_result, result)) self.assertEqual(result, expected_result, message) result = impact_function.metadata().units_for_layer( subcategory='flood', layer_type='raster', data_type='continuous') expected_result = [] message = ('I expect %s but I got %s.' % (expected_result, result)) self.assertEqual(result, expected_result, message) result = impact_function.metadata().units_for_layer( subcategory='earthquake', layer_type='vector', data_type='continuous') expected_result = [] message = ('I expect %s but I got %s.' % (expected_result, result)) self.assertEqual(result, expected_result, message) result = impact_function.metadata().units_for_layer( subcategory='earthquake', layer_type='raster', data_type='polygon') expected_result = [] message = ('I expect %s but I got %s.' % (expected_result, result)) self.assertEqual(result, expected_result, message) impact_function = ContinuousHazardPopulationFunction() result = impact_function.metadata().units_for_layer( subcategory='flood', layer_type='raster', data_type='continuous') expected_result = [] message = ('I expect %s but I got %s.' % (expected_result, result)) self.assertEqual(result, expected_result, message)
def test_categories_for_layer(self): """Test for categories_for_layer API.""" impact_function = EarthquakeBuildingFunction() result = impact_function.metadata().categories_for_layer( layer_type='raster', data_type='continuous') expected_result = ['hazard'] message = ('I expect %s but I got %s.' % (expected_result, result)) self.assertEqual(result, expected_result, message) result = impact_function.metadata().categories_for_layer( layer_type='vector', data_type='line') expected_result = [] message = ('I expect %s but I got %s.' % (expected_result, result)) self.assertEqual(result, expected_result, message) result = impact_function.metadata().categories_for_layer( layer_type='vector', data_type='polygon') expected_result = ['exposure'] message = ('I expect %s but I got %s.' % (expected_result, result)) self.assertItemsEqual(result, expected_result, message) impact_function = ContinuousHazardPopulationFunction() result = impact_function.metadata().categories_for_layer( layer_type='raster', data_type='continuous') expected_result = ['exposure', 'hazard'] message = ('I expect %s but I got %s.' % (expected_result, result)) self.assertListEqual(result, expected_result, message) result = impact_function.metadata().categories_for_layer( layer_type='vector', data_type='line') expected_result = [] message = ('I expect %s but I got %s.' % (expected_result, result)) self.assertEqual(result, expected_result, message) result = impact_function.metadata().categories_for_layer( layer_type='vector', data_type='polygon') expected_result = [] message = ('I expect %s but I got %s.' % (expected_result, result)) self.assertItemsEqual(result, expected_result, message) result = impact_function.metadata().categories_for_layer( layer_type='vector', data_type='point') expected_result = [] message = ('I expect %s but I got %s.' % (expected_result, result)) self.assertItemsEqual(result, expected_result, message)