File: test_qtest_proxies.py

package info (click to toggle)
pytest-qt 4.2.0%2Brepack-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 624 kB
  • sloc: python: 4,098; makefile: 139
file content (52 lines) | stat: -rw-r--r-- 1,381 bytes parent folder | download | duplicates (2)
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 *"])