intercom_test.utils module

class intercom_test.utils.FilteredDictView(d, *, key_filter=None, value_transform=None)[source]

Bases: object

dict-like access to a key-filtered and value-transformed dict

Only _viewing_ methods are supported, not modifications.

class Items(dview)[source]

Bases: object

class Keys(dview)[source]

Bases: object

class Values(dview)[source]

Bases: object

get(k, defval=None)[source]
items()[source]
keys()[source]
values()[source]
intercom_test.utils.attributed_error(cls)[source]

Expose exception instance constructor arguments (or specified names) as properties

If the only purpose of the exception class constructor would be to generate properties from the argument names, the ATTRIBUTES attribute of the class can be assigned with either an iterable of str or a single str (which will be str.split()) to more concisely specify the names to map to the arguments passed to the constructor.

intercom_test.utils.complex_test_context(fn)[source]

Decorator to facilitate building a test environment through context managers

The callable decorated should accept a test case and a context entry callable. The test case is simply passed through from the wrapper. The context entry callable should be called on a context manager to enter its context, and all contexts will be exited in reverse order when the decorated function exits. This compares to the defer statement in the Go programming language or scope(exit) at the function level for the D programming language.

Example:

@complex_test_context
def around_interface_case(case, setup):
    setup(database_fixtures(case))
    setup(stubs(case))
    
    yield
intercom_test.utils.def_enum(fn)[source]

Decorator allowing a function to DRYly define an enumeration

The decorated function should not require any arguments and should return an enumeration source, which will be passed to enum.Enum along with the name of the decorated function. The resulting enum.Enum-derived class will be returned.

The value returned by fn can be any kind of source accepted by the functional API of enum.Enum.

intercom_test.utils.open_temp_copy(path, binary=False, *, blocksize=None)[source]

Make a temporary copy of path and return the opened file

The returned file object will be opened with mode 'w+' or 'w+b' (depending on binary) and will be positioned at the beginning of the file contents. If specified, blocksize indicates the size of the buffer to use (in bytes) when making the copy.

intercom_test.utils.optional_key(mapping, key)[source]

Syntactic sugar for working with dict keys that might be present

Typical usage:

for value in optional_key(d, 'answer'):
    # Body executed once, with *value* assigned ``d['answer']``, if
    # *d* contains ``'answer'``.  The body of the ``for`` is not
    # executed at all, otherwise.
    print(f"The answer: {value}")