traits_futures.asyncio.event_loop_helper module

Test support, providing the ability to run the event loop from tests.

class traits_futures.asyncio.event_loop_helper.EventLoopHelper(event_loop)[source]

Bases: object

Support for running the asyncio event loop in unit tests.

Parameters:

event_loop (asyncio.AbstractEventLoop) – The asyncio event loop that this object wraps.

dispose()[source]

Dispose of any resources used by this object.

init()[source]

Prepare the event loop for use.

run_until(object, trait, condition, timeout)[source]

Run event loop until a given condition occurs, or timeout.

The condition is re-evaluated, with the object as argument, every time the trait changes.

Parameters:
  • object (traits.has_traits.HasTraits) – Object whose trait we monitor.

  • trait (str) – Name of the trait to monitor for changes.

  • condition – Single-argument callable, returning a boolean. This will be called with object as the only input.

  • timeout (float) – Number of seconds to allow before timing out with an exception.

Raises:

RuntimeError – If timeout is reached, regardless of whether the condition is true or not at that point.

setattr_soon(obj, name, value)[source]

Arrange for an attribute to be set once the event loop is running.

In typical usage, obj will be a HasTraits instance and name will be the name of a trait on obj.

This method is not thread-safe. It’s designed to be called from the main thread.

Parameters:
  • obj (object) – Object to set the given attribute on.

  • name (str) – Name of the attribute to set; typically this is a traited attribute.

  • value (object) – Value to set the attribute to.