5.1. spy¶
This module exposes spy’s core API.
See also
spy.decorators- Function decorators for use with spy fragments
5.1.1. Constants¶
5.1.2. Exceptions¶
5.1.3. Functions¶
-
class
spy.catch¶ 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 catchCaughtExceptioninstead, you can use itsprint_traceback()method to print the formatted traceback without exiting.
-
class
spy.chain(seq)[source]¶ Construct a chain of fragments from
seq.Parameters: seq (sequence) – Fragments to chain together -
apply(data)[source]¶ Feed
datainto the fragment chain, and return an iterator over the resulting data.
-
classmethod
auto_fragments(seq)[source]¶ Like the regular constructor, but for each element in
seq, applyfragment()to it if it isn’t already a fragment.Items in seq must be either regular functions (not generators) or fragments.
-
-
spy.collect(context)[source]¶ Return an iterator of the elements being processed by the current fragment. Can be used to write a fragment that consumes multiple items.
-
@spy.fragment[source]¶ Given a callable
func, return a fragment that callsfuncto process data.funcmust 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 (namelycollect()).