def __init__(self): """ Constructor for postprocessor class. It takes care of defining self.impact_total """ BuildingTypePostprocessor.__init__(self) # Note: Do we need these explicityl defined? With new osm-reporter # changes you already get a nicely named list in the 'type' field self.fields_values = OrderedDict( [ ("Motorway / highway", ["Motorway or highway"]), ("Motorway link", ["Motorway link"]), ("Primary road", ["Primary road"]), ("Primary link", ["Primary link"]), ("Tertiary", ["Tertiary"]), ("Tertiary link", ["Tertiary link"]), ("Secondary", ["Secondary"]), ("Secondary link", ["Secondary link"]), ("Road, residential, living street, etc.", ["Road, residential, living street, etc."]), ("Track", ["Track"]), ("Cycleway, footpath, etc.", ["Cycleway, footpath, etc."]), ("Other", []), ] ) self.known_types = [] self._update_known_types()
def __init__(self): """ Constructor for postprocessor class. It takes care of defining self.impact_total """ BuildingTypePostprocessor.__init__(self) # Note: Do we need these explicityl defined? With new osm-reporter # changes you already get a nicely named list in the 'type' field self.fields_values = OrderedDict([ ('Motorway / highway', ['Motorway or highway']), ('Motorway link', ['Motorway link']), ('Primary road', ['Primary road']), ('Primary link', ['Primary link']), ('Tertiary', ['Tertiary']), ('Tertiary link', ['Tertiary link']), ('Secondary', ['Secondary']), ('Secondary link', ['Secondary link']), ('Road, residential, living street, etc.', ['Road, residential, living street, etc.']), ('Track', ['Track']), ('Cycleway, footpath, etc.', ['Cycleway, footpath, etc.']), ('Other', []) ]) self.known_types = [] self._update_known_types()
Test building type postprocessor """ __author__ = 'Christian Christelis <*****@*****.**>' __revision__ = '2125fd80224d97278a3e4b80775a678d109f3bf7' __date__ = '21/07/2015' __license__ = "GPL" __copyright__ = 'Copyright 2012, Australia Indonesia Facility for ' __copyright__ += 'Disaster Reduction' import unittest from safe.postprocessors.building_type_postprocessor import ( BuildingTypePostprocessor) POSTPROCESSOR = BuildingTypePostprocessor() class TestBuildingTypePostprocessor(unittest.TestCase): def tearDown(self): """Run after each test.""" POSTPROCESSOR.clear() def test_process_integer_values(self): """Test for checking if the ratio is wrong (total is more than one).""" # ratios_total < 1 should pass params = { 'impact_total': 0, 'key_attribute': 'type',
class TestBuildingTypePostprocessor(unittest.TestCase): postprocessor = BuildingTypePostprocessor() def tearDown(self): """Run after each test.""" self.postprocessor.clear() def test_process_integer_values(self): """Test for checking when the value is integer.""" params = { 'impact_total': 0, 'key_attribute': 'type', 'Building type': True, 'target_field': 'affected', 'value_mapping': { 'government': ['Government'] }, 'impact_attrs': [ { 'type': 'Government', 'affected': 1 }, { 'type': 'Government', 'affected': 0 }, { 'type': 'Government', 'affected': 1 }, { 'type': 'Government', 'affected': 0 }, ] } self.postprocessor.setup(params) self.postprocessor.process() results = self.postprocessor.results() self.assertEqual(results['Government']['value'], '2') def test_process_string_values(self): """Test for checking when the value is string.""" params = { 'impact_total': 0, 'key_attribute': 'type', 'Building type': True, 'target_field': 'affected', 'value_mapping': { 'government': ['Government'] }, 'impact_attrs': [ { 'type': 'Government', 'affected': 'Zone 1' }, { 'type': 'Government', 'affected': 'Not Affected' }, { 'type': 'Government', 'affected': 'Zone 1' }, { 'type': 'Government', 'affected': 'Not Affected' }, ] } self.postprocessor.setup(params) self.postprocessor.process() results = self.postprocessor.results() self.assertEqual(results['Government']['value'], '2') def test_total_affected_calculated_correctly(self): """Test for checking the total affected and value mapping""" params = { 'impact_total': 0, 'key_attribute': 'type', 'Building type': True, 'target_field': 'affected', 'value_mapping': { 'government': ['Government'], 'economy': ['Economy'], }, 'impact_attrs': [ { 'type': 'Government', 'affected': 'Zone 1' }, { 'type': 'Museum', 'affected': 'Zone 2' }, { 'type': 'Government', 'affected': 'Zone 1' }, { 'type': 'Government', 'affected': 'Not Affected' }, { 'type': 'School', 'affected': 'Zone 3' }, ] } self.postprocessor.setup(params) self.postprocessor.process() results = self.postprocessor.results() self.assertEqual(results['Government']['value'], '2') self.assertEqual(results['Other']['value'], '2') self.postprocessor.clear() # Same as above, but we add the school in the value mapping. params = { 'impact_total': 0, 'key_attribute': 'type', 'Building type': True, 'target_field': 'affected', 'value_mapping': { 'government': ['Government', 'School'], 'economy': ['Economy'], }, 'impact_attrs': [ { 'type': 'Government', 'affected': 'Zone 1' }, { 'type': 'Museum', 'affected': 'Zone 2' }, { 'type': 'Government', 'affected': 'Zone 1' }, { 'type': 'Government', 'affected': 'Not Affected' }, { 'type': 'School', 'affected': 'Zone 3' }, ] } self.postprocessor.setup(params) self.postprocessor.process() results = self.postprocessor.results() self.assertEqual(results['Government']['value'], '3') self.assertEqual(results['Other']['value'], '1')