Exemple #1
0
    def test_state(self):
        """Check if the save/restore state methods work. See also
        https://github.com/AIFDR/inasafe/issues/58
        """
        DOCK.cboExposure.setCurrentIndex(DOCK.cboExposure.currentIndex() + 1)
        DOCK.save_state()
        expected_dict = get_ui_state(DOCK)
        #myState = DOCK.state
        # Now reset and restore and check that it gets the old state
        # Html is not considered in restore test since the ready
        # message overwrites it in dock implementation
        DOCK.cboExposure.setCurrentIndex(DOCK.cboExposure.currentIndex() + 1)
        DOCK.restore_state()
        result_dict = get_ui_state(DOCK)
        message = 'Got unexpected state: %s\nExpected: %s\n%s' % (
            result_dict, expected_dict, combos_to_string(DOCK))
        self.assertTrue(expected_dict == result_dict, message)

        # Corner case test when two layers can have the
        # same functions - when switching layers the selected function should
        # remain unchanged
        self.tearDown()
        file_list = [
            join(HAZDATA, 'Flood_Design_Depth_Jakarta_geographic.asc'),
            join(HAZDATA, 'Flood_Current_Depth_Jakarta_geographic.asc'),
            join(TESTDATA, 'Population_Jakarta_geographic.asc')]
        hazard_layer_count, exposure_layer_count = load_layers(
            file_list, data_directory=None)
        self.assertTrue(hazard_layer_count == 2)
        self.assertTrue(exposure_layer_count == 1)
        DOCK.cboFunction.setCurrentIndex(1)
        DOCK.cboHazard.setCurrentIndex(0)
        DOCK.cboExposure.setCurrentIndex(0)
        expected_function = str(DOCK.cboFunction.currentText())
        # Now move down one hazard in the combo then verify
        # the function remains unchanged
        DOCK.cboHazard.setCurrentIndex(1)
        current_function = str(DOCK.cboFunction.currentText())
        message = (
            'Expected selected impact function to remain unchanged when '
            'choosing a different hazard of the same category:'
            ' %s\nExpected: %s\n%s' % (
                expected_function, current_function, combos_to_string(DOCK)))

        self.assertTrue(expected_function == current_function, message)
        DOCK.cboHazard.setCurrentIndex(0)
        # Selected function should remain the same
        expected = 'Need evacuation'
        function = DOCK.cboFunction.currentText()
        message = 'Expected: %s, Got: %s' % (expected, function)
        self.assertTrue(function == expected, message)
Exemple #2
0
    def test_issue71(self):
        """Test issue #71 in github - cbo changes should update ok button."""
        # See https://github.com/AIFDR/inasafe/issues/71
        # Push OK with the left mouse button
        print 'Using QGIS: %s' % qgis_version()
        self.tearDown()
        button = DOCK.pbnRunStop
        # First part of scenario should have enabled run
        file_list = [
            join(HAZDATA, 'Flood_Current_Depth_Jakarta_geographic.asc'),
            join(TESTDATA, 'Population_Jakarta_geographic.asc')]
        hazard_layer_count, exposure_layer_count = load_layers(
            file_list, data_directory=None)

        message = (
            'Incorrect number of Hazard layers: expected 1 got %s'
            % hazard_layer_count)
        self.assertTrue(hazard_layer_count == 1, message)

        message = (
            'Incorrect number of Exposure layers: expected 1 got %s'
            % exposure_layer_count)
        self.assertTrue(exposure_layer_count == 1, message)

        message = 'Run button was not enabled'
        self.assertTrue(button.isEnabled(), message)

        # Second part of scenario - run disabled when adding invalid layer
        # and select it - run should be disabled
        file_list = ['issue71.tif']  # This layer has incorrect keywords
        clear_flag = False
        _, _ = load_layers(file_list, clear_flag)
        # set exposure to : Population Density Estimate (5kmx5km)
        # by moving one down
        DOCK.cboExposure.setCurrentIndex(DOCK.cboExposure.currentIndex() + 1)
        actual_dict = get_ui_state(DOCK)
        expected_dict = {
            'Run Button Enabled': False,
            'Impact Function Id': '',
            'Impact Function Title': '',
            'Hazard': 'A flood in Jakarta like in 2007',
            'Exposure': 'Population density (5kmx5km)'}
        message = ((
            'Run button was not disabled when exposure set to \n%s'
            '\nUI State: \n%s\nExpected State:\n%s\n%s') %
            (
                DOCK.cboExposure.currentText(),
                actual_dict,
                expected_dict,
                combos_to_string(DOCK)))

        self.assertTrue(expected_dict == actual_dict, message)

        # Now select again a valid layer and the run button
        # should be enabled
        DOCK.cboExposure.setCurrentIndex(DOCK.cboExposure.currentIndex() - 1)
        message = (
            'Run button was not enabled when exposure set to \n%s' %
            DOCK.cboExposure.currentText())
        self.assertTrue(button.isEnabled(), message)
Exemple #3
0
    def test_issue71(self):
        """Test issue #71 in github - cbo changes should update ok button."""
        # See https://github.com/AIFDR/inasafe/issues/71
        # Push OK with the left mouse button
        print 'Using QGIS: %s' % qgis_version()
        self.tearDown()
        myButton = DOCK.pbnRunStop
        # First part of scenario should have enabled run
        myFileList = [
            join(HAZDATA, 'Flood_Current_Depth_Jakarta_geographic.asc'),
            join(TESTDATA, 'Population_Jakarta_geographic.asc')
        ]
        myHazardLayerCount, myExposureLayerCount = load_layers(
            myFileList, data_directory=None)

        myMessage = ('Incorrect number of Hazard layers: expected 1 got %s' %
                     myHazardLayerCount)
        assert myHazardLayerCount == 1, myMessage

        myMessage = ('Incorrect number of Exposure layers: expected 1 got %s' %
                     myExposureLayerCount)
        assert myExposureLayerCount == 1, myMessage
        myMessage = 'Run button was not enabled'
        assert myButton.isEnabled(), myMessage

        # Second part of scenario - run disabled when adding invalid layer
        # and select it - run should be disabled
        myFileList = ['issue71.tif']  # This layer has incorrect keywords
        myClearFlag = False
        _, _ = load_layers(myFileList, myClearFlag)
        # set exposure to : Population Density Estimate (5kmx5km)
        # noinspection PyCallByClass,PyTypeChecker
        QTest.keyClick(DOCK.cboExposure, QtCore.Qt.Key_Down)
        # noinspection PyCallByClass,PyTypeChecker
        QTest.keyClick(DOCK.cboExposure, QtCore.Qt.Key_Enter)
        myDict = get_ui_state(DOCK)
        myExpectedDict = {
            'Run Button Enabled': False,
            'Impact Function Id': '',
            'Impact Function Title': '',
            'Hazard': 'A flood in Jakarta like in 2007',
            'Exposure': 'Population density (5kmx5km)'
        }
        myMessage = (('Run button was not disabled when exposure set to \n%s'
                      '\nUI State: \n%s\nExpected State:\n%s\n%s') %
                     (DOCK.cboExposure.currentText(), myDict, myExpectedDict,
                      combos_to_string(DOCK)))

        assert myExpectedDict == myDict, myMessage

        # Now select again a valid layer and the run button
        # should be enabled
        # noinspection PyCallByClass,PyTypeChecker
        QTest.keyClick(DOCK.cboExposure, QtCore.Qt.Key_Up)
        # noinspection PyCallByClass,PyTypeChecker
        QTest.keyClick(DOCK.cboExposure, QtCore.Qt.Key_Enter)
        myMessage = ('Run button was not enabled when exposure set to \n%s' %
                     DOCK.cboExposure.currentText())
        assert myButton.isEnabled(), myMessage
Exemple #4
0
    def test_issue71(self):
        """Test issue #71 in github - cbo changes should update ok button."""
        # See https://github.com/AIFDR/inasafe/issues/71
        # Push OK with the left mouse button
        print 'Using QGIS: %s' % qgis_version()
        self.tearDown()
        myButton = DOCK.pbnRunStop
        # First part of scenario should have enabled run
        myFileList = [join(HAZDATA,
                           'Flood_Current_Depth_Jakarta_geographic.asc'),
                      join(TESTDATA,
                           'Population_Jakarta_geographic.asc')]
        myHazardLayerCount, myExposureLayerCount = load_layers(
            myFileList, data_directory=None)

        myMessage = ('Incorrect number of Hazard layers: expected 1 got %s'
                     % myHazardLayerCount)
        assert myHazardLayerCount == 1, myMessage

        myMessage = ('Incorrect number of Exposure layers: expected 1 got %s'
                     % myExposureLayerCount)
        assert myExposureLayerCount == 1, myMessage
        myMessage = 'Run button was not enabled'
        assert myButton.isEnabled(), myMessage

        # Second part of scenario - run disabled when adding invalid layer
        # and select it - run should be disabled
        myFileList = ['issue71.tif']  # This layer has incorrect keywords
        myClearFlag = False
        _, _ = load_layers(myFileList, myClearFlag)
        # set exposure to : Population Density Estimate (5kmx5km)
        # noinspection PyCallByClass,PyTypeChecker
        QTest.keyClick(DOCK.cboExposure, QtCore.Qt.Key_Down)
        # noinspection PyCallByClass,PyTypeChecker
        QTest.keyClick(DOCK.cboExposure, QtCore.Qt.Key_Enter)
        myDict = get_ui_state(DOCK)
        myExpectedDict = {'Run Button Enabled': False,
                          'Impact Function Id': '',
                          'Impact Function Title': '',
                          'Hazard': 'A flood in Jakarta like in 2007',
                          'Exposure': 'Population density (5kmx5km)'}
        myMessage = (('Run button was not disabled when exposure set to \n%s'
                      '\nUI State: \n%s\nExpected State:\n%s\n%s') %
                     (DOCK.cboExposure.currentText(), myDict, myExpectedDict,
                      combos_to_string(DOCK)))

        assert myExpectedDict == myDict, myMessage

        # Now select again a valid layer and the run button
        # should be enabled
        # noinspection PyCallByClass,PyTypeChecker
        QTest.keyClick(DOCK.cboExposure, QtCore.Qt.Key_Up)
        # noinspection PyCallByClass,PyTypeChecker
        QTest.keyClick(DOCK.cboExposure, QtCore.Qt.Key_Enter)
        myMessage = ('Run button was not enabled when exposure set to \n%s' %
                     DOCK.cboExposure.currentText())
        assert myButton.isEnabled(), myMessage
Exemple #5
0
    def test_runEarthquakeFatalityFunction_Padang_full(self):
        """Padang 2009 fatalities estimated correctly (large extent)"""

        # Push OK with the left mouse button

        button = DOCK.pbnRunStop
        set_canvas_crs(GEOCRS, True)
        set_geo_extent([96, -5, 105, 2])  # This covers all of the 2009 shaking
        message = 'Run button was not enabled'
        self.assertTrue(button.isEnabled(), message)

        # Hazard layers
        index = DOCK.cboHazard.findText(PADANG2009_title)
        self.assertTrue(
            index != -1, 'Padang 2009 scenario hazard layer not found')
        DOCK.cboHazard.setCurrentIndex(index)

        # Exposure layers
        index = DOCK.cboExposure.findText('People')
        self.assertTrue(index != -1, 'People')
        DOCK.cboExposure.setCurrentIndex(index)

        # Choose impact function
        index = DOCK.cboFunction.findText('Earthquake Fatality Function')
        message = (
            'Earthquake Fatality Function not '
            'found: ' + combos_to_string(DOCK))
        self.assertTrue(index != -1, message)
        DOCK.cboFunction.setCurrentIndex(index)

        actual_dict = get_ui_state(DOCK)
        expected_dict = {
            'Hazard': PADANG2009_title,
            'Exposure': 'People',
            'Impact Function Id': 'Earthquake Fatality Function',
            'Impact Function Title': 'Earthquake Fatality Function',
            'Run Button Enabled': True}
        message = 'Got unexpected state: %s\nExpected: %s\n%s' % (
            actual_dict, expected_dict, combos_to_string(DOCK))
        self.assertTrue(actual_dict == expected_dict, message)

        DOCK.accept()

        result = DOCK.wvResults.page_to_text()

        # Check against expected output
        message = (
            'Unexpected result returned for Earthquake Fatality '
            'Function Expected: fatality count of '
            '500 , received: \n %s' % result)
        self.assertTrue(format_int(500) in result, message)

        message = (
            'Unexpected result returned for Earthquake Fatality '
            'Function Expected: total population count of '
            '31374747 , received: \n %s' % result)
        self.assertTrue(format_int(31374747) in result, message)
Exemple #6
0
    def test_runEarthquakeFatalityFunction_Padang_full(self):
        """Padang 2009 fatalities estimated correctly (large extent)"""

        # Push OK with the left mouse button

        myButton = DOCK.pbnRunStop
        set_canvas_crs(GEOCRS, True)
        set_geo_extent([96, -5, 105, 2])  # This covers all of the 2009 shaking
        myMessage = 'Run button was not enabled'
        assert myButton.isEnabled(), myMessage

        # Hazard layers
        myIndex = DOCK.cboHazard.findText(PADANG2009_title)
        assert myIndex != -1, 'Padang 2009 scenario hazard layer not found'
        DOCK.cboHazard.setCurrentIndex(myIndex)

        # Exposure layers
        myIndex = DOCK.cboExposure.findText('People')
        assert myIndex != -1, 'People'
        DOCK.cboExposure.setCurrentIndex(myIndex)

        # Choose impact function
        myIndex = DOCK.cboFunction.findText('Earthquake Fatality Function')
        myMessage = ('Earthquake Fatality Function not '
                     'found: ' + combos_to_string(DOCK))
        assert myIndex != -1, myMessage
        DOCK.cboFunction.setCurrentIndex(myIndex)

        myDict = get_ui_state(DOCK)
        myExpectedDict = {
            'Hazard': PADANG2009_title,
            'Exposure': 'People',
            'Impact Function Id': 'Earthquake Fatality Function',
            'Impact Function Title': 'Earthquake Fatality Function',
            'Run Button Enabled': True
        }
        myMessage = 'Got unexpected state: %s\nExpected: %s\n%s' % (
            myDict, myExpectedDict, combos_to_string(DOCK))
        assert myDict == myExpectedDict, myMessage

        DOCK.accept()

        myResult = DOCK.wvResults.page_to_text()

        # Check against expected output
        myMessage = ('Unexpected result returned for Earthquake Fatality '
                     'Function Expected: fatality count of '
                     '500 , received: \n %s' % myResult)
        assert format_int(500) in myResult, myMessage

        myMessage = ('Unexpected result returned for Earthquake Fatality '
                     'Function Expected: total population count of '
                     '31372262 , received: \n %s' % myResult)
        assert format_int(31372262) in myResult, myMessage
Exemple #7
0
    def test_state(self):
        """Check if the save/restore state methods work. See also
        https://github.com/AIFDR/inasafe/issues/58
        """
        # noinspection PyCallByClass,PyTypeChecker
        QTest.keyClick(DOCK.cboExposure, QtCore.Qt.Key_Up)
        # noinspection PyTypeChecker,PyCallByClass
        QTest.keyClick(DOCK.cboExposure, QtCore.Qt.Key_Enter)
        DOCK.save_state()
        myExpectedDict = get_ui_state(DOCK)
        #myState = DOCK.state
        # Now reset and restore and check that it gets the old state
        # Html is not considered in restore test since the ready
        # message overwrites it in dock implementation
        # noinspection PyTypeChecker,PyCallByClass
        QTest.keyClick(DOCK.cboExposure, QtCore.Qt.Key_Up)
        # noinspection PyTypeChecker,PyCallByClass
        QTest.keyClick(DOCK.cboExposure, QtCore.Qt.Key_Enter)
        DOCK.restore_state()
        myResultDict = get_ui_state(DOCK)
        myMessage = 'Got unexpected state: %s\nExpected: %s\n%s' % (
            myResultDict, myExpectedDict, combos_to_string(DOCK))
        assert myExpectedDict == myResultDict, myMessage

        # Corner case test when two layers can have the
        # same functions - when switching layers the selected function should
        # remain unchanged
        self.tearDown()
        myFileList = [join(HAZDATA,
                           'Flood_Design_Depth_Jakarta_geographic.asc'),
                      join(HAZDATA,
                           'Flood_Current_Depth_Jakarta_geographic.asc'),
                      join(TESTDATA,
                           'Population_Jakarta_geographic.asc')]
        myHazardLayerCount, myExposureLayerCount = load_layers(
            myFileList, data_directory=None)
        assert myHazardLayerCount == 2
        assert myExposureLayerCount == 1
        DOCK.cboHazard.setCurrentIndex(0)
        # noinspection PyTypeChecker,PyCallByClass
        QTest.keyClick(DOCK.cboFunction, QtCore.Qt.Key_Down)
        # noinspection PyTypeChecker,PyCallByClass
        QTest.keyClick(DOCK.cboFunction, QtCore.Qt.Key_Enter)
        myExpectedFunction = str(DOCK.cboFunction.currentText())
        # Now move down one hazard in the combo then verify
        # the function remains unchanged
        # noinspection PyTypeChecker,PyCallByClass
        QTest.keyClick(DOCK.cboHazard, QtCore.Qt.Key_Down)
        # noinspection PyTypeChecker,PyCallByClass
        QTest.keyClick(DOCK.cboHazard, QtCore.Qt.Key_Enter)
        myCurrentFunction = str(DOCK.cboFunction.currentText())
        myMessage = ('Expected selected impact function to remain unchanged '
                     'when choosing a different hazard of the same category:'
                     ' %s\nExpected: %s\n%s' % (myExpectedFunction,
                                                myCurrentFunction,
                                                combos_to_string(DOCK)))

        assert myExpectedFunction == myCurrentFunction, myMessage
        # noinspection PyTypeChecker,PyCallByClass
        QTest.keyClick(DOCK.cboHazard, QtCore.Qt.Key_Down)
        # noinspection PyTypeChecker,PyCallByClass
        QTest.keyClick(DOCK.cboHazard, QtCore.Qt.Key_Enter)
        # Selected function should remain the same
        myExpectation = 'Need evacuation'
        myFunction = DOCK.cboFunction.currentText()
        myMessage = 'Expected: %s, Got: %s' % (myExpectation, myFunction)
        assert myFunction == myExpectation, myMessage
Exemple #8
0
    def test_state(self):
        """Check if the save/restore state methods work. See also
        https://github.com/AIFDR/inasafe/issues/58
        """
        # noinspection PyCallByClass,PyTypeChecker
        QTest.keyClick(DOCK.cboExposure, QtCore.Qt.Key_Up)
        # noinspection PyTypeChecker,PyCallByClass
        QTest.keyClick(DOCK.cboExposure, QtCore.Qt.Key_Enter)
        DOCK.save_state()
        myExpectedDict = get_ui_state(DOCK)
        #myState = DOCK.state
        # Now reset and restore and check that it gets the old state
        # Html is not considered in restore test since the ready
        # message overwrites it in dock implementation
        # noinspection PyTypeChecker,PyCallByClass
        QTest.keyClick(DOCK.cboExposure, QtCore.Qt.Key_Up)
        # noinspection PyTypeChecker,PyCallByClass
        QTest.keyClick(DOCK.cboExposure, QtCore.Qt.Key_Enter)
        DOCK.restore_state()
        myResultDict = get_ui_state(DOCK)
        myMessage = 'Got unexpected state: %s\nExpected: %s\n%s' % (
            myResultDict, myExpectedDict, combos_to_string(DOCK))
        assert myExpectedDict == myResultDict, myMessage

        # Corner case test when two layers can have the
        # same functions - when switching layers the selected function should
        # remain unchanged
        self.tearDown()
        myFileList = [
            join(HAZDATA, 'Flood_Design_Depth_Jakarta_geographic.asc'),
            join(HAZDATA, 'Flood_Current_Depth_Jakarta_geographic.asc'),
            join(TESTDATA, 'Population_Jakarta_geographic.asc')
        ]
        myHazardLayerCount, myExposureLayerCount = load_layers(
            myFileList, data_directory=None)
        assert myHazardLayerCount == 2
        assert myExposureLayerCount == 1
        DOCK.cboHazard.setCurrentIndex(0)
        # noinspection PyTypeChecker,PyCallByClass
        QTest.keyClick(DOCK.cboFunction, QtCore.Qt.Key_Down)
        # noinspection PyTypeChecker,PyCallByClass
        QTest.keyClick(DOCK.cboFunction, QtCore.Qt.Key_Enter)
        myExpectedFunction = str(DOCK.cboFunction.currentText())
        # Now move down one hazard in the combo then verify
        # the function remains unchanged
        # noinspection PyTypeChecker,PyCallByClass
        QTest.keyClick(DOCK.cboHazard, QtCore.Qt.Key_Down)
        # noinspection PyTypeChecker,PyCallByClass
        QTest.keyClick(DOCK.cboHazard, QtCore.Qt.Key_Enter)
        myCurrentFunction = str(DOCK.cboFunction.currentText())
        myMessage = (
            'Expected selected impact function to remain unchanged '
            'when choosing a different hazard of the same category:'
            ' %s\nExpected: %s\n%s' %
            (myExpectedFunction, myCurrentFunction, combos_to_string(DOCK)))

        assert myExpectedFunction == myCurrentFunction, myMessage
        # noinspection PyTypeChecker,PyCallByClass
        QTest.keyClick(DOCK.cboHazard, QtCore.Qt.Key_Down)
        # noinspection PyTypeChecker,PyCallByClass
        QTest.keyClick(DOCK.cboHazard, QtCore.Qt.Key_Enter)
        # Selected function should remain the same
        myExpectation = 'Need evacuation'
        myFunction = DOCK.cboFunction.currentText()
        myMessage = 'Expected: %s, Got: %s' % (myExpectation, myFunction)
        assert myFunction == myExpectation, myMessage