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-transformeddict
Only _viewing_ methods are supported, not modifications.
-
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 ofstr
or a singlestr
(which will bestr.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 orscope(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 resultingenum.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}")