def test_remove_item_by_value(self): """Test remove item by its value works.""" make_padang_layer() dialog = KeywordsDialog(PARENT, IFACE) dialog.remove_item_by_value('hazard') keywords = dialog.get_keywords() expected_keywords = { 'source': 'USGS', 'title': 'An earthquake in Padang like in 2009', 'subcategory': 'earthquake', 'unit': 'MMI'} self.assertEqual(keywords, expected_keywords)
def test_load_state_from_keywords(self): """Test load state from keywords works.""" layer = make_padang_layer() dialog = KeywordsDialog(PARENT, IFACE, layer=layer) dialog.load_state_from_keywords() keywords = dialog.get_keywords() expected_keywords = { 'title': 'An earthquake in Padang like in 2009', 'category': 'hazard', 'source': 'USGS', 'subcategory': 'earthquake', 'unit': 'MMI'} self.assertEqual(keywords, expected_keywords)
def test_remove_item_by_value(self): """Test remove item by its value works""" make_padang_layer() dialog = KeywordsDialog(PARENT, IFACE) dialog.remove_item_by_value('hazard') keywords = dialog.get_keywords() expected_keywords = { 'source': 'USGS', 'title': 'An earthquake in Padang like in 2009', 'subcategory': 'earthquake', 'unit': 'MMI' } self.assertEqual(keywords, expected_keywords)
def test_layer_without_keywords(self): """Test load state from keywords works""" myDialog = KeywordsDialog(PARENT, IFACE) myLayer = make_keywordless_layer() myDialog.layer = myLayer myDialog.load_state_from_keywords() myKeywords = myDialog.get_keywords() #check that a default title is given (see #https://github.com/AIFDR/inasafe/issues/111) myExpectedKeywords = { 'category': 'exposure', 'title': 'Keywordless Layer'} myMessage = ('\nGot: %s\nExpected: %s\n' % (myKeywords, myExpectedKeywords)) assert myKeywords == myExpectedKeywords, myMessage
def test_removeItemByValue(self): """Test remove item by its value works""" makePadangLayer() myDialog = KeywordsDialog(PARENT, IFACE) myDialog.remove_item_by_value('hazard') myKeywords = myDialog.get_keywords() myExpectedKeywords = {'source': 'USGS', 'title': 'An earthquake in Padang like in 2009', 'subcategory': 'earthquake', 'unit': 'MMI'} myMessage = ('\nGot: %s\nExpected: %s\n' % (myKeywords, myExpectedKeywords)) assert myKeywords == myExpectedKeywords, myMessage
def test_load_state_from_keywords(self): """Test load state from keywords works.""" layer = make_padang_layer() dialog = KeywordsDialog(PARENT, IFACE, layer=layer) dialog.load_state_from_keywords() keywords = dialog.get_keywords() expected_keywords = { 'title': 'An earthquake in Padang like in 2009', 'category': 'hazard', 'source': 'USGS', 'subcategory': 'earthquake', 'unit': 'MMI' } self.assertEqual(keywords, expected_keywords)
def test_loadStateFromKeywords(self): """Test load state from keywords works""" myDialog = KeywordsDialog(PARENT, IFACE) myLayer = makePadangLayer() myDialog.layer = myLayer myDialog.load_state_from_keywords() myKeywords = myDialog.get_keywords() myExpectedKeywords = {'title': 'An earthquake in Padang like in 2009', 'category': 'hazard', 'source': 'USGS', 'subcategory': 'earthquake', 'unit': 'MMI'} myMessage = ('\nGot:\n%s\nExpected:\n%s\n' % (myKeywords, myExpectedKeywords)) assert myKeywords == myExpectedKeywords, myMessage
def test_check_aggregation(self): """Test for keywords dialog's behavior for aggregation layer.""" layer = clone_shp_layer( name='kabupaten_jakarta', include_keywords=True, source_directory=BOUNDDATA) dialog = KeywordsDialog(PARENT, IFACE, layer=layer) # Load existing keywords keywords = dialog.get_keywords() expected_keywords = { 'category': 'postprocessing', 'aggregation attribute': 'KAB_NAME', 'title': 'kabupaten jakarta', 'elderly ratio attribute': 'Global default', 'youth ratio default': '0.263', 'source': 'OpenStreetMap', 'elderly ratio default': '0.078', 'adult ratio attribute': 'Global default', 'female ratio attribute': 'Global default', 'youth ratio attribute': 'Global default', 'female ratio default': '0.5', 'adult ratio default': '0.659'} message = 'Expected %s but I got %s' % (expected_keywords, keywords) self.assertDictEqual(expected_keywords, keywords, message) good_sum_ratio, _ = dialog.age_ratios_are_valid(keywords) message = 'Expected %s but I got %s' % (True, good_sum_ratio) self.assertEqual(True, good_sum_ratio, message) # Change youth ratio attribute to Don't Use dialog.cboYouthRatioAttribute.setCurrentIndex(1) keywords = dialog.get_keywords() expected_keywords = { 'category': 'postprocessing', 'aggregation attribute': 'KAB_NAME', 'title': 'kabupaten jakarta', 'elderly ratio attribute': 'Global default', 'source': 'OpenStreetMap', 'elderly ratio default': '0.078', 'adult ratio attribute': 'Global default', 'female ratio attribute': 'Global default', 'youth ratio attribute': 'Don\'t use', 'female ratio default': '0.5', 'adult ratio default': '0.659'} message = 'Expected %s but I got %s' % (expected_keywords, keywords) self.assertDictEqual(expected_keywords, keywords, message) good_sum_ratio, _ = dialog.age_ratios_are_valid(keywords) message = 'Expected %s but I got %s' % (True, good_sum_ratio) self.assertEqual(True, good_sum_ratio, message) # Change youth ratio attribute to Global Default # Change youth ratio default to 0.99 dialog.cboYouthRatioAttribute.setCurrentIndex(0) dialog.dsbYouthRatioDefault.setValue(0.99) keywords = dialog.get_keywords() expected_keywords = { 'category': 'postprocessing', 'aggregation attribute': 'KAB_NAME', 'title': 'kabupaten jakarta', 'elderly ratio attribute': 'Global default', 'youth ratio default': '0.99', 'source': 'OpenStreetMap', 'elderly ratio default': '0.078', 'adult ratio attribute': 'Global default', 'female ratio attribute': 'Global default', 'youth ratio attribute': 'Global default', 'female ratio default': '0.5', 'adult ratio default': '0.659'} message = 'Expected %s but I got %s' % (expected_keywords, keywords) self.assertDictEqual(expected_keywords, keywords, message) good_sum_ratio, _ = dialog.age_ratios_are_valid(keywords) message = 'Expected %s but I got %s' % (False, good_sum_ratio) self.assertEqual(False, good_sum_ratio, message) # We need to delete reference to layer on Windows before removing # the files del layer del dialog.layer # Using clone_shp_layer the files are saved in testing dir under # InaSAFE temp dir shutil.rmtree(temp_dir(sub_dir='testing'))
def test_check_aggregation(self): """Test for keywords dialog's behavior for aggregation layer.""" layer = clone_shp_layer(name='kabupaten_jakarta', include_keywords=True, source_directory=BOUNDDATA) dialog = KeywordsDialog(PARENT, IFACE, layer=layer) # Load existing keywords keywords = dialog.get_keywords() expected_keywords = { 'category': 'postprocessing', 'aggregation attribute': 'KAB_NAME', 'title': 'kabupaten jakarta', 'elderly ratio attribute': 'Global default', 'youth ratio default': '0.263', 'source': 'OpenStreetMap', 'elderly ratio default': '0.078', 'adult ratio attribute': 'Global default', 'female ratio attribute': 'Global default', 'youth ratio attribute': 'Global default', 'female ratio default': '0.5', 'adult ratio default': '0.659' } message = 'Expected %s but I got %s' % (expected_keywords, keywords) self.assertDictEqual(expected_keywords, keywords, message) good_sum_ratio, _ = dialog.age_ratios_are_valid(keywords) message = 'Expected %s but I got %s' % (True, good_sum_ratio) self.assertEqual(True, good_sum_ratio, message) # Change youth ratio attribute to Don't Use dialog.cboYouthRatioAttribute.setCurrentIndex(1) keywords = dialog.get_keywords() expected_keywords = { 'category': 'postprocessing', 'aggregation attribute': 'KAB_NAME', 'title': 'kabupaten jakarta', 'elderly ratio attribute': 'Global default', 'source': 'OpenStreetMap', 'elderly ratio default': '0.078', 'adult ratio attribute': 'Global default', 'female ratio attribute': 'Global default', 'youth ratio attribute': 'Don\'t use', 'female ratio default': '0.5', 'adult ratio default': '0.659' } message = 'Expected %s but I got %s' % (expected_keywords, keywords) self.assertDictEqual(expected_keywords, keywords, message) good_sum_ratio, _ = dialog.age_ratios_are_valid(keywords) message = 'Expected %s but I got %s' % (True, good_sum_ratio) self.assertEqual(True, good_sum_ratio, message) # Change youth ratio attribute to Global Default # Change youth ratio default to 0.99 dialog.cboYouthRatioAttribute.setCurrentIndex(0) dialog.dsbYouthRatioDefault.setValue(0.99) keywords = dialog.get_keywords() expected_keywords = { 'category': 'postprocessing', 'aggregation attribute': 'KAB_NAME', 'title': 'kabupaten jakarta', 'elderly ratio attribute': 'Global default', 'youth ratio default': '0.99', 'source': 'OpenStreetMap', 'elderly ratio default': '0.078', 'adult ratio attribute': 'Global default', 'female ratio attribute': 'Global default', 'youth ratio attribute': 'Global default', 'female ratio default': '0.5', 'adult ratio default': '0.659' } message = 'Expected %s but I got %s' % (expected_keywords, keywords) self.assertDictEqual(expected_keywords, keywords, message) good_sum_ratio, _ = dialog.age_ratios_are_valid(keywords) message = 'Expected %s but I got %s' % (False, good_sum_ratio) self.assertEqual(False, good_sum_ratio, message) # We need to delete reference to layer on Windows before removing # the files del layer del dialog.layer # Using clone_shp_layer the files are saved in testing dir under # InaSAFE temp dir shutil.rmtree(temp_dir(sub_dir='testing'))