コード例 #1
0
 def test_inner_class(self):
     """Test call inner class."""
     impact_function = EarthquakeBuildingImpactFunction()
     # call from an object
     metadata = impact_function.Metadata()
     metadata_dictionary = metadata.get_metadata()
     assert isinstance(metadata_dictionary, dict), 'I did not got a dict'
     # call from the class
     metadata = impact_function.Metadata
     metadata_dictionary = metadata.get_metadata()
     assert isinstance(metadata_dictionary, dict), 'I did not got a dict'
コード例 #2
0
    def test_subcategories_for_layer(self):
        """Test for subcategories_for_layer API."""
        impact_function = EarthquakeBuildingImpactFunction()
        result = impact_function.Metadata. subcategories_for_layer(
            category='hazard', layer_type='raster', data_type='numeric')
        expected_result = [hazard_earthquake]
        message = ('I expect %s but I got %s.' % (expected_result, result))
        self.assertEqual(result, expected_result, message)

        impact_function = EarthquakeBuildingImpactFunction()
        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)
コード例 #3
0
    def test_allowed_subcategories(self):
        """Test for allowed_subcategories API."""
        impact_function = EarthquakeBuildingImpactFunction()
        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 = CategorisedHazardPopulationImpactFunction()
        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)
コード例 #4
0
    def test_units_for_layer(self):
        """Test for units_for_layer API."""
        impact_function = EarthquakeBuildingImpactFunction()
        result = impact_function.Metadata.units_for_layer(
            subcategory='earthquake', layer_type='raster', data_type='numeric')
        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='numeric')
        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='numeric')
        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 = CategorisedHazardPopulationImpactFunction()
        result = impact_function.Metadata.units_for_layer(
            subcategory='flood', layer_type='raster', data_type='numeric')
        expected_result = [unit_normalised]
        message = ('I expect %s but I got %s.' % (expected_result, result))
        self.assertEqual(result, expected_result, message)
コード例 #5
0
    def test_allowed_units(self):
        """Test for allowed_units API."""
        impact_function = EarthquakeBuildingImpactFunction()
        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', 'numeric')
        expected_result = []
        message = ('I expect %s but I got %s.' % (expected_result, result))
        self.assertEqual(result, expected_result, message)

        impact_function = FloodBuildingImpactFunction
        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', 'numeric')
        expected_result = [unit_wetdry, unit_metres_depth, unit_feet_depth]
        message = ('I expect %s but I got %s.' % (expected_result, result))
        self.assertEqual(result, expected_result, message)
コード例 #6
0
    def test_allowed_data_types(self):
        """Test for allowed_data_types API."""
        impact_function = EarthquakeBuildingImpactFunction()
        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 = ['numeric', 'polygon']
        message = ('I expect %s but I got %s.' % (expected_result, result))
        self.assertItemsEqual(result, expected_result, message)
コード例 #7
0
    def test_has_exposure(self):
        """Test for has_exposure API."""
        impact_function = EarthquakeBuildingImpactFunction()
        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 = FloodRasterBuildingImpactFunction()
        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)
コード例 #8
0
    def test_get_exposures(self):
        """Test for get_exposures API."""
        impact_function = EarthquakeBuildingImpactFunction()
        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 = FloodRasterBuildingImpactFunction()
        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)
コード例 #9
0
    def test_get_hazards(self):
        """Test for get_hazards API."""
        impact_function = EarthquakeBuildingImpactFunction()
        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 = FloodRasterBuildingImpactFunction()
        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)
コード例 #10
0
    def test_has_hazard(self):
        """Test for has_hazard API."""
        impact_function = EarthquakeBuildingImpactFunction()
        result = impact_function.Metadata.has_hazard(hazard_earthquake)
        expected_result = True
        message = ('I expect %s but I got %s.' % (expected_result, result))
        self.assertEqual(result, expected_result, message)

        impact_function = FloodBuildingImpactFunction()
        result = impact_function.Metadata.has_hazard(hazard_earthquake)
        expected_result = False
        message = ('I expect %s but I got %s.' % (expected_result, result))
        self.assertEqual(result, expected_result, message)
コード例 #11
0
    def test_get_available_hazards(self):
        """Test get_available_hazards API."""
        impact_function_manager = ImpactFunctionManager()

        result = impact_function_manager.get_available_hazards()
        expected_result = hazard_all
        message = ('I expect %s but I got %s.' % (expected_result, result))
        self.assertItemsEqual(result, expected_result, message)

        impact_function = EarthquakeBuildingImpactFunction()
        result = impact_function_manager.get_available_hazards(impact_function)
        expected_result = [hazard_earthquake]
        message = ('I expect %s but I got %s.' % (expected_result, result))
        self.assertItemsEqual(result, expected_result, message)
コード例 #12
0
    def test_get_available_exposures(self):
        """Test get_available_exposures API."""
        impact_function_manager = ImpactFunctionManager()

        result = impact_function_manager.get_available_exposures()
        expected_result = [
            exposure_population, exposure_road, exposure_structure
        ]
        message = ('I expect %s but I got %s.' % (expected_result, result))
        self.assertItemsEqual(result, expected_result, message)

        impact_function = EarthquakeBuildingImpactFunction()
        result = impact_function_manager.get_available_exposures(
            impact_function)
        expected_result = [exposure_structure]
        message = ('I expect %s but I got %s.' % (expected_result, result))
        self.assertItemsEqual(result, expected_result, message)
コード例 #13
0
    def test_categories_for_layer(self):
        """Test for categories_for_layer API."""
        impact_function = EarthquakeBuildingImpactFunction()
        result = impact_function.Metadata.categories_for_layer(
            layer_type='raster', data_type='numeric')
        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 = ['hazard', 'exposure']
        message = ('I expect %s but I got %s.' % (expected_result, result))
        self.assertItemsEqual(result, expected_result, message)

        impact_function = CategorisedHazardPopulationImpactFunction()
        result = impact_function.Metadata.categories_for_layer(
            layer_type='raster', data_type='numeric')
        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)
コード例 #14
0
    def test_allowed_layer_constraints(self):
        """Test for allowed_layer_constraints API."""
        impact_function = EarthquakeBuildingImpactFunction()
        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)