schrodinger.test.unittest_utils module¶
- schrodinger.test.unittest_utils.change_booleaness(obj, truth_value)[source]¶
Sets the return value for __bool__ or __nonzero__ depending on whether or not you are in Python 2 or Python 3
- Parameters
obj (objects) – An object that has the __bool__ or __nonzero__ attribute
truth_value (bool) – What __bool__ or __nonzero__ should return
- schrodinger.test.unittest_utils.wait_until_condition_met(success_cond_func, poll_interval=500, timeout=300)[source]¶
Call
success_cond_func
until it returns True or the time runs out.- Parameters
success_cond_func (callable) – Function to call until it returns True
poll_interval (int) – How often to check for success (milliseconds)
timeout (int) – When to time out (seconds)
- Returns
Whether the function timed out
- Return type
bool
- class schrodinger.test.unittest_utils.PatchStack[source]¶
Bases:
contextlib.ExitStack
Context manager for patching multiple paths at once.
Usage:
with PatchStack() as stack: stack.patch("foo_module", return_value=bar)
- patch(path, *args, **kwargs)[source]¶
Patch the given path. args and kwargs will be passed to mock.patch.
- patchObject(obj, attribute, *args, **kwargs)[source]¶
Patch an object’s attribute. args and kwargs will be passed to mock.patch.object.
- __init__()¶
- callback(callback, /, *args, **kwds)¶
Registers an arbitrary callback and arguments.
Cannot suppress exceptions.
- close()¶
Immediately unwind the context stack.
- enter_context(cm)¶
Enters the supplied context manager.
If successful, also pushes its __exit__ method as a callback and returns the result of the __enter__ method.
- pop_all()¶
Preserve the context stack by transferring it to a new instance.
- push(exit)¶
Registers a callback with the standard __exit__ method signature.
Can suppress exceptions the same way __exit__ method can. Also accepts any object with an __exit__ method (registering a call to the method instead of the object itself).