diff options
author | Erik Johnston <erik@matrix.org> | 2014-08-28 16:52:46 +0100 |
---|---|---|
committer | Erik Johnston <erik@matrix.org> | 2014-08-28 16:52:46 +0100 |
commit | 54d0a755734f71e38c5cdc0e922422cc4d31ad74 (patch) | |
tree | 4d0256be69f304553d0efaa71ec50498f3821683 /tests/utils.py | |
parent | Up timeout to 10 minutes (diff) | |
parent | Only send presence "poll"/"unpoll" EDUs when changing from/to zero remotes (diff) | |
download | synapse-54d0a755734f71e38c5cdc0e922422cc4d31ad74.tar.xz |
Merge branch 'develop' of github.com:matrix-org/synapse into presence_logging
Conflicts: synapse/handlers/presence.py
Diffstat (limited to 'tests/utils.py')
-rw-r--r-- | tests/utils.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/tests/utils.py b/tests/utils.py index 6666b06931..98d4f9ed58 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -28,6 +28,16 @@ from mock import patch, Mock import json import urlparse +from inspect import getcallargs + + +def get_mock_call_args(pattern_func, mock_func): + """ Return the arguments the mock function was called with interpreted + by the pattern functions argument list. + """ + invoked_args, invoked_kargs = mock_func.call_args + return getcallargs(pattern_func, *invoked_args, **invoked_kargs) + # This is a mock /resource/ not an entire server class MockHttpResource(HttpServer): @@ -238,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)) @@ -262,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 + ]) + ) |