1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
import pytest
from pytestqt.qt_compat import qt_api
@pytest.mark.parametrize(
"expected_method",
[
"keyPress",
"keyClick",
"keyClicks",
"keyEvent",
"keyPress",
"keyRelease",
"keyToAscii",
"keySequence",
"mouseClick",
"mouseDClick",
"mouseMove",
"mousePress",
"mouseRelease",
],
)
def test_expected_qtest_proxies(qtbot, expected_method):
"""
This test originates from the implementation where QTest
API methods were exported on runtime.
"""
assert hasattr(qtbot, expected_method)
assert getattr(qtbot, expected_method).__name__ == expected_method
@pytest.mark.skipif(qt_api.is_pyside, reason="PyQt test only")
def test_keyToAscii_not_available_on_pyqt(testdir):
"""
Test that qtbot.keyToAscii() is not available on PyQt5 and
calling the method raises a NotImplementedError.
"""
testdir.makepyfile(
"""
import pytest
from pytestqt.qt_compat import qt_api
def test_foo(qtbot):
widget = qt_api.QtWidgets.QWidget()
qtbot.add_widget(widget)
with pytest.raises(NotImplementedError):
qtbot.keyToAscii(qt_api.QtCore.Qt.Key.Key_Escape)
"""
)
result = testdir.runpytest()
result.stdout.fnmatch_lines(["*= 1 passed in *"])
|