def make_call_asserter(func=None):
 calls = [0]
 @contextmanager
 def asserter(count, msg=None):
  calls[0] = 0
  (yield)
  assert (calls[0] == count)
 def wrapped(*args, **kwargs):
  calls[0] += 1
  if (func is not None):
   return func(*args, **kwargs)
 return (asserter, wrapped)

def make_call_asserter ( func = None ) : calls = [ 0 ] @ contextmanager def asserter ( count , msg = None ) : calls [ 0 ] = 0 ( yield ) assert ( calls [ 0 ] == count ) def wrapped ( * args , ** kwargs ) : calls [ 0 ] += 1 if ( func is not None ) : return func ( * args , ** kwargs ) return ( asserter , wrapped )
utility to assert a certain number of function calls .