예제 #1
0
파일: plugin.py 프로젝트: Samweli/inasafe
    def show_minimum_needs(self):
        """Show the minimum needs dialog."""
        # import here only so that it is AFTER i18n set up
        from safe.gui.tools.minimum_needs.needs_calculator_dialog import NeedsCalculatorDialog

        dialog = NeedsCalculatorDialog(self.iface.mainWindow())
        dialog.show()  # non modal
    def test_minimum_needs_calculator(self):
        """Test behaviour of the minimum needs function."""
        dialog = NeedsCalculatorDialog(PARENT)
        layer = load_test_vector_layer('other', 'minimum_needs.shp')
        QgsMapLayerRegistry.instance().addMapLayers([layer])

        # Set selected layer and displaced field
        dialog.layer.setLayer(layer)
        dialog.displaced.setField(u'displaced')

        # run minimum needs function
        dialog.accept()

        # get output layer
        layer = dialog.result_layer

        assert layer is not None
        field_names = [field.name() for field in layer.pendingFields()]
        for feature in layer.getFeatures():
            value = [attribute for attribute in feature.attributes()]

        actual_attributes = dict(zip(field_names, value))

        expected_attributes = {
            'displaced': 1000,
            'minimum_needs__rice': 2800,
            'minimum_needs__drinking_water': 17500,
            'minimum_needs__clean_water': 67000,
            'minimum_needs__family_kits': 200,
            'minimum_needs__toilets': 50}

        self.assertDictEqual(
            byteify(expected_attributes),
            byteify(actual_attributes))
예제 #3
0
    def test_minimum_needs_calculator(self):
        """Test behaviour of the minimum needs function."""
        dialog = NeedsCalculatorDialog(PARENT)
        layer = load_test_vector_layer('other', 'minimum_needs.shp')
        QgsProject.instance().addMapLayers([layer])

        # Set selected layer and displaced field
        dialog.layer.setLayer(layer)
        dialog.displaced.setField('displaced')

        # run minimum needs function
        dialog.accept()

        # get output layer
        layer = dialog.result_layer

        assert layer is not None
        field_names = [field.name() for field in layer.fields()]
        for feature in layer.getFeatures():
            value = [attribute for attribute in feature.attributes()]

        actual_attributes = dict(list(zip(field_names, value)))

        expected_attributes = {
            'displaced': 1000,
            'minimum_needs__rice': 2800,
            'minimum_needs__drinking_water': 17500,
            'minimum_needs__clean_water': 67000,
            'minimum_needs__family_kits': 200,
            'minimum_needs__toilets': 50
        }

        self.assertDictEqual(byteify(expected_attributes),
                             byteify(actual_attributes))
예제 #4
0
    def test_minimum_needs_calculator(self):
        """Test behaviour of the minimum needs function."""
        dialog = NeedsCalculatorDialog(PARENT)
        layer = QgsVectorLayer(shapefile_path,
                               os.path.basename(shapefile_path), 'ogr')
        QgsMapLayerRegistry.instance().addMapLayers([layer])

        # Set selected layer and displaced field
        dialog.layer.setLayer(layer)
        dialog.displaced.setField(u'displaced')

        # run minimum needs function
        dialog.accept()

        # get output layer
        layer = dialog.result_layer

        assert layer is not None
        field_names = [field.name() for field in layer.pendingFields()]
        for feature in layer.getFeatures():
            value = [attribute for attribute in feature.attributes()]

        actual_attributes = dict(zip(field_names, value))

        expected_attributes = {
            'displaced': 1000,
            'minimum_needs__rice': 2800,
            'minimum_needs__drinking_water': 17500,
            'minimum_needs__clean_water': 67000,
            'minimum_needs__family_kits': 200,
            'minimum_needs__toilets': 50
        }

        self.assertDictEqual(expected_attributes, actual_attributes)
예제 #5
0
    def show_minimum_needs(self):
        """Show the minimum needs dialog."""
        # import here only so that it is AFTER i18n set up
        from safe.gui.tools.minimum_needs.needs_calculator_dialog import (
            NeedsCalculatorDialog)

        dialog = NeedsCalculatorDialog(self.iface.mainWindow())
        dialog.exec_()
예제 #6
0
 def test_minimum_needs(self):
     """Test behaviour of the minimum needs function.
     """
     dialog = NeedsCalculatorDialog(PARENT)
     layer = safe_read_layer(shapefile_path)
     attribute = 'displaced'
     new_layer = dialog.minimum_needs(layer, attribute)
     assert new_layer is not None
     attributes = {
         'Drinking Water': 17500,
         'Family Kits': 200,
         'Rice': 2800,
         'Toilets': 50,
         'Clean Water': 67000}
     self.assertDictEqual(attributes, dict(new_layer.data[0]))
예제 #7
0
    def test_ok_button(self):
        """Test behaviour of Ok button."""
        # Test Ok button without any input in the combo box
        dialog = NeedsCalculatorDialog(PARENT)
        ok_button = dialog.button_box.button(QtWidgets.QDialogButtonBox.Ok)

        self.assertFalse(ok_button.isEnabled())

        # Close because this is a modal dialog
        dialog.reject()

        input_layer = load_test_vector_layer('other', 'minimum_needs.shp')

        QgsProject.instance().addMapLayers([input_layer])

        # Open the dialog again
        dialog = NeedsCalculatorDialog(PARENT)
        ok_button = dialog.button_box.button(QtWidgets.QDialogButtonBox.Ok)

        # Test Ok button with layer and displaced field
        # selected in the combo box
        dialog.layer.setLayer(input_layer)
        dialog.displaced.setField('displaced')

        self.assertTrue(ok_button.isEnabled())
    def test_ok_button(self):
        """Test behaviour of Ok button."""
        # Test Ok button without any input in the combo box
        dialog = NeedsCalculatorDialog(PARENT)
        ok_button = dialog.button_box.button(QtGui.QDialogButtonBox.Ok)

        self.assertFalse(ok_button.isEnabled())

        input_layer = load_test_vector_layer('other', 'minimum_needs.shp')

        QgsMapLayerRegistry.instance().addMapLayers([input_layer])

        # Test Ok button with layer and displaced field
        # selected in the combo box
        dialog.layer.setLayer(input_layer)
        dialog.displaced.setField(u'displaced')

        self.assertTrue(ok_button.isEnabled())
예제 #9
0
    def test_ok_button(self):
        """Test behaviour of Ok button."""
        # Test Ok button without any input in the combo box
        dialog = NeedsCalculatorDialog(PARENT)
        ok_button = dialog.button_box.button(QtGui.QDialogButtonBox.Ok)

        self.assertFalse(ok_button.isEnabled())

        input_layer = QgsVectorLayer(shapefile_path,
                                     os.path.basename(shapefile_path), 'ogr')
        QgsMapLayerRegistry.instance().addMapLayers([input_layer])

        # Test Ok button with layer and displaced field
        # selected in the combo box
        dialog.layer.setLayer(input_layer)
        dialog.displaced.setField(u'displaced')

        self.assertTrue(ok_button.isEnabled())