def test_widget_kept_as_weakref(qtbot): """ Test if the widget is kept as a weak reference in QtBot """ widget = qt_api.QWidget() qtbot.add_widget(widget) widget = weakref.ref(widget) assert widget() is None
def test_stop_for_interaction(qtbot, timer): """ Test qtbot.stopForInteraction() """ widget = qt_api.QWidget() qtbot.addWidget(widget) qtbot.waitForWindowShown(widget) timer.single_shot_callback(widget.close, 0) qtbot.stopForInteraction()
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 qt_api.QApplication.instance() is not None widget = qt_api.QWidget() qtbot.addWidget(widget) widget.setWindowTitle("W1") widget.show() assert widget.isVisible() assert widget.windowTitle() == "W1"
def test_basics(qtbot): ''' Basic test that works more like a sanity check to ensure we are setting up a QApplication properly ''' assert qt_api.QApplication.instance() is not None widget = qt_api.QWidget() qtbot.addWidget(widget) widget.setWindowTitle("W1") widget.show() assert widget.isVisible() assert widget.windowTitle() == "W1"
def test_wait_window_propagates_other_exception(method_name, qtbot): """ Exceptions raised inside the with-statement of wait-widget methods should propagate properly. """ if qt_api.pytest_qt_api != "pyqt5": pytest.skip("Available in PyQt5 only") method = getattr(qtbot, method_name) widget = qt_api.QWidget() qtbot.add_widget(widget) with pytest.raises(ValueError) as exc_info: with method(widget, timeout=100): widget.show() raise ValueError("some other error") assert str(exc_info.value) == "some other error"
def test_wait_window(show, method_name, qtbot): """ Using one of the wait-widget methods should not raise anything if the widget is properly displayed, otherwise should raise a TimeoutError. """ method = getattr(qtbot, method_name) if qt_api.pytest_qt_api != "pyqt5": with pytest.raises(RuntimeError) as exc_info: with method(None, None): pass assert str(exc_info.value) == "Available in PyQt5 only" else: widget = qt_api.QWidget() qtbot.add_widget(widget) if show: with method(widget, timeout=1000): widget.show() else: with pytest.raises(qtbot.TimeoutError): with method(widget, timeout=100): pass