Revision ebfb2f46

b/test/testutils.py
223 223
                 for (key, value) in data.iteritems()])
224 224

  
225 225
  return data
226

  
227

  
228
class CallCounter(object):
229
  """Utility class to count number of calls to a function/method.
230

  
231
  """
232
  def __init__(self, fn):
233
    """Initializes this class.
234

  
235
    @type fn: Callable
236

  
237
    """
238
    self._fn = fn
239
    self._count = 0
240

  
241
  def __call__(self, *args, **kwargs):
242
    """Calls wrapped function with given parameters.
243

  
244
    """
245
    self._count += 1
246
    return self._fn(*args, **kwargs)
247

  
248
  def Count(self):
249
    """Returns number of calls.
250

  
251
    @rtype: number
252

  
253
    """
254
    return self._count

Also available in: Unified diff