|
| 1 | +"""pytest configuration: stub out PySide6 when it is not installed. |
| 2 | +
|
| 3 | +test_input_action_server.py patches every PySide6 call it makes, so the |
| 4 | +tests run correctly with lightweight stubs. test_input_gui.py exercises |
| 5 | +real widget behaviour and requires genuine PySide6, so it is excluded from |
| 6 | +collection when only stubs are present. |
| 7 | +""" |
| 8 | +import sys |
| 9 | +import types |
| 10 | + |
| 11 | +try: |
| 12 | + import PySide6 # noqa: F401 |
| 13 | + collect_ignore = [] |
| 14 | +except ImportError: |
| 15 | + collect_ignore = ['test_input_gui.py'] |
| 16 | + |
| 17 | + # ------------------------------------------------------------------ # |
| 18 | + # Minimal PySide6 stubs sufficient for importing input_action_server # |
| 19 | + # and input_gui without a real Qt installation. # |
| 20 | + # ------------------------------------------------------------------ # |
| 21 | + |
| 22 | + class _Signal: |
| 23 | + |
| 24 | + def __init__(self, *args): |
| 25 | + pass |
| 26 | + |
| 27 | + def connect(self, *args, **kwargs): |
| 28 | + pass |
| 29 | + |
| 30 | + def emit(self, *args): |
| 31 | + pass |
| 32 | + |
| 33 | + def _Slot(*_args, **_kwargs): |
| 34 | + def decorator(func): |
| 35 | + return func |
| 36 | + return decorator |
| 37 | + |
| 38 | + class _QObject: |
| 39 | + |
| 40 | + def __init__(self, *args, **kwargs): |
| 41 | + pass |
| 42 | + |
| 43 | + def __getattr__(self, name): |
| 44 | + return lambda *a, **kw: None |
| 45 | + |
| 46 | + class _QThread(_QObject): |
| 47 | + pass |
| 48 | + |
| 49 | + class _QCoreApplication: |
| 50 | + |
| 51 | + @staticmethod |
| 52 | + def quit(): # noqa: A003 |
| 53 | + pass |
| 54 | + |
| 55 | + class _QApplication(_QObject): |
| 56 | + pass |
| 57 | + |
| 58 | + _qtcore = types.ModuleType('PySide6.QtCore') |
| 59 | + _qtcore.Signal = _Signal |
| 60 | + _qtcore.Slot = _Slot |
| 61 | + _qtcore.QThread = _QThread |
| 62 | + _qtcore.QCoreApplication = _QCoreApplication |
| 63 | + _qtcore.Qt = type('Qt', (), {'BlockingQueuedConnection': None})() |
| 64 | + _qtcore.QSize = type('QSize', (_QObject,), {}) |
| 65 | + |
| 66 | + _qtwidgets = types.ModuleType('PySide6.QtWidgets') |
| 67 | + _qtwidgets.QApplication = _QApplication |
| 68 | + for _cls_name in ('QComboBox', 'QLabel', 'QLineEdit', 'QMainWindow', |
| 69 | + 'QPushButton', 'QVBoxLayout', 'QWidget'): |
| 70 | + setattr(_qtwidgets, _cls_name, type(_cls_name, (_QObject,), {})) |
| 71 | + |
| 72 | + _pyside6 = types.ModuleType('PySide6') |
| 73 | + _pyside6.QtCore = _qtcore |
| 74 | + _pyside6.QtWidgets = _qtwidgets |
| 75 | + |
| 76 | + sys.modules['PySide6'] = _pyside6 |
| 77 | + sys.modules['PySide6.QtCore'] = _qtcore |
| 78 | + sys.modules['PySide6.QtWidgets'] = _qtwidgets |
0 commit comments