mirror of
https://git.anonymousland.org/anonymousland/synapse-product.git
synced 2024-12-11 08:24:19 -05:00
Ability to assert a DeferredMockCallable has received no calls
This commit is contained in:
parent
b1da3fa0a7
commit
113342a756
@ -248,8 +248,11 @@ class DeferredMockCallable(object):
|
||||
|
||||
def __init__(self):
|
||||
self.expectations = []
|
||||
self.calls = []
|
||||
|
||||
def __call__(self, *args, **kwargs):
|
||||
self.calls.append((args, kwargs))
|
||||
|
||||
if not self.expectations:
|
||||
raise ValueError("%r has no pending calls to handle call(%s)" % (
|
||||
self, _format_call(args, kwargs))
|
||||
@ -272,3 +275,15 @@ class DeferredMockCallable(object):
|
||||
while self.expectations:
|
||||
(_, _, d) = self.expectations.pop(0)
|
||||
yield d
|
||||
self.calls = []
|
||||
|
||||
def assert_had_no_calls(self):
|
||||
if self.calls:
|
||||
calls = self.calls
|
||||
self.calls = []
|
||||
|
||||
raise AssertionError("Expected not to received any calls, got:\n" +
|
||||
"\n".join([
|
||||
"call(%s)" % _format_call(c[0], c[1]) for c in calls
|
||||
])
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user