MCPcopy
hub / github.com/pallets/werkzeug / make_call_asserter

Function make_call_asserter

tests/test_datastructures.py:931–955  ·  view source on GitHub ↗

Utility to assert a certain number of function calls. :param func: Additional callback for each function call. .. code-block:: python assert_calls, func = make_call_asserter() with assert_calls(2): func() func()

(func=None)

Source from the content-addressed store, hash-verified

929
930
931def make_call_asserter(func=None):
932 """Utility to assert a certain number of function calls.
933
934 :param func: Additional callback for each function call.
935
936 .. code-block:: python
937 assert_calls, func = make_call_asserter()
938 with assert_calls(2):
939 func()
940 func()
941 """
942 calls = [0]
943
944 @contextmanager
945 def asserter(count, msg=None):
946 calls[0] = 0
947 yield
948 assert calls[0] == count
949
950 def wrapped(*args, **kwargs):
951 calls[0] += 1
952 if func is not None:
953 return func(*args, **kwargs)
954
955 return asserter, wrapped
956
957
958class TestCallbackDict:

Callers 2

Calls

no outgoing calls

Tested by

no test coverage detected