def test_build_form_minimum_needs(self):
        """Test that we can build a form by passing it a function and params.
        """
        function_id = 'Flood Evacuation Function Vector Hazard'
        function_list = get_plugins(function_id)
        assert len(function_list) == 1
        assert function_list[0].keys()[0] == function_id

        dialog = FunctionOptionsDialog(None)
        parameters = {
            'thresholds': [1.0],
            'postprocessors': {
                'Gender': {'on': True},
                'Age': {
                    'on': True,
                    'params': {
                        'youth_ratio': 0.263,
                        'elderly_ratio': 0.078,
                        'adult_ratio': 0.659}}}}

        dialog.build_form(parameters)

        assert dialog.tabWidget.count() == 2

        children = dialog.tabWidget.findChildren(QLineEdit)
        assert len(children) == 4
    def test_buildFormMinimumNeeds(self):
        """Test that we can build a form by passing it a function and params.
        """
        myFunctionId = 'Flood Evacuation Function Vector Hazard'
        myFunctionList = get_plugins(myFunctionId)
        assert len(myFunctionList) == 1
        assert myFunctionList[0].keys()[0] == myFunctionId

        myDialog = FunctionOptionsDialog(None)
        myParameters = {
            'thresholds': [1.0],
            'postprocessors': {
                'Gender': {'on': True},
                'Age': {
                    'on': True,
                    'params': {
                        'youth_ratio': 0.263,
                        'elder_ratio': 0.078,
                        'adult_ratio': 0.659}}}}

        myDialog.buildForm(myParameters)

        assert myDialog.tabWidget.count() == 2

        myChildren = myDialog.tabWidget.findChildren(QLineEdit)
        assert len(myChildren) == 4
    def test_build_form(self):
        """Test that we can build a form by passing it a function and params.
        """
        # noinspection PyUnresolvedReferences
        # pylint: disable=W0612
        from safe.engine.impact_functions_for_testing import \
            itb_fatality_model_configurable
        # pylint: enable=W0612
        function_id = 'I T B Fatality Function Configurable'
        function_list = get_plugins(function_id)
        assert len(function_list) == 1
        assert function_list[0].keys()[0] == function_id

        dialog = FunctionOptionsDialog(None)
        parameter = {
            'thresholds': [1.0],
            'postprocessors': {
                'Gender': {'on': True},
                'Age': {
                    'on': True,
                    'params': {
                        'youth_ratio': 0.263,
                        'elderly_ratio': 0.078,
                        'adult_ratio': 0.659}}}}

        dialog.build_form(parameter)

        assert dialog.tabWidget.count() == 2

        children = dialog.tabWidget.findChildren(QLineEdit)
        assert len(children) == 4
    def test_buildFormMinimumNeeds(self):
        """Test that we can build a form by passing it a function and params.
        """
        myFunctionId = 'Flood Evacuation Function Vector Hazard'
        myFunctionList = get_plugins(myFunctionId)
        assert len(myFunctionList) == 1
        assert myFunctionList[0].keys()[0] == myFunctionId

        myDialog = FunctionOptionsDialog(None)
        myParameters = {
            'thresholds': [1.0],
            'postprocessors': {
                'Gender': {
                    'on': True
                },
                'Age': {
                    'on': True,
                    'params': {
                        'youth_ratio': 0.263,
                        'elder_ratio': 0.078,
                        'adult_ratio': 0.659
                    }
                }
            }
        }

        myDialog.buildForm(myParameters)

        assert myDialog.tabWidget.count() == 2

        myChildren = myDialog.tabWidget.findChildren(QLineEdit)
        assert len(myChildren) == 4
    def test_buildForm(self):
        """Test that we can build a form by passing it a function and params.
        """
        # noinspection PyUnresolvedReferences
        # pylint: disable=W0612
        from safe.engine.impact_functions_for_testing import \
            itb_fatality_model_configurable
        # pylint: enable=W0612
        myFunctionId = 'I T B Fatality Function Configurable'
        myFunctionList = get_plugins(myFunctionId)
        assert len(myFunctionList) == 1
        assert myFunctionList[0].keys()[0] == myFunctionId

        myDialog = FunctionOptionsDialog(None)
        myParameters = {
            'thresholds': [1.0],
            'postprocessors': {
                'Gender': {'on': True},
                'Age': {
                    'on': True,
                    'params': {
                        'youth_ratio': 0.263,
                        'elder_ratio': 0.078,
                        'adult_ratio': 0.659}}}}

        myDialog.build_form(myParameters)

        assert myDialog.tabWidget.count() == 2

        myChildren = myDialog.tabWidget.findChildren(QLineEdit)
        assert len(myChildren) == 4
    def test_build_form(self):
        """Test that we can build a form by passing it a function and params.
        """
        # noinspection PyUnresolvedReferences
        # pylint: disable=W0612
        from safe.engine.impact_functions_for_testing import \
            itb_fatality_model_configurable
        # pylint: enable=W0612
        function_id = 'I T B Fatality Function Configurable'
        function_list = get_plugins(function_id)
        assert len(function_list) == 1
        assert function_list[0].keys()[0] == function_id

        dialog = FunctionOptionsDialog(None)

        # Define rice for minimum needs
        rice = ResourceParameter()
        rice.value = 2.8
        rice.frequency = 'weekly'
        rice.minimum_allowed_value = 1.4
        rice.maximum_allowed_value = 5.6
        rice.name = 'Rice'
        rice.unit.abbreviation = 'kg'
        rice.unit.name = 'kilogram'
        rice.unit.plural = 'kilograms'

        parameter = {
            'thresholds': [1.0],
            'postprocessors': {
                'Gender': {'on': True},
                'Age': {
                    'on': True,
                    'params': {
                        'youth_ratio': 0.263,
                        'elderly_ratio': 0.078,
                        'adult_ratio': 0.659
                    }
                }
            },
            'minimum needs': [rice]
        }

        dialog.build_form(parameter)

        message = 'There should be %s tabwidget but got %s' % (
            3, dialog.tabWidget.count())
        self.assertEqual(dialog.tabWidget.count(), 3, message)

        children = dialog.tabWidget.findChildren(QLineEdit)
        message = 'There should be %s QLineEdit but got %s' % (
            5, len(children))
        self.assertEqual(len(children), 5, message)
示例#7
0
    def test_dynamic_translation_function_title(self):
        """Test for dynamic translations for function title."""
        plugins_dict = get_plugins()
        plugin_name = 'Volcano Building Impact'
        message = '%s not found in %s' % (plugin_name, str(plugins_dict))
        self.assertIn(plugin_name, plugins_dict, message)
        function = plugins_dict[plugin_name]

        # English
        function_title = get_function_title(function)
        expected_title = 'Be affected'
        message = 'Expected %s but I got %s' % (expected_title, function_title)
        self.assertEqual(expected_title, function_title, message)

        # Indonesia
        os.environ['LANG'] = 'id'
        function_title = get_function_title(function)
        expected_title = 'Terkena dampak'
        message = ('expected %s but got %s, in lang = %s' % (
            expected_title, function_title, os.environ['LANG']))
        self.assertEqual(expected_title, function_title, message)
    def test_dynamic_translation_function_title(self):
        """Test for dynamic translations for function title
        """

        plugins_dict = get_plugins()
        plugin_name = "Volcano Building Impact"
        message = "%s not found in %s" % (plugin_name, str(plugins_dict))
        assert plugin_name in plugins_dict, message
        func = plugins_dict[plugin_name]

        # English
        func_title = get_function_title(func)
        expected_title = "Be affected"
        msg = "expected %s but got %s" % (expected_title, func_title)
        assert func_title == expected_title, msg

        # Indonesia
        os.environ["LANG"] = "id"
        func_title = get_function_title(func)
        expected_title = "Terkena dampak"
        msg = "expected %s but got %s, in lang = %s" % (expected_title, func_title, os.environ["LANG"])
        assert expected_title == func_title, msg
示例#9
0
    def test_dynamic_translation_function_title(self):
        """Test for dynamic translations for function title
        """

        plugins_dict = get_plugins()
        plugin_name = 'Volcano Building Impact'
        message = '%s not found in %s' % (plugin_name, str(plugins_dict))
        assert plugin_name in plugins_dict, message
        func = plugins_dict[plugin_name]

        # English
        func_title = get_function_title(func)
        expected_title = 'Be affected'
        msg = 'expected %s but got %s' % (expected_title, func_title)
        assert func_title == expected_title, msg

        # Indonesia
        os.environ['LANG'] = 'id'
        func_title = get_function_title(func)
        expected_title = 'Terkena dampak'
        msg = ('expected %s but got %s, in lang = %s'
               % (expected_title, func_title, os.environ['LANG']))
        assert expected_title == func_title, msg
示例#10
0
    def testDynamicTranslationFunctionTitle(self):
        """Test for dynamic translations for function title
        """

        plugins_dict = get_plugins()
        myPluginName = 'Volcano Building Impact'
        myMessage = '%s not found in %s' % (myPluginName, str(plugins_dict))
        assert myPluginName in plugins_dict, myMessage
        func = plugins_dict[myPluginName]

        # English
        func_title = get_function_title(func)
        expected_title = 'Be affected'
        msg = 'expected %s but got %s' % (expected_title, func_title)
        assert func_title == expected_title, msg

        # Indonesia
        os.environ['LANG'] = 'id'
        func_title = get_function_title(func)
        expected_title = 'Terkena dampak'
        msg = ('expected %s but got %s, in lang = %s' %
               (expected_title, func_title, os.environ['LANG']))
        assert expected_title == func_title, msg
示例#11
0
 def __init__(self):
     self.plugin_metadata = []
     for plugin in get_plugins().values():
         if hasattr(plugin, 'Metadata'):
             self.plugin_metadata.append(plugin.Metadata().get_metadata())