diff options
author | Paul "LeoNerd" Evans <paul@matrix.org> | 2014-08-28 16:40:06 +0100 |
---|---|---|
committer | Paul "LeoNerd" Evans <paul@matrix.org> | 2014-08-28 16:40:06 +0100 |
commit | 113342a7568ff3d019de5099880671417bf4ecf2 (patch) | |
tree | 85349ac220fa212a812cf3cb8dfea67a3a9307e5 /tests/utils.py | |
parent | Avoid AlreadyCalledError from EDU sending failures (diff) | |
download | synapse-113342a7568ff3d019de5099880671417bf4ecf2.tar.xz |
Ability to assert a DeferredMockCallable has received no calls
Diffstat (limited to 'tests/utils.py')
-rw-r--r-- | tests/utils.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/tests/utils.py b/tests/utils.py index b32d5ef356..98d4f9ed58 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -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 + ]) + ) |