Exemplo n.º 1
0
    def test_on_rad_postprocessing_toggled(self):
        """Test postprocessing radio button toggle behaviour works"""
        layer = clone_shp_layer(name='district_osm_jakarta',
                                include_keywords=True,
                                source_directory=test_data_path('boundaries'))
        defaults = get_defaults()
        dialog = KeywordsDialog(PARENT, IFACE, layer=layer)
        # Click hazard/exposure button first so that it won't take default
        # from keywords file
        dialog.radExposure.click()

        # Now click the postprocessing button
        button = dialog.radPostprocessing
        button.click()
        message = ('Toggling the postprocessing radio did not add a '
                   'category to the keywords list.')
        self.assertEqual(dialog.get_value_for_key('category'),
                         'postprocessing', message)

        message = ('Toggling the postprocessing radio did not add an '
                   'aggregation attribute to the keywords list.')
        self.assertEqual(dialog.get_value_for_key(defaults['AGGR_ATTR_KEY']),
                         'KAB_NAME', message)

        message = ('Toggling the postprocessing radio did not add a '
                   'female ratio attribute to the keywords list.')
        self.assertEqual(
            dialog.get_value_for_key(defaults['FEMALE_RATIO_ATTR_KEY']),
            dialog.global_default_string, message)

        message = ('Toggling the postprocessing radio did not add a '
                   'female ratio default value to the keywords list.')
        self.assertEqual(
            float(dialog.get_value_for_key(defaults['FEMALE_RATIO_KEY'])),
            defaults['FEMALE_RATIO'], message)
Exemplo n.º 2
0
    def test_on_dsb_female_ratio_default_value_changed(self):
        """Test hazard radio button toggle behaviour works"""
        layer = clone_shp_layer(name='district_osm_jakarta',
                                include_keywords=True,
                                source_directory=test_data_path('boundaries'))
        defaults = get_defaults()
        dialog = KeywordsDialog(PARENT, IFACE, layer=layer)
        button = dialog.radPostprocessing
        button.setChecked(False)
        button.click()
        female_ratio_box = dialog.cboFemaleRatioAttribute

        # set to Don't use
        index = female_ratio_box.findText(dialog.do_not_use_string)
        message = (dialog.do_not_use_string + ' not found')
        self.assertNotEqual(index, -1, message)
        female_ratio_box.setCurrentIndex(index)

        message = ('Toggling the female ratio attribute combo to'
                   ' "Don\'t use" did not add it to the keywords list.')
        self.assertEqual(
            dialog.get_value_for_key(defaults['FEMALE_RATIO_ATTR_KEY']),
            dialog.do_not_use_string, message)

        message = ('Toggling the female ratio attribute combo to'
                   ' "Don\'t use" did not disable dsbFemaleRatioDefault.')
        is_enabled = dialog.dsbFemaleRatioDefault.isEnabled()
        assert not is_enabled, message

        message = ('Toggling the female ratio attribute combo to'
                   ' "Don\'t use" did not remove the keyword.')
        assert (dialog.get_value_for_key(defaults['FEMALE_RATIO']) is None), \
            message

        # set to PEREMPUAN attribute
        attribute = 'PEREMPUAN'
        index = female_ratio_box.findText(attribute)
        message = 'The attribute %s is not found in the layer' % attribute
        self.assertNotEqual(index, -1, message)

        female_ratio_box.setCurrentIndex(index)
        message = ('Toggling the female ratio attribute combo to %s'
                   ' did not add it to the keywords list.') % attribute
        self.assertEqual(
            dialog.get_value_for_key(defaults['FEMALE_RATIO_ATTR_KEY']),
            attribute, message)

        message = ('Toggling the female ratio attribute combo to %s'
                   ' did not disable dsbFemaleRatioDefault.') % attribute
        is_enabled = dialog.dsbFemaleRatioDefault.isEnabled()
        self.assertFalse(is_enabled, message)

        message = ('Toggling the female ratio attribute combo to %s'
                   ' did not remove the keyword.') % attribute
        self.assertIsNone(dialog.get_value_for_key(defaults['FEMALE_RATIO']),
                          message)
Exemplo n.º 3
0
 def Xtest_add_warnings_for_colons(self):
     """Test add add warning fot colons."""
     dialog = KeywordsDialog(PARENT, IFACE)
     dialog.reset(False)
     dialog.add_list_entry('bar', 'fo:o')
     result = dialog.get_value_for_key('bar')
     expected_result = 'fo.o'
     message = '\nGot: %s\nExpected: %s\n' % (result, expected_result)
     self.assertEqual(result, expected_result, message)
     #
     # Check the user gets a message if they put colons in the value
     #
     expected_result = 'Colons are not allowed, replaced with "."'
     result = str(dialog.lblMessage.text())
     message = ('lblMessage error \nGot: %s\nExpected: %s\n' %
                (result, expected_result))
     self.assertEqual(result, expected_result, message)
     #
     # Check the user gets a message if they put colons in the key
     #
     dialog.add_list_entry('ba:r', 'foo')
     expected_result = 'Colons are not allowed, replaced with "."'
     result = str(dialog.lblMessage.text())
     message = ('lblMessage error \nGot: %s\nExpected: %s\n' %
                (result, expected_result))
     self.assertEqual(result, expected_result, message)
 def Xtest_add_warnings_for_colons(self):
     """Test add add warning fot colons."""
     dialog = KeywordsDialog(PARENT, IFACE)
     dialog.reset(False)
     dialog.add_list_entry('bar', 'fo:o')
     result = dialog.get_value_for_key('bar')
     expected_result = 'fo.o'
     message = '\nGot: %s\nExpected: %s\n' % (result, expected_result)
     self.assertEqual(result, expected_result, message)
     #
     # Check the user gets a message if they put colons in the value
     #
     expected_result = 'Colons are not allowed, replaced with "."'
     result = str(dialog.lblMessage.text())
     message = (
         'lblMessage error \nGot: %s\nExpected: %s\n' %
         (result, expected_result))
     self.assertEqual(result, expected_result, message)
     #
     # Check the user gets a message if they put colons in the key
     #
     dialog.add_list_entry('ba:r', 'foo')
     expected_result = 'Colons are not allowed, replaced with "."'
     result = str(dialog.lblMessage.text())
     message = (
         'lblMessage error \nGot: %s\nExpected: %s\n' %
         (result, expected_result))
     self.assertEqual(result, expected_result, message)
Exemplo n.º 5
0
 def test_set_category(self):
     """Test set category works."""
     dialog = KeywordsDialog(PARENT, IFACE)
     dialog.reset(False)
     dialog.set_category('hazard')
     expected_result = 'hazard'
     result = dialog.get_value_for_key('category')
     message = '\nGot: %s\nExpected: %s\n' % (result, expected_result)
     self.assertEqual(result, expected_result, message)
Exemplo n.º 6
0
 def test_add_list_entry(self):
     """Test add entry to list works."""
     dialog = KeywordsDialog(PARENT, IFACE)
     dialog.reset(False)
     dialog.add_list_entry('bar', 'foo')
     result = dialog.get_value_for_key('bar')
     expected_result = 'foo'
     message = '\nGot: %s\nExpected: %s\n' % (result, expected_result)
     self.assertEqual(result, expected_result, message)
 def test_add_list_entry(self):
     """Test add entry to list works."""
     dialog = KeywordsDialog(PARENT, IFACE)
     dialog.reset(False)
     dialog.add_list_entry('bar', 'foo')
     result = dialog.get_value_for_key('bar')
     expected_result = 'foo'
     message = '\nGot: %s\nExpected: %s\n' % (result, expected_result)
     self.assertEqual(result, expected_result, message)
 def test_set_category(self):
     """Test set category works."""
     dialog = KeywordsDialog(PARENT, IFACE)
     dialog.reset(False)
     dialog.set_category('hazard')
     expected_result = 'hazard'
     result = dialog.get_value_for_key('category')
     message = '\nGot: %s\nExpected: %s\n' % (result, expected_result)
     self.assertEqual(result, expected_result, message)
    def test_on_rad_postprocessing_toggled(self):
        """Test postprocessing radio button toggle behaviour works"""
        layer = clone_shp_layer(
            name='district_osm_jakarta',
            include_keywords=True,
            source_directory=test_data_path('boundaries'))
        defaults = get_defaults()
        dialog = KeywordsDialog(PARENT, IFACE, layer=layer)
        # Click hazard/exposure button first so that it won't take default
        # from keywords file
        dialog.radExposure.click()

        # Now click the postprocessing button
        button = dialog.radPostprocessing
        button.click()
        message = (
            'Toggling the postprocessing radio did not add a '
            'category to the keywords list.')
        self.assertEqual(
            dialog.get_value_for_key('category'), 'postprocessing', message)

        message = (
            'Toggling the postprocessing radio did not add an '
            'aggregation attribute to the keywords list.')
        self.assertEqual(
            dialog.get_value_for_key(defaults['AGGR_ATTR_KEY']),
            'KAB_NAME',
            message)

        message = (
            'Toggling the postprocessing radio did not add a '
            'female ratio attribute to the keywords list.')
        self.assertEqual(
            dialog.get_value_for_key(defaults['FEMALE_RATIO_ATTR_KEY']),
            dialog.global_default_string,
            message)

        message = (
            'Toggling the postprocessing radio did not add a '
            'female ratio default value to the keywords list.')
        self.assertEqual(
            float(dialog.get_value_for_key(defaults['FEMALE_RATIO_KEY'])),
            defaults['FEMALE_RATIO'],
            message)
Exemplo n.º 10
0
 def test_on_rad_hazard_toggled(self):
     """Test hazard radio button toggle behaviour works"""
     dialog = KeywordsDialog(PARENT, IFACE)
     button = dialog.radHazard
     button.setChecked(False)
     button.click()
     message = ('Toggling the hazard radio did not add a category '
                'to the keywords list.')
     self.assertEqual(dialog.get_value_for_key('category'), 'hazard',
                      message)
 def test_on_rad_hazard_toggled(self):
     """Test hazard radio button toggle behaviour works"""
     dialog = KeywordsDialog(PARENT, IFACE)
     button = dialog.radHazard
     button.setChecked(False)
     button.click()
     message = (
         'Toggling the hazard radio did not add a category '
         'to the keywords list.')
     self.assertEqual(
         dialog.get_value_for_key('category'), 'hazard',
         message)
Exemplo n.º 12
0
 def test_on_pbn_add_to_list1_clicked(self):
     """Test adding an item to the list using predefined form works"""
     dialog = KeywordsDialog(PARENT, IFACE, layer=None)
     dialog.reset(False)
     dialog.radPredefined.setChecked(True)
     dialog.cboKeyword.setCurrentIndex(2)
     expected_result = 'foo'
     dialog.lePredefinedValue.setText(expected_result)
     dialog.on_pbnAddToList1_clicked()
     result = dialog.get_value_for_key('datatype')
     message = '\nGot: %s\nExpected: %s\n' % (result, expected_result)
     self.assertEqual(result, expected_result, message)
 def test_on_pbn_add_to_list1_clicked(self):
     """Test adding an item to the list using predefined form works"""
     dialog = KeywordsDialog(PARENT, IFACE, layer=None)
     dialog.reset(False)
     dialog.radPredefined.setChecked(True)
     dialog.cboKeyword.setCurrentIndex(2)
     expected_result = 'foo'
     dialog.lePredefinedValue.setText(expected_result)
     dialog.on_pbnAddToList1_clicked()
     result = dialog.get_value_for_key('datatype')
     message = '\nGot: %s\nExpected: %s\n' % (result, expected_result)
     self.assertEqual(result, expected_result, message)
Exemplo n.º 14
0
 def test_on_radExposure_toggled(self):
     """Test exposure radio button toggle behaviour works"""
     dialog = KeywordsDialog(PARENT, IFACE)
     # Set other radio button checked first so that radExposure is not
     # toggled
     dialog.radHazard.setChecked(True)
     # Then click the radExposure
     button = dialog.radExposure
     button.click()
     message = ('Toggling the exposure radio did not add a category '
                'to the keywords list.')
     assert dialog.get_value_for_key('category') == 'exposure', message
Exemplo n.º 15
0
 def test_on_pbn_add_to_list2_clicked(self):
     """Test adding an item to the list using user defined form works"""
     dialog = KeywordsDialog(PARENT, IFACE)
     dialog.reset(False)
     dialog.radUserDefined.setChecked(True)
     dialog.leKey.setText('foo')
     dialog.leValue.setText('bar')
     expected_result = 'bar'
     dialog.lePredefinedValue.setText(expected_result)
     dialog.on_pbnAddToList2_clicked()
     result = dialog.get_value_for_key('foo')
     message = '\nGot: %s\nExpected: %s\n' % (result, expected_result)
     self.assertEqual(result, expected_result, message)
 def test_on_pbn_add_to_list2_clicked(self):
     """Test adding an item to the list using user defined form works"""
     dialog = KeywordsDialog(PARENT, IFACE)
     dialog.reset(False)
     dialog.radUserDefined.setChecked(True)
     dialog.leKey.setText('foo')
     dialog.leValue.setText('bar')
     expected_result = 'bar'
     dialog.lePredefinedValue.setText(expected_result)
     dialog.on_pbnAddToList2_clicked()
     result = dialog.get_value_for_key('foo')
     message = '\nGot: %s\nExpected: %s\n' % (result, expected_result)
     self.assertEqual(result, expected_result, message)
 def test_on_radExposure_toggled(self):
     """Test exposure radio button toggle behaviour works"""
     dialog = KeywordsDialog(PARENT, IFACE)
     # Set other radio button checked first so that radExposure is not
     # toggled
     dialog.radHazard.setChecked(True)
     # Then click the radExposure
     button = dialog.radExposure
     button.click()
     message = (
         'Toggling the exposure radio did not add a category '
         'to the keywords list.')
     assert dialog.get_value_for_key('category') == 'exposure', message
Exemplo n.º 18
0
 def test_get_value_for_key(self):
     """Test get_value_for_key works."""
     layer = clone_raster_layer(name='tsunami_wgs84',
                                extension='.tif',
                                include_keywords=True,
                                source_directory=test_data_path('hazard'))
     dialog = KeywordsDialog(PARENT, IFACE, layer=layer)
     key = 'category'
     expected_value = 'hazard'
     value = dialog.get_value_for_key(key)
     message = 'The value for key %s should be %s, but it returns %s' % (
         key, expected_value, value)
     self.assertEqual(value, expected_value, message)
 def test_get_value_for_key(self):
     """Test get_value_for_key works."""
     layer = clone_raster_layer(
         name='tsunami_wgs84',
         extension='.tif',
         include_keywords=True,
         source_directory=test_data_path('hazard')
     )
     dialog = KeywordsDialog(PARENT, IFACE, layer=layer)
     key = 'category'
     expected_value = 'hazard'
     value = dialog.get_value_for_key(key)
     message = 'The value for key %s should be %s, but it returns %s' % (
         key, expected_value, value)
     self.assertEqual(value, expected_value, message)
Exemplo n.º 20
0
    def test_on_subcategory_currentindexchanged(self):
        """Test subcategory combo change event works"""
        dialog = KeywordsDialog(PARENT, IFACE)
        button = dialog.radHazard
        button.setChecked(True)
        button = dialog.radExposure
        button.click()
        combo = dialog.cboSubcategory
        combo.setCurrentIndex(1)  # change from 'Not set' to 'structure'
        message = (
            'Changing the subcategory did not add %s to the keywords list' %
            combo.currentText())
        key = dialog.get_value_for_key('subcategory')

        self.assertTrue(key is not None, message)
        assert key in str(combo.currentText()), message
    def test_on_subcategory_currentindexchanged(self):
        """Test subcategory combo change event works"""
        dialog = KeywordsDialog(PARENT, IFACE)
        button = dialog.radHazard
        button.setChecked(True)
        button = dialog.radExposure
        button.click()
        combo = dialog.cboSubcategory
        combo.setCurrentIndex(1)  # change from 'Not set' to 'structure'
        message = (
            'Changing the subcategory did not add %s to the keywords list' %
            combo.currentText())
        key = dialog.get_value_for_key('subcategory')

        self.assertTrue(key is not None, message)
        assert key in str(combo.currentText()), message
Exemplo n.º 22
0
    def test_add_user_defined_keyword(self):
        """Test add user defined keyword when ok button is pressed."""
        layer = clone_raster_layer(name='padang_tsunami_mw8',
                                   extension='.tif',
                                   include_keywords=True,
                                   source_directory=test_data_path('hazard'))
        # Set the keywords dialog
        dialog = KeywordsDialog(PARENT, IFACE, layer=layer)
        dialog.radUserDefined.setChecked(True)
        dialog.leKey.setText('foo')
        dialog.leValue.setText('bar')
        ok_button = dialog.buttonBox.button(QtGui.QDialogButtonBox.Ok)
        ok_button.click()

        expected_result = 'bar'
        result = dialog.get_value_for_key('foo')
        message = 'The key %s should have value %s, but it returns %s' % (
            'foo', expected_result, result)
        self.assertEqual(result, expected_result, message)
    def test_add_user_defined_keyword(self):
        """Test add user defined keyword when ok button is pressed."""
        layer = clone_raster_layer(
            name='padang_tsunami_mw8',
            extension='.tif',
            include_keywords=True,
            source_directory=test_data_path('hazard')
        )
        # Set the keywords dialog
        dialog = KeywordsDialog(PARENT, IFACE, layer=layer)
        dialog.radUserDefined.setChecked(True)
        dialog.leKey.setText('foo')
        dialog.leValue.setText('bar')
        ok_button = dialog.buttonBox.button(QtGui.QDialogButtonBox.Ok)
        ok_button.click()

        expected_result = 'bar'
        result = dialog.get_value_for_key('foo')
        message = 'The key %s should have value %s, but it returns %s' % (
            'foo', expected_result, result)
        self.assertEqual(result, expected_result, message)
    def test_on_dsb_female_ratio_default_value_changed(self):
        """Test hazard radio button toggle behaviour works"""
        layer = clone_shp_layer(
            name='district_osm_jakarta',
            include_keywords=True,
            source_directory=test_data_path('boundaries'))
        defaults = get_defaults()
        dialog = KeywordsDialog(PARENT, IFACE, layer=layer)
        button = dialog.radPostprocessing
        button.setChecked(False)
        button.click()
        female_ratio_box = dialog.cboFemaleRatioAttribute

        # set to Don't use
        index = female_ratio_box.findText(dialog.do_not_use_string)
        message = (dialog.do_not_use_string + ' not found')
        self.assertNotEqual(index, -1, message)
        female_ratio_box.setCurrentIndex(index)

        message = (
            'Toggling the female ratio attribute combo to'
            ' "Don\'t use" did not add it to the keywords list.')
        self.assertEqual(
            dialog.get_value_for_key(defaults['FEMALE_RATIO_ATTR_KEY']),
            dialog.do_not_use_string,
            message)

        message = (
            'Toggling the female ratio attribute combo to'
            ' "Don\'t use" did not disable dsbFemaleRatioDefault.')
        is_enabled = dialog.dsbFemaleRatioDefault.isEnabled()
        assert not is_enabled, message

        message = (
            'Toggling the female ratio attribute combo to'
            ' "Don\'t use" did not remove the keyword.')
        assert (dialog.get_value_for_key(defaults['FEMALE_RATIO']) is None), \
            message

        # set to PEREMPUAN attribute
        attribute = 'PEREMPUAN'
        index = female_ratio_box.findText(attribute)
        message = 'The attribute %s is not found in the layer' % attribute
        self.assertNotEqual(index, -1, message)

        female_ratio_box.setCurrentIndex(index)
        message = (
            'Toggling the female ratio attribute combo to %s'
            ' did not add it to the keywords list.') % attribute
        self.assertEqual(
            dialog.get_value_for_key(defaults['FEMALE_RATIO_ATTR_KEY']),
            attribute,
            message)

        message = (
            'Toggling the female ratio attribute combo to %s'
            ' did not disable dsbFemaleRatioDefault.') % attribute
        is_enabled = dialog.dsbFemaleRatioDefault.isEnabled()
        self.assertFalse(is_enabled, message)

        message = (
            'Toggling the female ratio attribute combo to %s'
            ' did not remove the keyword.') % attribute
        self.assertIsNone(
            dialog.get_value_for_key(defaults['FEMALE_RATIO']), message)