コード例 #1
0
    def test_on_rad_postprocessing_toggled(self):
        """Test hazard radio button toggle behaviour works"""
        layer = make_polygon_layer()
        defaults = breakdown_defaults()
        dialog = KeywordsDialog(PARENT, IFACE, layer=layer)
        button = dialog.radPostprocessing
        button.setChecked(False)
        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)
コード例 #2
0
ファイル: test_utilities.py プロジェクト: D2KG/FLOOgin
    def test_get_defaults(self):
        """Test defaults for post processing can be obtained properly."""
        # Warning this code is duplicated from test_defaults...TS
        expected = {
            'ADULT_RATIO_KEY': 'adult ratio default',
            'ADULT_RATIO_ATTR_KEY': 'adult ratio attribute',
            'ADULT_RATIO': 0.659,

            'FEMALE_RATIO_KEY': 'female ratio default',
            'FEMALE_RATIO_ATTR_KEY': 'female ratio attribute',
            'FEMALE_RATIO': 0.5,

            'ELDERLY_RATIO_ATTR_KEY': 'elderly ratio attribute',
            'ELDERLY_RATIO_KEY': 'elderly ratio default',
            'ELDERLY_RATIO': 0.078,

            'YOUTH_RATIO': 0.263,
            'YOUTH_RATIO_ATTR_KEY': 'youth ratio attribute',
            'YOUTH_RATIO_KEY': 'youth ratio default',

            'NO_DATA': u'No data',

            'AGGR_ATTR_KEY': 'aggregation attribute'}
        defaults = breakdown_defaults()
        self.assertDictEqual(defaults, expected)
コード例 #3
0
ファイル: test_defaults.py プロジェクト: D2KG/FLOOgin
    def test_breakdown_defaults(self):
        """Test we can get breakdown defaults.
        """
        expected = {
            'ADULT_RATIO_KEY': 'adult ratio default',
            'ADULT_RATIO_ATTR_KEY': 'adult ratio attribute',
            'ADULT_RATIO': 0.659,

            'FEMALE_RATIO_KEY': 'female ratio default',
            'FEMALE_RATIO_ATTR_KEY': 'female ratio attribute',
            'FEMALE_RATIO': 0.5,

            'ELDERLY_RATIO_ATTR_KEY': 'elderly ratio attribute',
            'ELDERLY_RATIO_KEY': 'elderly ratio default',
            'ELDERLY_RATIO': 0.078,

            'YOUTH_RATIO': 0.263,
            'YOUTH_RATIO_ATTR_KEY': 'youth ratio attribute',
            'YOUTH_RATIO_KEY': 'youth ratio default',

            'NO_DATA': u'No data',

            'AGGR_ATTR_KEY': 'aggregation attribute'}

        actual = breakdown_defaults()
        self.maxDiff = None
        self.assertDictEqual(expected, actual)
コード例 #4
0
    def test_on_rad_postprocessing_toggled(self):
        """Test hazard radio button toggle behaviour works"""
        layer = make_polygon_layer()
        defaults = breakdown_defaults()
        dialog = KeywordsDialog(PARENT, IFACE, layer=layer)
        button = dialog.radPostprocessing
        button.setChecked(False)
        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['FEM_RATIO_ATTR_KEY']),
            dialog.tr('Use default'), 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['FEM_RATIO_KEY'])),
            defaults['FEM_RATIO'], message)
コード例 #5
0
    def test_on_dsb_female_ratio_default_value_changed(self):
        """Test hazard radio button toggle behaviour works"""
        layer = make_polygon_layer()
        defaults = breakdown_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 TEST_REAL
        index = female_ratio_box.findText('TEST_REAL')
        message = 'TEST_REAL not found'
        assert (index != -1), message
        female_ratio_box.setCurrentIndex(index)

        message = (
            'Toggling the female ratio attribute combo to "TEST_REAL"'
            ' did not add it to the keywords list.')
        assert dialog.get_value_for_key(
            defaults['FEMALE_RATIO_ATTR_KEY']) == 'TEST_REAL', message

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

        message = (
            'Toggling the female ratio attribute combo to "TEST_REAL"'
            ' did not remove the keyword.')
        assert (dialog.get_value_for_key(defaults['FEMALE_RATIO']) is
                None), message
コード例 #6
0
    def test_on_dsb_female_ratio_default_value_changed(self):
        """Test hazard radio button toggle behaviour works"""
        layer = make_polygon_layer()
        defaults = breakdown_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.tr('Don\'t use'))
        message = (dialog.tr('Don\'t use') + ' 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['FEM_RATIO_ATTR_KEY']),
            dialog.tr('Don\'t use'), 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['FEM_RATIO']) is None), \
            message

        #set to TEST_REAL
        index = female_ratio_box.findText('TEST_REAL')
        message = 'TEST_REAL not found'
        assert (index != -1), message
        female_ratio_box.setCurrentIndex(index)

        message = ('Toggling the female ratio attribute combo to "TEST_REAL"'
                   ' did not add it to the keywords list.')
        assert dialog.get_value_for_key(
            defaults['FEM_RATIO_ATTR_KEY']) == 'TEST_REAL', message

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

        message = ('Toggling the female ratio attribute combo to "TEST_REAL"'
                   ' did not remove the keyword.')
        assert (dialog.get_value_for_key(defaults['FEM_RATIO']) is
                None), message
コード例 #7
0
ファイル: test_defaults.py プロジェクト: FlavioFalcao/inasafe
 def test_breakdown_defaults(self):
     """Test we can get breakdown defaults.
     """
     expected = {
         'FEM_RATIO_KEY': 'female ratio default',
         'YOUTH_RATIO': 0.263,
         'ELDER_RATIO': 0.078,
         'NO_DATA': u'No data',
         'FEM_RATIO': 0.5,
         'AGGR_ATTR_KEY': 'aggregation attribute',
         'FEM_RATIO_ATTR_KEY': 'female ratio attribute',
         'ADULT_RATIO': 0.659}
     actual = breakdown_defaults()
     self.assertEquals(expected, actual)
コード例 #8
0
 def test_breakdown_defaults(self):
     """Test we can get breakdown defaults.
     """
     expected = {
         'FEM_RATIO_KEY': 'female ratio default',
         'YOUTH_RATIO': 0.263,
         'ELDER_RATIO': 0.078,
         'NO_DATA': u'No data',
         'FEM_RATIO': 0.5,
         'AGGR_ATTR_KEY': 'aggregation attribute',
         'FEM_RATIO_ATTR_KEY': 'female ratio attribute',
         'ADULT_RATIO': 0.659
     }
     actual = breakdown_defaults()
     self.assertEquals(expected, actual)
コード例 #9
0
ファイル: test_utilities.py プロジェクト: borysiasty/inasafe
 def test_getDefaults(self):
     """Test defaults for post processing can be obtained properly."""
     myExpectedDefaults = {
         'FEM_RATIO_KEY': 'female ratio default',
         'YOUTH_RATIO': 0.263,
         'ELDER_RATIO': 0.078,
         'NO_DATA': 'No data',
         'FEM_RATIO': 0.5,
         'AGGR_ATTR_KEY': 'aggregation attribute',
         'FEM_RATIO_ATTR_KEY': 'female ratio attribute',
         'ADULT_RATIO': 0.659}
     myDefaults = breakdown_defaults()
     message = 'Defaults: got %s, expected %s' % (
         myDefaults, myExpectedDefaults)
     assert (myDefaults == myExpectedDefaults), message
コード例 #10
0
    if not result:
        message = 'Failed to load translation for %s' % locale_name
        raise TranslationLoadError(message)
    # noinspection PyTypeChecker,PyCallByClass
    QCoreApplication.installTranslator(translator)

# LOGGER.debug('%s %s' % (
#     translation_path,
#     os.path.exists(translation_path)))

# MONKEYPATCHING safe.defaults.get_defaults to use breakdown_defaults
# see safe_qgis.utilities.defaults for more details
import safe.defaults
from safe_qgis.utilities.defaults import breakdown_defaults

safe.defaults.get_defaults = lambda the_default=None: breakdown_defaults(
    the_default)

try:
    # When upgrading, using the plugin manager, you may get an error when
    # doing the following import, so we wrap it in a try except
    # block and then display a friendly message to restart QGIS
    from safe_qgis.utilities.custom_logging import setup_logger
    setup_logger()
except ImportError:
    # Note we use translate directly but the string may still not translate
    # at this early stage since the i18n setup routines have not been called
    # yet.
    import traceback

    trace = ''.join(traceback.format_tb(sys.exc_info()[2]))
    # Note that we do a late import here to avoid QPaintDevice before
コード例 #11
0
ファイル: __init__.py プロジェクト: D2KG/FLOOgin
    result = translator.load(translation_path)
    if not result:
        message = 'Failed to load translation for %s' % locale_name
        raise TranslationLoadError(message)
    # noinspection PyTypeChecker,PyCallByClass
    QCoreApplication.installTranslator(translator)

# LOGGER.debug('%s %s' % (
#     translation_path,
#     os.path.exists(translation_path)))

# MONKEYPATCHING safe.defaults.get_defaults to use breakdown_defaults
# see safe_qgis.utilities.defaults for more details
import safe.defaults
from safe_qgis.utilities.defaults import breakdown_defaults
safe.defaults.get_defaults = lambda the_default=None: breakdown_defaults(
    the_default)

try:
    # When upgrading, using the plugin manager, you may get an error when
    # doing the following import, so we wrap it in a try except
    # block and then display a friendly message to restart QGIS
    from safe_qgis.utilities.custom_logging import setup_logger
    setup_logger()
except ImportError:
    # Note we use translate directly but the string may still not translate
    # at this early stage since the i18n setup routines have not been called
    # yet.
    import traceback

    trace = ''.join(traceback.format_tb(sys.exc_info()[2]))
    # Note that we do a late import here to avoid QPaintDevice before
コード例 #12
0
ファイル: keywords_dialog.py プロジェクト: borysiasty/inasafe
    def __init__(self, parent, iface, dock=None, layer=None):
        """Constructor for the dialog.

        .. note:: In QtDesigner the advanced editor's predefined keywords
           list should be shown in english always, so when adding entries to
           cboKeyword, be sure to choose :safe_qgis:`Properties<<` and untick
           the :safe_qgis:`translatable` property.

        :param parent: Parent widget of this dialog.
        :type parent: QWidget

        :param iface: Quantum GIS QGisAppInterface instance.
        :type iface: QGisAppInterface

        :param dock: Dock widget instance that we can notify of changes to
            the keywords. Optional.
        :type dock: Dock
        """
        QtGui.QDialog.__init__(self, parent)
        self.setupUi(self)
        self.setWindowTitle(self.tr(
            'InaSAFE %s Keywords Editor' % get_version()))
        # Save reference to the QGIS interface and parent
        self.iface = iface
        self.parent = parent
        self.dock = dock

        if layer is None:
            self.layer = iface.activeLayer()
        else:
            self.layer = layer

        self.keyword_io = KeywordIO()

        # note the keys should remain untranslated as we need to write
        # english to the keywords file. The keys will be written as user data
        # in the combo entries.
        # .. seealso:: http://www.voidspace.org.uk/python/odict.html
        self.standard_exposure_list = OrderedDict(
            [('population', self.tr('population')),
             ('structure', self.tr('structure')),
             ('road', self.tr('road')),
             ('Not Set', self.tr('Not Set'))])
        self.standard_hazard_list = OrderedDict(
            [('earthquake [MMI]', self.tr('earthquake [MMI]')),
             ('tsunami [m]', self.tr('tsunami [m]')),
             ('tsunami [wet/dry]', self.tr('tsunami [wet/dry]')),
             ('tsunami [feet]', self.tr('tsunami [feet]')),
             ('flood [m]', self.tr('flood [m]')),
             ('flood [wet/dry]', self.tr('flood [wet/dry]')),
             ('flood [feet]', self.tr('flood [feet]')),
             ('tephra [kg2/m2]', self.tr('tephra [kg2/m2]')),
             ('volcano', self.tr('volcano')),
             ('Not Set', self.tr('Not Set'))])

        self.lstKeywords.itemClicked.connect(self.edit_key_value_pair)

        # Set up help dialog showing logic.
        help_button = self.buttonBox.button(QtGui.QDialogButtonBox.Help)
        help_button.clicked.connect(self.show_help)

        # set some initial ui state:
        self.defaults = breakdown_defaults()
        self.pbnAdvanced.setChecked(False)
        self.radPredefined.setChecked(True)
        self.dsbFemaleRatioDefault.blockSignals(True)
        self.dsbFemaleRatioDefault.setValue(self.defaults['FEM_RATIO'])
        self.dsbFemaleRatioDefault.blockSignals(False)

        if self.layer:
            self.load_state_from_keywords()

        # add a reload from keywords button
        reload_button = self.buttonBox.addButton(
            self.tr('Reload'), QtGui.QDialogButtonBox.ActionRole)
        reload_button.clicked.connect(self.load_state_from_keywords)
        self.grpAdvanced.setVisible(False)
        self.resize_dialog()
コード例 #13
0
    def __init__(self, parent, iface, dock=None, layer=None):
        """Constructor for the dialog.

        .. note:: In QtDesigner the advanced editor's predefined keywords
           list should be shown in english always, so when adding entries to
           cboKeyword, be sure to choose :safe_qgis:`Properties<<` and untick
           the :safe_qgis:`translatable` property.

        :param parent: Parent widget of this dialog.
        :type parent: QWidget

        :param iface: Quantum GIS QGisAppInterface instance.
        :type iface: QGisAppInterface

        :param dock: Dock widget instance that we can notify of changes to
            the keywords. Optional.
        :type dock: Dock
        """
        QtGui.QDialog.__init__(self, parent)
        self.setupUi(self)
        self.setWindowTitle(
            self.tr('InaSAFE %s Keywords Editor' % get_version()))
        # Save reference to the QGIS interface and parent
        self.iface = iface
        self.parent = parent
        self.dock = dock

        if layer is None:
            self.layer = iface.activeLayer()
        else:
            self.layer = layer

        self.keyword_io = KeywordIO()

        # note the keys should remain untranslated as we need to write
        # english to the keywords file. The keys will be written as user data
        # in the combo entries.
        # .. seealso:: http://www.voidspace.org.uk/python/odict.html
        self.standard_exposure_list = OrderedDict([
            ('population', self.tr('population')),
            ('structure', self.tr('structure')), ('road', self.tr('road')),
            ('Not Set', self.tr('Not Set'))
        ])
        self.standard_hazard_list = OrderedDict([
            ('earthquake [MMI]', self.tr('earthquake [MMI]')),
            ('tsunami [m]', self.tr('tsunami [m]')),
            ('tsunami [wet/dry]', self.tr('tsunami [wet/dry]')),
            ('tsunami [feet]', self.tr('tsunami [feet]')),
            ('flood [m]', self.tr('flood [m]')),
            ('flood [wet/dry]', self.tr('flood [wet/dry]')),
            ('flood [feet]', self.tr('flood [feet]')),
            ('tephra [kg2/m2]', self.tr('tephra [kg2/m2]')),
            ('volcano', self.tr('volcano')), ('Not Set', self.tr('Not Set'))
        ])

        self.lstKeywords.itemClicked.connect(self.edit_key_value_pair)

        # Set up help dialog showing logic.
        help_button = self.buttonBox.button(QtGui.QDialogButtonBox.Help)
        help_button.clicked.connect(self.show_help)

        # set some initial ui state:
        self.defaults = breakdown_defaults()
        self.pbnAdvanced.setChecked(False)
        self.radPredefined.setChecked(True)
        self.dsbFemaleRatioDefault.blockSignals(True)
        self.dsbFemaleRatioDefault.setValue(self.defaults['FEM_RATIO'])
        self.dsbFemaleRatioDefault.blockSignals(False)

        if self.layer:
            self.load_state_from_keywords()

        # add a reload from keywords button
        reload_button = self.buttonBox.addButton(
            self.tr('Reload'), QtGui.QDialogButtonBox.ActionRole)
        reload_button.clicked.connect(self.load_state_from_keywords)
        self.grpAdvanced.setVisible(False)
        self.resize_dialog()
コード例 #14
0
    def __init__(self, parent, iface, dock=None, layer=None):
        """Constructor for the dialog.

        .. note:: In QtDesigner the advanced editor's predefined keywords
           list should be shown in english always, so when adding entries to
           cboKeyword, be sure to choose :safe_qgis:`Properties<<` and untick
           the :safe_qgis:`translatable` property.

        :param parent: Parent widget of this dialog.
        :type parent: QWidget

        :param iface: Quantum GIS QGisAppInterface instance.
        :type iface: QGisAppInterface

        :param dock: Dock widget instance that we can notify of changes to
            the keywords. Optional.
        :type dock: Dock
        """
        QtGui.QDialog.__init__(self, parent)
        self.setupUi(self)
        self.setWindowTitle(self.tr(
            'InaSAFE %s Keywords Editor' % get_version()))
        # Save reference to the QGIS interface and parent
        self.iface = iface
        self.parent = parent
        self.dock = dock
        self.defaults = None

        # string constants
        self.global_default_string = metadata.global_default_attribute['name']
        self.do_not_use_string = metadata.do_not_use_attribute['name']
        self.global_default_data = metadata.global_default_attribute['id']
        self.do_not_use_data = metadata.do_not_use_attribute['id']

        if layer is None:
            self.layer = self.iface.activeLayer()
        else:
            self.layer = layer

        self.keyword_io = KeywordIO()

        # note the keys should remain untranslated as we need to write
        # english to the keywords file. The keys will be written as user data
        # in the combo entries.
        # .. seealso:: http://www.voidspace.org.uk/python/odict.html
        self.standard_exposure_list = OrderedDict(
            [('population', self.tr('population')),
             ('structure', self.tr('structure')),
             ('road', self.tr('road')),
             ('Not Set', self.tr('Not Set'))])
        self.standard_hazard_list = OrderedDict(
            [('earthquake [MMI]', self.tr('earthquake [MMI]')),
             ('tsunami [m]', self.tr('tsunami [m]')),
             ('tsunami [wet/dry]', self.tr('tsunami [wet/dry]')),
             ('tsunami [feet]', self.tr('tsunami [feet]')),
             ('flood [m]', self.tr('flood [m]')),
             ('flood [wet/dry]', self.tr('flood [wet/dry]')),
             ('flood [feet]', self.tr('flood [feet]')),
             ('tephra [kg2/m2]', self.tr('tephra [kg2/m2]')),
             ('volcano', self.tr('volcano')),
             ('Not Set', self.tr('Not Set'))])

        # noinspection PyUnresolvedReferences
        self.lstKeywords.itemClicked.connect(self.edit_key_value_pair)

        # Set up help dialog showing logic.
        help_button = self.buttonBox.button(QtGui.QDialogButtonBox.Help)
        help_button.clicked.connect(self.show_help)

        if self.layer is not None and is_polygon_layer(self.layer):
            # set some initial ui state:
            self.defaults = breakdown_defaults()
            self.radPredefined.setChecked(True)
            self.dsbFemaleRatioDefault.blockSignals(True)
            self.dsbFemaleRatioDefault.setValue(self.defaults['FEMALE_RATIO'])
            self.dsbFemaleRatioDefault.blockSignals(False)

            self.dsbYouthRatioDefault.blockSignals(True)
            self.dsbYouthRatioDefault.setValue(self.defaults['YOUTH_RATIO'])
            self.dsbYouthRatioDefault.blockSignals(False)

            self.dsbAdultRatioDefault.blockSignals(True)
            self.dsbAdultRatioDefault.setValue(self.defaults['ADULT_RATIO'])
            self.dsbAdultRatioDefault.blockSignals(False)

            self.dsbElderlyRatioDefault.blockSignals(True)
            self.dsbElderlyRatioDefault.setValue(
                self.defaults['ELDERLY_RATIO'])
            self.dsbElderlyRatioDefault.blockSignals(False)
        else:
            self.radPostprocessing.hide()
            self.tab_widget.removeTab(1)

        if self.layer:
            self.load_state_from_keywords()

        # add a reload from keywords button
        reload_button = self.buttonBox.addButton(
            self.tr('Reload'), QtGui.QDialogButtonBox.ActionRole)
        reload_button.clicked.connect(self.load_state_from_keywords)
        self.resize_dialog()
        self.tab_widget.setCurrentIndex(0)
        # TODO No we should not have test related stuff in prod code. TS
        self.test = False