Example #1
0
def qtbot(request, qapp, qtbot_params) -> pytest_qt_extras.QtBot:
    if sys.version_info < (3, 7):
        pytest.skip('GUI tests are not available for Python 3.6 or lower')
    _qtbot = pytest_qt_extras.QtBot(request, **qtbot_params)
    with capture_exceptions() as exceptions:
        yield _qtbot
    if exceptions:
        pytest.fail(format_captured_exceptions(exceptions))
    _qtbot.describe()
Example #2
0
def test_format_captured_exceptions():
    try:
        raise ValueError('errors were made')
    except ValueError:
        exceptions = [sys.exc_info()]

    obtained_text = format_captured_exceptions(exceptions)
    lines = obtained_text.splitlines()

    assert 'Qt exceptions in virtual methods:' in lines
    assert 'ValueError: errors were made' in lines
Example #3
0
def test_format_captured_exceptions():
    try:
        raise ValueError("errors were made")
    except ValueError:
        exceptions = [sys.exc_info()]

    obtained_text = format_captured_exceptions(exceptions)
    lines = obtained_text.splitlines()

    assert "Exceptions caught in Qt event loop:" in lines
    assert "ValueError: errors were made" in lines
Example #4
0
def test_format_captured_exceptions():
    try:
        raise ValueError('errors were made')
    except ValueError:
        exceptions = [sys.exc_info()]

    obtained_text = format_captured_exceptions(exceptions)
    lines = obtained_text.splitlines()

    assert 'Qt exceptions in virtual methods:' in lines
    assert 'ValueError: errors were made' in lines
Example #5
0
def test_format_captured_exceptions():
    try:
        raise ValueError("errors were made")
    except ValueError:
        exceptions = [sys.exc_info()]

    obtained_text = format_captured_exceptions(exceptions)
    lines = obtained_text.splitlines()

    assert "Exceptions caught in Qt event loop:" in lines
    assert "ValueError: errors were made" in lines
Example #6
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)
Example #7
0
def test_format_captured_exceptions_chained():
    try:
        try:
            raise ValueError("errors were made")
        except ValueError:
            raise RuntimeError("error handling value error")
    except RuntimeError:
        exceptions = [sys.exc_info()]

    obtained_text = format_captured_exceptions(exceptions)
    lines = obtained_text.splitlines()

    assert "Qt exceptions in virtual methods:" in lines
    assert "ValueError: errors were made" in lines
    assert "RuntimeError: error handling value error" in lines
def test_format_captured_exceptions_chained():
    try:
        try:
            raise ValueError("errors were made")
        except ValueError:
            raise RuntimeError("error handling value error")
    except RuntimeError:
        exceptions = [sys.exc_info()]

    obtained_text = format_captured_exceptions(exceptions)
    lines = obtained_text.splitlines()

    assert "Qt exceptions in virtual methods:" in lines
    assert "ValueError: errors were made" in lines
    assert "RuntimeError: error handling value error" in lines
Example #9
0
def qtbot(qapp, request):
    """
    Fixture used to create a QtBot instance for using during testing.

    Make sure to call addWidget for each top-level widget you create to ensure
    that they are properly closed after the test ends.
    """
    result = QtBot()
    no_capture = _is_exception_capture_disabled(request.node)
    if no_capture:
        yield result  # pragma: no cover
    else:
        with capture_exceptions() as exceptions:
            yield result
        if exceptions:
            pytest.fail(format_captured_exceptions(exceptions), pytrace=False)

    result._close()
Example #10
0
def qtbot_session(qapp, request):
    result = QtBot(qapp)
    with capture_exceptions() as exceptions:
        yield result
    if exceptions:
        pytest.fail(format_captured_exceptions(exceptions))