예제 #1
0
    def click_through_model(self, model_ui, files_to_check):
        """Click through a standard modelui interface.

            model_ui - an instance of natcap.invest.iui.modelui.ModelUI
            files_to_check - a list of strings.  Each string must be a URI
                relative to the workspace.  All files at these URIs are required
                to exist.  An AssertionError will be thrown if a file does not
                exist.

        Returns nothing."""

        workspace_element = locate_workspace_element(model_ui)

        workspace_element.setValue(self.workspace)
        QTest.qWait(100)  # Wait for the test workspace to validate

        # Assert that the test workspace didn't get a validation error.
        self.assertEqual(workspace_element.has_error(), False)

        # Assert that there are no default data validation errors.
        validation_errors = model_ui.errors_exist()
        self.assertEqual(
            validation_errors, [], 'Validation errors '
            'exist for %s inputs. Errors: %s' %
            (len(validation_errors), validation_errors))

        # Click the 'Run' button and see what happens now.
        QTest.mouseClick(model_ui.runButton, Qt.MouseButton(1))

        # Now that the run button has been pressed, we need to check the state
        # of the operation dialog to see if it has finished completing.  This
        # check is done at half-secong intervals.
        while not model_ui.operationDialog.backButton.isEnabled():
            QTest.qWait(500)

        # Once the test has finished, click the back button on the dialog to
        # return toe the UI.
        QTest.mouseClick(model_ui.operationDialog.backButton,
                         Qt.MouseButton(1))

        missing_files = []
        for filepath in files_to_check:
            full_filepath = os.path.join(self.workspace, filepath)
            if not os.path.exists(full_filepath):
                missing_files.append(filepath)

        self.assertEqual(
            missing_files, [], 'Some expected files were not '
            'found: %s' % missing_files)
예제 #2
0
    def sendEvent(self, type_, arg1, arg2):
        type_ = type_.lower()

        if type_ in ('mousedown', 'mouseup', 'mousemove'):
            eventType = QMouseEvent.Type(QEvent.None)
            button = Qt.MouseButton(Qt.LeftButton)
            buttons = Qt.MouseButtons(Qt.LeftButton)

            if type_ == 'mousedown':
                eventType = QEvent.MouseButtonPress
            elif type_ == 'mouseup':
                eventType = QEvent.MouseButtonRelease
            elif type_ == 'mousemove':
                eventType = QEvent.MouseMove
                button = buttons = Qt.NoButton

            assert eventType != QEvent.None

            event = QMouseEvent(eventType, QPoint(arg1, arg2), button, buttons, Qt.NoModifier)
            QApplication.postEvent(self.m_webPage, event)
            QApplication.processEvents()

            return

        if type_ == 'click':
            self.sendEvent('mousedown', arg1, arg2)
            self.sendEvent('mouseup', arg1, arg2)