File: test_backends.py

package info (click to toggle)
magicgui 0.9.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 21,796 kB
  • sloc: python: 11,202; makefile: 11; sh: 9
file content (48 lines) | stat: -rw-r--r-- 1,349 bytes parent folder | download
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
#!/usr/bin/env python

"""Tests for `magicgui._qt` module."""


import pytest
from qtpy import API_NAME, QtCore
from qtpy import QtWidgets as QtW

from magicgui import event_loop, widgets


@pytest.mark.skipif("PyQt" in API_NAME, reason="Couldn't delete app on PyQt")
def test_event():
    """Test that the event loop makes a Qt app."""
    if QtW.QApplication.instance():
        if API_NAME == "PySide2":
            __import__("shiboken2").delete(QtW.QApplication.instance())
        elif API_NAME == "PySide6":
            __import__("shiboken6").delete(QtW.QApplication.instance())
        else:
            raise AssertionError(f"known API name: {API_NAME}")
    assert not QtW.QApplication.instance()
    with event_loop():
        app = QtW.QApplication.instance()
        assert app
        timer = QtCore.QTimer()
        timer.timeout.connect(lambda: app.exit())
        timer.start(100)


@pytest.mark.parametrize(
    "WidgetClass",
    [
        widgets.ComboBox,
        widgets.LineEdit,
        widgets.PushButton,
        widgets.DateTimeEdit,
        widgets.SpinBox,
        widgets.FloatSpinBox,
        widgets.Slider,
        widgets.FloatSlider,
        widgets.FileEdit,
    ],
)
def test_get_set_change(WidgetClass):
    """Test that we can retrieve getters, setters, and signals for most Widgets."""
    _ = WidgetClass()