4.1. spy¶
This module exposes spy’s core API.
See also
- spy.decorators
- Function decorators for use with spy fragments
4.1.1. Constants¶
4.1.2. Exceptions¶
4.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 catch CaughtException instead, you can use its print_traceback() method to print the formatted traceback without exiting.
- class spy.chain(seq)¶
Construct a chain of fragments from seq.
Parameters: seq (sequence) – Fragments to chain together - apply(data)¶
Feed data into the fragment chain, and return an iterator over the resulting data.
- classmethod 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.
- spy.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.
- @spy.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()).
- spy.many(ita)¶
Return a signaling object that instructs spy to yield values from ita from the current fragment, instead of yielding only one value.