def function_call_count(variance=0.05):
 def decorate(fn):
  def wrap(*args, **kw):
   if (cProfile is None):
    raise SkipTest('cProfile is not installed')
   if ((not _profile_stats.has_stats()) and (not _profile_stats.write)):
    fn(*args, **kw)
    raise SkipTest(('No profiling stats available on this platform for this function.  Run tests with --write-profiles to add statistics to %s for this platform.' % _profile_stats.short_fname))
   gc_collect()
   (timespent, load_stats, fn_result) = _profile(fn, *args, **kw)
   stats = load_stats()
   callcount = stats.total_calls
   expected = _profile_stats.result(callcount)
   if (expected is None):
    expected_count = None
   else:
    (line_no, expected_count) = expected
   print ('Pstats calls: %d Expected %s' % (callcount, expected_count))
   stats.print_stats()
   if expected_count:
    deviance = int((callcount * variance))
    failed = (abs((callcount - expected_count)) > deviance)
    if failed:
     if _profile_stats.write:
      _profile_stats.replace(callcount)
     else:
      raise AssertionError(('Adjusted function call count %s not within %s%% of expected %s. Rerun with --write-profiles to regenerate this callcount.' % (callcount, (variance * 100), expected_count)))
   return fn_result
  return update_wrapper(wrap, fn)
 return decorate

def function_call_count ( variance = 0.05 ) : def decorate ( fn ) : def wrap ( * args , ** kw ) : if ( cProfile is None ) : raise SkipTest ( 'cProfile is not installed' ) if ( ( not _profile_stats . has_stats ( ) ) and ( not _profile_stats . write ) ) : fn ( * args , ** kw ) raise SkipTest ( ( 'No profiling stats available on this platform for this function.  Run tests with --write-profiles to add statistics to %s for this platform.' % _profile_stats . short_fname ) ) gc_collect ( ) ( timespent , load_stats , fn_result ) = _profile ( fn , * args , ** kw ) stats = load_stats ( ) callcount = stats . total_calls expected = _profile_stats . result ( callcount ) if ( expected is None ) : expected_count = None else : ( line_no , expected_count ) = expected print ( 'Pstats calls: %d Expected %s' % ( callcount , expected_count ) ) stats . print_stats ( ) if expected_count : deviance = int ( ( callcount * variance ) ) failed = ( abs ( ( callcount - expected_count ) ) > deviance ) if failed : if _profile_stats . write : _profile_stats . replace ( callcount ) else : raise AssertionError ( ( 'Adjusted function call count %s not within %s%% of expected %s. Rerun with --write-profiles to regenerate this callcount.' % ( callcount , ( variance * 100 ) , expected_count ) ) ) return fn_result return update_wrapper ( wrap , fn ) return decorate
assert a target for a test cases function call count .