exopy.testing.util module¶
Generic utility functions for testing.
-
exopy.testing.util.
run_pending_tasks
(qtbot, timeout=1000)[source]¶ Run all enaml pending tasks.
WARNING: this may not run the Qt event loop if no task is pending. This will only deal with tasks schedule through the schedule function (or Application method)
- Parameters
timeout (
int
, optional) – Timeout after which the operation should fail in ms
-
exopy.testing.util.
get_window
(qtbot, cls=<class 'enaml.widgets.window.Window'>, timeout=1000)[source]¶ Convenience function running the event loop and returning the first window found in the set of active windows.
- Parameters
- Returns
window – Return the first window found matching the specified class
- Return type
Window
orNone
:raises AssertionError : raised if no window is found in the given time:
-
exopy.testing.util.
get_popup
(qtbot, cls=<class 'enaml.widgets.popup_view.PopupView'>, timeout=1000)[source]¶ Convenience function running the event loop and returning the first popup found in the set of active popups.
- Parameters
- Returns
popup – Return the first window found matching the specified class
- Return type
PopupView
orNone
:raises AssertionError : raised if no popup is found in the given time:
-
exopy.testing.util.
wait_for_window_displayed
(qtbot, window, timeout=1000)[source]¶ Wait for a window to be displayed.
This method should be called on already activated windows (the show method should have been called).
-
class
exopy.testing.util.
EventObserver
[source]¶ Bases:
atom.atom.Atom
Simple observer registering the fact it was called once.
-
called
¶ A value of type bool.
-
-
exopy.testing.util.
close_window_or_popup
(qtbot, window_or_popup)[source]¶ Close a window/popup and run the event loop to make sure the closing complete.
-
class
exopy.testing.util.
ScheduledClosing
(bot, cls, handler, op, skip_answer)[source]¶ Bases:
object
Scheduled closing of dialog.
-
exopy.testing.util.
handle_dialog
(qtbot, op='accept', handler=<function <lambda>>, cls=<class 'enaml.widgets.dialog.Dialog'>, time=100, skip_answer=False)[source]¶ Automatically close a dialog opened during the context.
- Parameters
op (
{'accept', 'reject'}
, optional) – Whether to accept or reject the dialog.handler (
callable
, optional) – Callable taking as arguments the bot and the dialog, called before accepting or rejecting the dialog.cls (
type
, optional) – Dialog class to identify.time (
float
, optional) – Time to wait before handling the dialog in ms.skip_answer (
bool
, optional) – Skip answering to the dialog. If this is True the handler should handle the answer itself.
-
exopy.testing.util.
show_and_close_widget
(qtbot, widget)[source]¶ Show a widget in a window and then close it.
-
exopy.testing.util.
set_preferences
(workbench, preferences)[source]¶ Set the preferences stored in the preference plugin.
This function must be called before accessing any plugin relying on those values.
- Parameters
workbench – Application workbench.
preferences (
dict
) – Dictionary describing the preferences.
-
exception
exopy.testing.util.
ErrorDialogException
[source]¶ Bases:
Exception
Error raised when patching the error plugin to raise rather than show a dialog when exiting error gathering.
-
exopy.testing.util.
signal_error_raise
()[source]¶ Make the error plugin raise an exception when signaling.
-
exopy.testing.util.
exit_on_err
(self)[source]¶ Replacement function for exopy.app.errors plugin exit_error_gathering.
This function will raise instead of displaying a dialog. Useful to catch unexpected errors.
Should be used in conjunction with the monkeypatch fixture.
-
class
exopy.testing.util.
CallSpy
[source]¶ Bases:
object
Object simply monitoring how many times it gets called.
-
called
¶
-
args
¶
-
kwargs
¶
-
-
class
exopy.testing.util.
ObjectTracker
(cls, has_weakref=True)[source]¶ Bases:
object
Object tracking instance of a given class exists.
It works by patching __new__ and keeping a WeakSet of the created objects. So instances created before creating the tracker are not tracked.
If the objects are not weak referenceable you should set has_weakref to False. By default objects inheriting from Atom are not weak referenceable. It provides way to list the object referring alive objects to help tracking ref leaks.
-
property
alive_instances
¶ Currently alive instances of the tracked objects.
-
list_referrers
(exclude=[], depth=0)[source]¶ List all the referrers of the tracked objects.
Can exlude some objects and go to deeper levels (referrers of the referrers) in which case reference to the first object are filtered. References held by frames are also filtered
This function is mostly useful when tracking why an object that is expected to be released is not.
-
property