def test_buildForm(self):
        """Test that we can build a form by passing it a function and params.
        """
        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.buildForm(myParameters)

        assert myDialog.tabWidget.count() == 2

        myChildren = myDialog.tabWidget.findChildren(QLineEdit)
        assert len(myChildren) == 4
    def _get_impact_function(self,
                             qgis_hazard,
                             qgis_exposure,
                             plugin_name,
                             impact_parameters):
        """Helper to run impact function

        This method is based on
        safe.engine.test_engine.test_flood_population_evacuation
        """

        # Calculate impact using API
        # hazard = read_layer(hazard_filename)
        # exposure = read_layer(exposure_filename)

        hazard = Wrapper(qgis_hazard, 'hazard', 'Hazard')
        exposure = Wrapper(qgis_exposure, 'exposure', 'Exposure')

        plugin_list = get_plugins(plugin_name)
        assert len(plugin_list) == 1
        assert plugin_list[0].keys()[0] == plugin_name

        impact_function = plugin_list[0][plugin_name]
        # Set up impact_function extent
        hazard_extent = hazard.get_layer().extent()
        hazard_extent = [
            hazard_extent.xMinimum(),
            hazard_extent.yMinimum(),
            hazard_extent.xMaximum(),
            hazard_extent.yMaximum()
        ]
        exposure_extent = exposure.get_layer().extent()
        exposure_extent = [
            exposure_extent.xMinimum(),
            exposure_extent.yMinimum(),
            exposure_extent.xMaximum(),
            exposure_extent.yMaximum()
        ]
        extent = [
            max(hazard_extent[0], exposure_extent[0]),
            max(hazard_extent[1], exposure_extent[1]),
            min(hazard_extent[2], exposure_extent[2]),
            min(hazard_extent[3], exposure_extent[3])
        ]

        impact_function.parameters = impact_parameters

        # Call calculation engine
        impact_layer = calculate_impact(
            layers=[hazard, exposure],
            impact_fcn=impact_function,
            extent=extent,
            check_integrity=False)

        impact_filename = impact_layer.get_filename()
        I = read_layer(impact_filename)

        return I
    def _get_impact_function(self,
                             qgis_hazard,
                             qgis_exposure,
                             plugin_name,
                             impact_parameters):
        """Helper to run impact function

        This method is based on
        safe.engine.test_engine.test_flood_population_evacuation
        """

        # Calculate impact using API
        # hazard = read_layer(hazard_filename)
        # exposure = read_layer(exposure_filename)

        hazard = Wrapper(qgis_hazard, 'hazard', 'Hazard')
        exposure = Wrapper(qgis_exposure, 'exposure', 'Exposure')

        plugin_list = get_plugins(plugin_name)
        assert len(plugin_list) == 1
        assert plugin_list[0].keys()[0] == plugin_name

        impact_function = plugin_list[0][plugin_name]
        # Set up impact_function extent
        hazard_extent = hazard.get_layer().extent()
        hazard_extent = [
            hazard_extent.xMinimum(),
            hazard_extent.yMinimum(),
            hazard_extent.xMaximum(),
            hazard_extent.yMaximum()
        ]
        exposure_extent = exposure.get_layer().extent()
        exposure_extent = [
            exposure_extent.xMinimum(),
            exposure_extent.yMinimum(),
            exposure_extent.xMaximum(),
            exposure_extent.yMaximum()
        ]
        extent = [
            max(hazard_extent[0], exposure_extent[0]),
            max(hazard_extent[1], exposure_extent[1]),
            min(hazard_extent[2], exposure_extent[2]),
            min(hazard_extent[3], exposure_extent[3])
        ]

        impact_function.parameters = impact_parameters

        # Call calculation engine
        impact_layer = calculate_impact(
            layers=[hazard, exposure],
            impact_fcn=impact_function,
            extent=extent,
            check_integrity=False)

        impact_filename = impact_layer.get_filename()
        I = read_layer(impact_filename)

        return I
예제 #4
0
    def test_buildForm(self):
        """Test that we can build a form by passing it a function and params.
        """
        myFunctionId = "I T B Fatality Function Configurable"
        myFunctionList = get_plugins(myFunctionId)
        assert len(myFunctionList) == 1
        assert myFunctionList[0].keys()[0] == myFunctionId
        myFunction = myFunctionList[0]
        myDialog = FunctionOptionsDialog(None)
        myParameters = {"foo": "bar"}
        myDialog.buildForm(myFunction, myParameters)

        # myKids = myDialog.findChildren(QLineEdit)
        # for myKid in myKids:
        #    print myKid.objectName()
        myWidget = myDialog.findChild(QLineEdit, "fooLineEdit")
        assert myWidget is not None
        assert myWidget.text() == "bar"
    def test_buildForm(self):
        """Test that we can build a form by passing it a function and params.
        """
        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.buildForm(myParameters)

        assert myDialog.tabWidget.count() == 2

        myChildren = myDialog.tabWidget.findChildren(QLineEdit)
        assert len(myChildren) == 4