exopy.testing.util module

Generic utility functions for testing.

exopy.testing.util.exopy_path()[source]

Get the exopy path as determined by the sys_path fixture.

exopy.testing.util.process_app_events()[source]

Manually run the Qt event loop so that windows are shown and event propagated.

exopy.testing.util.get_window(cls=<class 'enaml.widgets.window.Window'>)[source]

Convenience function running the event loop and returning the first window found in the set of active windows.

Parameters

cls (type, optional) – Type of the window which should be returned.

exopy.testing.util.close_all_windows()[source]

Close all opened windows.

This should be used by all tests creating windows in a teardown step.

class exopy.testing.util.ScheduledClosing(cls, handler, op, skip_answer)[source]

Bases: object

Scheduled closing of dialog.

exopy.testing.util.handle_dialog(op='accept', custom=<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.

  • custom (callable, optional) – Callable taking as only argument 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.handle_question(answer)[source]

Handle question dialog.

exopy.testing.util.show_widget(widget)[source]

Show a widget in a window

exopy.testing.util.show_and_close_widget(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.

stop_tracking()[source]

Use to properly remove tracking.

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.