Пример #1
0
def qapp():
    """
    fixture that instantiates the QApplication instance that will be used by
    the tests.
    """
    app = QApplication.instance()
    if app is None:
        global _qapp_instance
        _qapp_instance = QApplication([])
        yield _qapp_instance
    else:
        yield app  # pragma: no cover
Пример #2
0
def _process_events():
    """Calls app.processEvents() while taking care of capturing exceptions
    or not based on the given item's configuration.
    """
    app = QApplication.instance()
    if app is not None:
        app.processEvents()
Пример #3
0
def _process_events():
    """Calls app.processEvents() while taking care of capturing exceptions
    or not based on the given item's configuration.
    """
    app = QApplication.instance()
    if app is not None:
        app.processEvents()
Пример #4
0
def pytest_runtest_teardown():
    """
    Hook called after each test tear down, to process any pending events and
    avoiding leaking events to the next test.
    """
    yield
    app = QApplication.instance()
    if app is not None:
        app.processEvents()
Пример #5
0
def test_catch_exceptions_in_virtual_methods(qtbot, raise_error):
    """
    Catch exceptions that happen inside Qt virtual methods and make the
    tests fail if any.
    """
    v = Receiver(raise_error)
    app = QApplication.instance()
    app.sendEvent(v, QtCore.QEvent(QtCore.QEvent.User))
    app.sendEvent(v, QtCore.QEvent(QtCore.QEvent.User))
    app.processEvents()
Пример #6
0
def qapp():
    """
    fixture that instantiates the QApplication instance that will be used by
    the tests.
    """
    app = QApplication.instance()
    if app is None:
        global _qapp_instance
        _qapp_instance = QApplication([])
        yield app
    else:
        yield app  # pragma: no cover
Пример #7
0
    def stopForInteraction(self):
        """
        Stops the current test flow, letting the user interact with any visible widget.

        This is mainly useful so that you can verify the current state of the program while writing
        tests.

        Closing the windows should resume the test run, with ``qtbot`` attempting to restore visibility
        of the widgets as they were before this call.

        .. note:: As a convenience, it is also aliased as `stop`.
        """
        widget_and_visibility = []
        for weak_widget in self._widgets:
            widget = weak_widget()
            if widget is not None:
                widget_and_visibility.append((widget, widget.isVisible()))

        QApplication.instance().exec_()

        for widget, visible in widget_and_visibility:
            widget.setVisible(visible)
Пример #8
0
def test_basics(qtbot):
    """
    Basic test that works more like a sanity check to ensure we are setting up a QApplication
    properly and are able to display a simple event_recorder.
    """
    assert QApplication.instance() is not None
    widget = QWidget()
    qtbot.addWidget(widget)
    widget.setWindowTitle('W1')
    widget.show()

    assert widget.isVisible()
    assert widget.windowTitle() == 'W1'
Пример #9
0
def qapp():
    """
    fixture that instantiates the QApplication instance that will be used by
    the tests.
    """
    from pytestqt.qt_compat import QApplication
    app = QApplication.instance()
    if app is None:
        global _qapp_instance
        _qapp_instance = QApplication([])
        yield _qapp_instance
    else:
        yield app  # pragma: no cover
Пример #10
0
    def stopForInteraction(self):
        """
        Stops the current test flow, letting the user interact with any visible widget.

        This is mainly useful so that you can verify the current state of the program while writing
        tests.

        Closing the windows should resume the test run, with ``qtbot`` attempting to restore visibility
        of the widgets as they were before this call.

        .. note:: As a convenience, it is also aliased as `stop`.
        """
        widget_and_visibility = []
        for weak_widget in _iter_widgets(self._request.node):
            widget = weak_widget()
            if widget is not None:
                widget_and_visibility.append((widget, widget.isVisible()))

        QApplication.instance().exec_()

        for widget, visible in widget_and_visibility:
            widget.setVisible(visible)
Пример #11
0
def _process_events(item):
    """Calls app.processEvents() while taking care of capturing exceptions
    or not based on the given item's configuration.
    """
    app = QApplication.instance()
    if app is not None:
        if _is_exception_capture_disabled(item):
            app.processEvents()
        else:
            with capture_exceptions() as exceptions:
                app.processEvents()
            if exceptions:
                pytest.fail("TEARDOWN ERROR: " + format_captured_exceptions(exceptions), pytrace=False)
Пример #12
0
def _process_events(item):
    """Calls app.processEvents() while taking care of capturing exceptions
    or not based on the given item's configuration.
    """
    app = QApplication.instance()
    if app is not None:
        if _exception_capture_disabled(item):
            app.processEvents()
        else:
            with capture_exceptions() as exceptions:
                app.processEvents()
            if exceptions:
                pytest.fail('TEARDOWN ERROR: ' +
                            format_captured_exceptions(exceptions),
                            pytrace=False)
Пример #13
0
    def wait(self):
        """
        Waits until either a connected signal is triggered or timeout is reached.

        :raise ValueError: if no signals are connected and timeout is None; in
            this case it would wait forever.
        """
        try:
            if self.signal_triggered:
                return
            if self.timeout is None and not self._signals:
                raise ValueError("No signals or timeout specified.")
            timer = QtCore.QElapsedTimer()
            if self.timeout:
                timer.start()
            while not self.signal_triggered:
                QApplication.instance().processEvents()
                if self.timeout and timer.hasExpired(self.timeout):
                    break
            if not self.signal_triggered and self.raising:
                raise SignalTimeoutError("Didn't get signal after %sms." %
                                         self.timeout)
        finally:
            self._cleanup()
Пример #14
0
    def wait(self):
        """
        Waits until either a connected signal is triggered or timeout is reached.

        :raise ValueError: if no signals are connected and timeout is None; in
            this case it would wait forever.
        """
        try:
            if self.signal_triggered:
                return
            if self.timeout is None and not self._signals:
                raise ValueError("No signals or timeout specified.")
            timer = QtCore.QElapsedTimer()
            if self.timeout:
                timer.start()
            while not self.signal_triggered:
                QApplication.instance().processEvents()
                if self.timeout and timer.hasExpired(self.timeout):
                    break
            if not self.signal_triggered and self.raising:
                raise SignalTimeoutError("Didn't get signal after %sms." %
                                         self.timeout)
        finally:
            self._cleanup()
Пример #15
0
def qapp():
    """
    fixture that instantiates the QApplication instance that will be used by
    the tests.
    """
    app = QApplication.instance()
    if app is None:
        app = QApplication([])
        yield app
        app.exit()
        app.deleteLater()
    else:
        yield app  # pragma: no cover