Testing

UI test framework, see the module overview below for usage and for why some helpers are not built on QTest.

UI test framework for Qt widgets: from zoo.libs.pyqt import testing. Python 3.7 compatible.

Runs the same test in plain Python (offscreen), in mayapy and in interactive Maya, on PySide2 5.15 and PySide6.

Usage

from zoo.libs.pyqt import testing
from zoo.libs.pyqt.testing import QtTestCase
from zoovendor.Qt import QtWidgets


class TestButton(QtTestCase):

    def test_clickEmitsClicked(self):
        button = self.track(QtWidgets.QPushButton("ok"))   # closed and deleted after the test
        clicks = testing.collectSignal(button.clicked)      # list of emitted args
        testing.showAndWait(button)                         # show and wait until exposed
        testing.click(button)
        self.assertEqual(len(clicks), 1)

    @testing.requiresHost                                   # skipped without maya.cmds
    def test_needsMaya(self):
        ...

Rules: create every top level widget through self.track(); wait on conditions with testing.waitFor instead of fixed sleeps; assert visibility, relative geometry, signals and model state, never pixel exact output (offscreen fonts and DPI differ). QtTestCase creates one shared offscreen QApplication, never a second. Set ZOO_NO_QTESTS=1 to skip all Qt tests. Classes carry zooQtTest = True so runners can filter them.

testing.stubPreferences() runs on import: a few widgets read the Zoo preference manager at import, which is None until Zoo starts. The stub is only installed when it is still None and the session is not a real GUI (interactive Maya), so a live Zoo session is never touched; removeStubPreferences() undoes it and never removes a real manager.

Why some helpers do not use QTest

QTest is used where it behaves the same on every binding: click, keyClick, keyClicks and showAndWait (qWaitForWindowExposed). These are not built on it:

  • doubleClick always sends press, release, double click and release events. QTest.mouseDClick sends a different sequence on Qt5 and Qt6 and widgets which count presses see the difference.

  • contextMenu, hover, leave and wheel send the events directly, the offscreen platform does not turn a right click into a context menu event and QTest has no wheel helper.

  • runWithPopup and runWithWindow run a trigger which blocks (QMenu.exec_, QDialog.exec_, a Zoo MessageBox waiting in a loop of processEvents): a timer finds the popup, lets the test look at it or press its buttons, then closes it so the trigger returns.

  • waitFor polls with processEvents. QTest.qWaitFor does not exist in PySide2 5.15 (Maya 2022 to 2024).

  • drag sends QMouseEvent objects directly. QTest.mouseMove does not carry the held button reliably, so a drag handler never sees a press-move-release with the button down, especially on the offscreen platform.

  • collectSignal records into a plain list. QSignalSpy is not reliable across PySide2 and PySide6.

  • settle runs the event loop for a fixed time, for delayed refreshes only. QTest.qWait blocks differently.

  • Model checks use our own contract helpers (assertModelContract, recordModelSignals, in testing.models): QAbstractItemModelTester is not in PySide2 5.15 nor in Maya 2027. qtModelTester attaches it where it exists.

When QtTest is missing

Maya 2027 ships PySide6 6.8.3 without the QtTest module (Qt6Test.dll is in bin but there is no binding for it), so zoovendor.Qt cannot expose QtTest however its member list is edited, and importing it would stop every Qt test from loading. helpers therefore treats QtTest as optional. Without it:

  • click and doubleClick send QMouseEvent press, release (and double click) events to the widget, at the widget center when no position is given.

  • keyClick and keyClicks send QKeyEvent press and release events straight to the widget, as QTest does. They carry the character as text, so line edits and text edits receive typed text; shortcuts and focus handling are not emulated.

  • showAndWait shows the widget and polls until its window handle reports isExposed().

The fallbacks cover what the QTest helpers cover for widget tests, so tests are written once and run on every Maya version. tests/test_qttesting.py runs the helper tests with QtTest forced absent, so the fallbacks are exercised on every version, not only on 2027.

Everything is imported through zoovendor.Qt so tests never name a binding.

class QtTestCase(methodName='runTest')

Base for tests which need widgets. Runs standalone (offscreen) and in mayapy or Maya.

Skips when ZOO_NO_QTESTS=1. Pass every top level widget to track() so it is closed after the test, or a window every test of the class shares to trackClass() so it is closed after the class.

Qt objects must die while the QApplication is alive. A Python owned QObject in a reference cycle (a model and its data sources, a data source and its children) is only freed by the cycle collector, and when that first runs at interpreter shutdown the QApplication is already gone: interactive Maya then crashes on exit with an access violation and no crash log. So tearDown drops the Qt objects a test stored on itself (the test result keeps test instances alive) and tearDownClass collects the cycles and runs the pending deleteLater() calls.

Zoo windows are parented to the host’s main window and closing a frameless window only hides its container, so every Zoo top level window the class opened (and didn’t track) is deleted in tearDownClass too. Dozens of hidden windows left under Maya’s main window crash Maya when it quits. Set the Qt property zooTestKeep to True on a window which must outlive the class (the shared demo window).

zoo.libs.pyqt.utils.currentScreenGeometry() returns fixtures.TEST_SCREEN_GEOMETRY during the class, so code which keeps windows inside the screen behaves the same on every machine, Qt binding and host.

KEEP_PROPERTY = 'zooTestKeep'

Qt property which keeps a top level window alive after the class, see the class docstring

patchFrameIcons()

Patch the collapsable frame icons for this test, the engine icons aren’t needed

classmethod setUpClass()

Skips the class when ZOO_NO_QTESTS=1, otherwise gets the shared QApplication as cls.app

Raises:

unittest.SkipTest – if Qt tests are disabled or the running application is not a QApplication

tearDown()

Closes and deletes the tracked widgets, then runs the event loop once

classmethod tearDownClass()

Deletes the Zoo windows the class left open and frees the Qt objects left in reference cycles, while the QApplication is alive, see the class docstring

track(widget)

Register a widget to be closed and deleted in tearDown

Returns:

the widget

classmethod trackClass(widget)

Register a widget shared by every test of the class, usually created in setUpClass. It stays open between the tests, like a window a user keeps open, and is closed and deleted in tearDownClass. Reset the state a test changes in setUp so the tests don’t depend on their order.

Returns:

the widget

zooQtTest = True

marks the class as a Qt test for runners which filter

requiresHost(obj)

Skip unless maya.cmds can be imported

requiresGui(obj)

Skip unless running in a real GUI session (interactive Maya)

stubPreferences()

Make zoo.preferences.core.preference usable when Zoo has not started.

A few widgets (buttons, groupedtreewidget) read the preference manager at import, and it is None until Zoo starts. A stub is only installed when ALL of these hold, so a live session is never touched:

  • the preference manager is still None (Zoo has not set it up)

  • this is not a real GUI session (interactive Maya, see environment.isGui())

Temporary: goes away when widgets stop reading preferences at import. Undo with removeStubPreferences().

Returns:

True if a stub was installed

Return type:

bool

removeStubPreferences()

Remove the stub made by stubPreferences(), only if it is still the one installed (never a real manager)

Returns:

True if a stub was removed

Return type:

bool

stubEngine()

Make zoo.core.engine.currentEngine() usable when Zoo has not started, so iconlib and dialogs work.

The icon library asks the engine whether the host is headless. A stub (a non headless host) is installed only when there is no engine and this is not a real GUI session. Undo with removeStubEngine().

Returns:

True if a stub was installed

Return type:

bool

removeStubEngine()

Remove the engine made by stubEngine(), only if it is still the current one

Returns:

True if a stub was removed

Return type:

bool

stubHeadlessHost()

Make a headless host report that it is not, for the test process only.

mayapy is a headless host: iconlib.icon() returns None there, so every Zoo widget which sets an icon (the title bar of a ZooWindow, the buttons) fails to build. The widgets are created on an offscreen QApplication in the tests, so the icons are needed. Not done in a real GUI session, where the host is not headless anyway. Undo with removeStubHeadlessHost().

Returns:

True if the host was patched

Return type:

bool

removeStubHeadlessHost()

Undo stubHeadlessHost()

Returns:

True if the patch was removed

Return type:

bool

noFrameIcons()

The collapsable frame icons come from the icon engine, which tests don’t need

fixedScreenGeometry(geometry=(0, 0, 1920, 1080))

Context manager version of fixedScreenGeometryPatcher()

fixedScreenGeometryPatcher(geometry=(0, 0, 1920, 1080))

The patcher which makes zoo.libs.pyqt.utils.currentScreenGeometry() return the same screen everywhere.

Positions are contained in the screen, so tests which place windows would depend on the size of the offscreen screen of the Qt binding or Maya version they run on. Only the tests are affected, start() and stop() it.

Parameters:

geometry (tuple[int, int, int, int]) – left, top, width and height of the screen.

Return type:

mock._patch

settle(ms=80)

Run the event loop for ms milliseconds so delayed refreshes run, always at least once so settle(0) runs the pending events

waitFor(predicate, timeout=2000)

Process events until predicate() is true.

Polls instead of using QTest.qWaitFor, which PySide2 5.15 does not have.

Parameters:
  • predicate – callable returning bool

  • timeout – max wait in milliseconds

Returns:

True if the predicate became true

Return type:

bool

showAndWait(widget)

Show the widget and wait until it is exposed

click(widget, button=MockExt.QtCore.Qt.LeftButton, pos=None, modifier=MockExt.QtCore.Qt.NoModifier)

QTest mouse click on the widget

Parameters:
  • widget (QtWidgets.QWidget) – The widget to click

  • button – The mouse button

  • pos (QtCore.QPoint or None) – Position in widget coordinates, None for the center

  • modifier – Keyboard modifier held during the click

doubleClick(widget, button=MockExt.QtCore.Qt.LeftButton, pos=None)

QTest mouse double click on the widget

Parameters:
  • widget (QtWidgets.QWidget) – The widget to double click

  • button – The mouse button

  • pos (QtCore.QPoint or None) – Position in widget coordinates, None for the center

keyClick(widget, key, modifier=MockExt.QtCore.Qt.NoModifier)

QTest key press and release on the widget

Parameters:
  • widget (QtWidgets.QWidget) – The widget which gets the key

  • key – A QtCore.Qt.Key

  • modifier – Keyboard modifier held during the key

keyClicks(widget, text)

QTest types the text into the widget, one key click per character

Parameters:
  • widget (QtWidgets.QWidget) – The widget which gets the keys

  • text (str) – The text to type

drag(widget, start, end, button=MockExt.QtCore.Qt.LeftButton, steps=5)

Press at start, move to end in steps with the button held, release. Positions are QPoints in widget coordinates. Sends the events directly: QTest.mouseMove does not report the held button reliably.

resizeAndSettle(widget, width, height, ms=40)

Resize the widget then run the event loop so layouts and delayed refreshes follow

Parameters:
  • widget (QtWidgets.QWidget) – The widget to resize

  • width – New width in pixels

  • height – New height in pixels

  • ms – How long to run the event loop, in milliseconds

collectSignal(signal)

A list which records the args of every emission. A plain list on purpose: QSignalSpy is not reliable across PySide2 and PySide6

Returns:

list of tuples of emitted args

Return type:

list

grabImage(widget)

A QImage of the widget, for smoke checks only (no pixel exact asserts: fonts and DPI differ)

runWithPopup(trigger, inspect=None, timeout=2000)

Call trigger which opens a blocking popup or modal (QMenu.exec_, QDialog.exec_), look at the popup then close it, so the trigger returns. A test would hang forever on a blocking popup otherwise.

A timer polls for QApplication.activePopupWidget() then activeModalWidget(). When one is found inspect(widget) runs (if given) and the widget is closed. When none appears within timeout ms the trigger is left alone (it cannot be interrupted if it does block), so only use this for triggers which open a popup.

Parameters:
  • trigger – callable which opens the popup, eg lambda: testing.click(button)

  • inspect – callable receiving the popup, its return value is returned by this function

  • timeout – max wait for the popup in milliseconds

Returns:

the result of inspect, the popup if inspect is None, None if no popup appeared

runWithWindow(trigger, windowType, inspect=None, timeout=2000)

Like runWithPopup() for blocking windows which are not Qt popups or modals, eg a window which waits in a loop of processEvents until it is closed (MessageBox.showQuestion).

A timer polls the top level widgets (and their children, as frameless windows live in a container) for a visible instance of windowType. When found inspect(window) runs (it may click the window’s buttons, which closes it) and the window is closed if it is still open.

Parameters:
  • trigger – callable which shows the window and blocks until it is closed

  • windowType – class (or tuple of classes) of the window to wait for

  • inspect – callable receiving the window, its return value is returned by this function

  • timeout – max wait for the window in milliseconds

Returns:

the result of inspect, the window if inspect is None, None if no window appeared

contextMenu(widget, pos=None)

Send a context menu event (what a right click does on a real platform: the offscreen platform does not turn a right button click into one), so customContextMenuRequested and contextMenuEvent run

Parameters:
  • widget (QtWidgets.QWidget) – The widget to ask

  • pos (QtCore.QPoint or None) – Position in widget coordinates, None for the center

hover(widget, pos=None)

Move the mouse onto the widget: sends an enter event then a mouse move without buttons

Parameters:
  • widget (QtWidgets.QWidget) – The widget to hover

  • pos (QtCore.QPoint or None) – Position in widget coordinates, None for the center

leave(widget)

Move the mouse off the widget: sends a leave event

wheel(widget, delta=120, pos=None, modifier=MockExt.QtCore.Qt.NoModifier)

Scroll the mouse wheel over the widget. 120 is one notch up, -120 one notch down.

Parameters:
  • widget (QtWidgets.QWidget) – The widget under the cursor

  • delta (int) – Vertical angle delta in 1/8 degrees

  • pos (QtCore.QPoint or None) – Position in widget coordinates, None for the center

  • modifier – Keyboard modifier held, eg Ctrl

assertModelContract(model, maxDepth=4, maxRows=100)

Raise AssertionError listing every problem modelContractProblems() finds

Parameters:

model (QtCore.QAbstractItemModel) – the model to check

modelContractProblems(model, maxDepth=4, maxRows=100)

Walk the model and return every broken item model rule.

Checked for the root and every index down to maxDepth levels (only the first maxRows rows of a parent): counts are not negative, out of range indexes are invalid, index() is stable and points back at its row, column and model, parent() of a child is the index it was made from, sibling() agrees with index(), hasChildren() agrees with rowCount(), and data(), flags() and headerData() do not raise and return types a view accepts. Parents which can fetch more rows are not walked, fetching would change the model.

Parameters:
  • model (QtCore.QAbstractItemModel) – the model to check

  • maxDepth – how many levels of children are walked

  • maxRows – how many rows of each parent are walked

Returns:

one message per problem, empty when the model keeps the contract

Return type:

list[str]

recordModelSignals(model)

Record the change signals of model inside the with block.

with testing.recordModelSignals(model) as recorder:
    model.removeRows(0, 1)
recorder.assertValid()
Parameters:

model (QtCore.QAbstractItemModel) – the model to watch

Return type:

ModelSignalRecorder

class ModelSignalRecorder(model)

Records the change signals of a model and checks that they keep the contract.

Made by recordModelSignals(). Every begin signal (rowsAboutToBeInserted…) must be followed by its end signal with the same arguments before another change starts, and inserts and removes must change the row or column count by what the signals announced.

assertValid()

Raise AssertionError listing every problem

connect()
disconnect()
names()

The names of the emitted signals in order

Return type:

list[str]

problems()

Every broken rule, including begin signals which never got their end signal

Return type:

list[str]

emitted

(signal name, args) in the order they were emitted

qtModelTester(model)

Attach Qt’s QAbstractItemModelTester to the model, when this binding has it.

It is not in PySide2 5.15 or in Maya 2027 (no QtTest). It reports through Qt warnings, in Warning mode so a failure never aborts the process. Keep the returned object alive while the model is used.

Returns:

the tester, None when the binding has none

Case

The QtTestCase base class.

class QtTestCase(methodName='runTest')

Bases: TestCase

Base for tests which need widgets. Runs standalone (offscreen) and in mayapy or Maya.

Skips when ZOO_NO_QTESTS=1. Pass every top level widget to track() so it is closed after the test, or a window every test of the class shares to trackClass() so it is closed after the class.

Qt objects must die while the QApplication is alive. A Python owned QObject in a reference cycle (a model and its data sources, a data source and its children) is only freed by the cycle collector, and when that first runs at interpreter shutdown the QApplication is already gone: interactive Maya then crashes on exit with an access violation and no crash log. So tearDown drops the Qt objects a test stored on itself (the test result keeps test instances alive) and tearDownClass collects the cycles and runs the pending deleteLater() calls.

Zoo windows are parented to the host’s main window and closing a frameless window only hides its container, so every Zoo top level window the class opened (and didn’t track) is deleted in tearDownClass too. Dozens of hidden windows left under Maya’s main window crash Maya when it quits. Set the Qt property zooTestKeep to True on a window which must outlive the class (the shared demo window).

zoo.libs.pyqt.utils.currentScreenGeometry() returns fixtures.TEST_SCREEN_GEOMETRY during the class, so code which keeps windows inside the screen behaves the same on every machine, Qt binding and host.

KEEP_PROPERTY = 'zooTestKeep'

Qt property which keeps a top level window alive after the class, see the class docstring

zooQtTest = True

marks the class as a Qt test for runners which filter

classmethod setUpClass()

Skips the class when ZOO_NO_QTESTS=1, otherwise gets the shared QApplication as cls.app

Raises:

unittest.SkipTest – if Qt tests are disabled or the running application is not a QApplication

tearDown()

Closes and deletes the tracked widgets, then runs the event loop once

classmethod tearDownClass()

Deletes the Zoo windows the class left open and frees the Qt objects left in reference cycles, while the QApplication is alive, see the class docstring

track(widget)

Register a widget to be closed and deleted in tearDown

Returns:

the widget

classmethod trackClass(widget)

Register a widget shared by every test of the class, usually created in setUpClass. It stays open between the tests, like a window a user keeps open, and is closed and deleted in tearDownClass. Reset the state a test changes in setUp so the tests don’t depend on their order.

Returns:

the widget

patchFrameIcons()

Patch the collapsable frame icons for this test, the engine icons aren’t needed

Helpers

Event loop and input helpers. Wait on conditions, never on fixed sleeps.

settle(ms=80)

Run the event loop for ms milliseconds so delayed refreshes run, always at least once so settle(0) runs the pending events

waitFor(predicate, timeout=2000)

Process events until predicate() is true.

Polls instead of using QTest.qWaitFor, which PySide2 5.15 does not have.

Parameters:
  • predicate – callable returning bool

  • timeout – max wait in milliseconds

Returns:

True if the predicate became true

Return type:

bool

showAndWait(widget)

Show the widget and wait until it is exposed

click(widget, button=MockExt.QtCore.Qt.LeftButton, pos=None, modifier=MockExt.QtCore.Qt.NoModifier)

QTest mouse click on the widget

Parameters:
  • widget (QtWidgets.QWidget) – The widget to click

  • button – The mouse button

  • pos (QtCore.QPoint or None) – Position in widget coordinates, None for the center

  • modifier – Keyboard modifier held during the click

contextMenu(widget, pos=None)

Send a context menu event (what a right click does on a real platform: the offscreen platform does not turn a right button click into one), so customContextMenuRequested and contextMenuEvent run

Parameters:
  • widget (QtWidgets.QWidget) – The widget to ask

  • pos (QtCore.QPoint or None) – Position in widget coordinates, None for the center

hover(widget, pos=None)

Move the mouse onto the widget: sends an enter event then a mouse move without buttons

Parameters:
  • widget (QtWidgets.QWidget) – The widget to hover

  • pos (QtCore.QPoint or None) – Position in widget coordinates, None for the center

leave(widget)

Move the mouse off the widget: sends a leave event

wheel(widget, delta=120, pos=None, modifier=MockExt.QtCore.Qt.NoModifier)

Scroll the mouse wheel over the widget. 120 is one notch up, -120 one notch down.

Parameters:
  • widget (QtWidgets.QWidget) – The widget under the cursor

  • delta (int) – Vertical angle delta in 1/8 degrees

  • pos (QtCore.QPoint or None) – Position in widget coordinates, None for the center

  • modifier – Keyboard modifier held, eg Ctrl

doubleClick(widget, button=MockExt.QtCore.Qt.LeftButton, pos=None)

QTest mouse double click on the widget

Parameters:
  • widget (QtWidgets.QWidget) – The widget to double click

  • button – The mouse button

  • pos (QtCore.QPoint or None) – Position in widget coordinates, None for the center

keyClick(widget, key, modifier=MockExt.QtCore.Qt.NoModifier)

QTest key press and release on the widget

Parameters:
  • widget (QtWidgets.QWidget) – The widget which gets the key

  • key – A QtCore.Qt.Key

  • modifier – Keyboard modifier held during the key

keyClicks(widget, text)

QTest types the text into the widget, one key click per character

Parameters:
  • widget (QtWidgets.QWidget) – The widget which gets the keys

  • text (str) – The text to type

drag(widget, start, end, button=MockExt.QtCore.Qt.LeftButton, steps=5)

Press at start, move to end in steps with the button held, release. Positions are QPoints in widget coordinates. Sends the events directly: QTest.mouseMove does not report the held button reliably.

resizeAndSettle(widget, width, height, ms=40)

Resize the widget then run the event loop so layouts and delayed refreshes follow

Parameters:
  • widget (QtWidgets.QWidget) – The widget to resize

  • width – New width in pixels

  • height – New height in pixels

  • ms – How long to run the event loop, in milliseconds

collectSignal(signal)

A list which records the args of every emission. A plain list on purpose: QSignalSpy is not reliable across PySide2 and PySide6

Returns:

list of tuples of emitted args

Return type:

list

runWithPopup(trigger, inspect=None, timeout=2000)

Call trigger which opens a blocking popup or modal (QMenu.exec_, QDialog.exec_), look at the popup then close it, so the trigger returns. A test would hang forever on a blocking popup otherwise.

A timer polls for QApplication.activePopupWidget() then activeModalWidget(). When one is found inspect(widget) runs (if given) and the widget is closed. When none appears within timeout ms the trigger is left alone (it cannot be interrupted if it does block), so only use this for triggers which open a popup.

Parameters:
  • trigger – callable which opens the popup, eg lambda: testing.click(button)

  • inspect – callable receiving the popup, its return value is returned by this function

  • timeout – max wait for the popup in milliseconds

Returns:

the result of inspect, the popup if inspect is None, None if no popup appeared

runWithWindow(trigger, windowType, inspect=None, timeout=2000)

Like runWithPopup() for blocking windows which are not Qt popups or modals, eg a window which waits in a loop of processEvents until it is closed (MessageBox.showQuestion).

A timer polls the top level widgets (and their children, as frameless windows live in a container) for a visible instance of windowType. When found inspect(window) runs (it may click the window’s buttons, which closes it) and the window is closed if it is still open.

Parameters:
  • trigger – callable which shows the window and blocks until it is closed

  • windowType – class (or tuple of classes) of the window to wait for

  • inspect – callable receiving the window, its return value is returned by this function

  • timeout – max wait for the window in milliseconds

Returns:

the result of inspect, the window if inspect is None, None if no window appeared

grabImage(widget)

A QImage of the widget, for smoke checks only (no pixel exact asserts: fonts and DPI differ)

Decorators

Decorators which skip a test, instead of failing it, when the host or GUI it needs is missing.

requiresHost(obj)

Skip unless maya.cmds can be imported

requiresGui(obj)

Skip unless running in a real GUI session (interactive Maya)

Fixtures

Stand-ins for engine pieces which widgets reach at import or construction time.

class StubThemeInterface(theme=None)

Stands in for the core_interface preference interface when Zoo has not started.

Reads the default theme from the zoo_preferences stylesheet.pref and zootools_style.qss when that package is installed, so widgets get real theme colors (BUTTON_ICON_COLOR) and a real stylesheet. Anything else is a MagicMock. Without zoo_preferences the stylesheet is empty and every theme value is a MagicMock.

stylesheet(theme=None)
Return type:

zoo.libs.pyqt.stylesheet.StyleSheet

property themeUpdated

Signal emitting the theme update event, nothing emits it in tests unless the test does

stubPreferences()

Make zoo.preferences.core.preference usable when Zoo has not started.

A few widgets (buttons, groupedtreewidget) read the preference manager at import, and it is None until Zoo starts. A stub is only installed when ALL of these hold, so a live session is never touched:

  • the preference manager is still None (Zoo has not set it up)

  • this is not a real GUI session (interactive Maya, see environment.isGui())

Temporary: goes away when widgets stop reading preferences at import. Undo with removeStubPreferences().

Returns:

True if a stub was installed

Return type:

bool

removeStubPreferences()

Remove the stub made by stubPreferences(), only if it is still the one installed (never a real manager)

Returns:

True if a stub was removed

Return type:

bool

stubEngine()

Make zoo.core.engine.currentEngine() usable when Zoo has not started, so iconlib and dialogs work.

The icon library asks the engine whether the host is headless. A stub (a non headless host) is installed only when there is no engine and this is not a real GUI session. Undo with removeStubEngine().

Returns:

True if a stub was installed

Return type:

bool

removeStubEngine()

Remove the engine made by stubEngine(), only if it is still the current one

Returns:

True if a stub was removed

Return type:

bool

stubHeadlessHost()

Make a headless host report that it is not, for the test process only.

mayapy is a headless host: iconlib.icon() returns None there, so every Zoo widget which sets an icon (the title bar of a ZooWindow, the buttons) fails to build. The widgets are created on an offscreen QApplication in the tests, so the icons are needed. Not done in a real GUI session, where the host is not headless anyway. Undo with removeStubHeadlessHost().

Returns:

True if the host was patched

Return type:

bool

removeStubHeadlessHost()

Undo stubHeadlessHost()

Returns:

True if the patch was removed

Return type:

bool

TEST_SCREEN_GEOMETRY = (0, 0, 1920, 1080)

left, top, width, height of the screen the Qt tests run on, the real screen differs per machine, Qt binding and host

fixedScreenGeometryPatcher(geometry=(0, 0, 1920, 1080))

The patcher which makes zoo.libs.pyqt.utils.currentScreenGeometry() return the same screen everywhere.

Positions are contained in the screen, so tests which place windows would depend on the size of the offscreen screen of the Qt binding or Maya version they run on. Only the tests are affected, start() and stop() it.

Parameters:

geometry (tuple[int, int, int, int]) – left, top, width and height of the screen.

Return type:

mock._patch

fixedScreenGeometry(geometry=(0, 0, 1920, 1080))

Context manager version of fixedScreenGeometryPatcher()

noFrameIcons()

The collapsable frame icons come from the icon engine, which tests don’t need

Environment

Detects what the test process offers (Maya, a GUI session) and creates the shared QApplication.

hasHost()

If maya.cmds can be imported (mayapy or interactive Maya)

Return type:

bool

isGui()

If this is a real GUI session: a QApplication exists and it is not on a headless platform

Return type:

bool

mode()
Returns:

one of “standalone”, “host-headless”, “host-gui”

Return type:

str

ensureApplication()

The shared QApplication, created offscreen if there is none. Never creates a second one.

Raises:

unittest.SkipTest – if the running application is not a QApplication, widgets can’t be created

Return type:

QtWidgets.QApplication