This module exposes spy's core API.
spy.decorators
Function
decorators <decorator>
for use with spy fragments
spy
DROP
A signaling object: when returned from a fragment
, the fragment will not yield any value.
CaughtException
print_traceback()
Print the (formatted) traceback captured when the exception was raised.
A context manager
. Exceptions raised in the context will be subject to spy's traceback formatting and wrapped in a CaughtException
. If these are not caught, spy uses an exception hook to force them to be formatted properly. If you opt to catch CaughtException
instead, you can use its ~CaughtException.print_traceback
method to print the formatted traceback without exiting.
Construct a chain of fragments <fragment>
from seq
.
- param seq
Fragments to chain together
- type seq
sequence
__call__(data)
Alias for apply
.
apply(data)
Feed data
into the fragment chain, and return an iterator over the resulting data.
auto_fragments(seq)
Like the regular constructor, but for each element in seq
, apply fragment
to it if it isn't already a fragment.
Items in seq must be either regular functions (not generators) or fragments <fragment>
.
run_to_exhaustion(data)
Call apply
, then iterate until the chain runs out of data.
collect(context)
Return an iterator
of the elements being processed by the current fragment. Can be used to write a fragment that consumes multiple items.
fragment
Given a callable
func
, return a fragment
that calls func
to process data. func
must take at least one positional argument, a single value to process and return.
Optionally it can take another argument, called context
. If it does, a context object will be passed to it on each invocation. This object has no documented public functionality; its purpose is to be passed to spy API functions that require it (namely collect
).
many(ita)
Return a signaling object that instructs spy to yield values from ita
from the current fragment, instead of yielding only one value.