def test_with_refcounts(runner, verbosity, testcase):
 import gc
 import ctypes
 ptc = ctypes._pointer_type_cache.copy()
 cfc = ctypes._c_functype_cache.copy()
 wfc = ctypes._win_functype_cache.copy()
 def cleanup():
  ctypes._pointer_type_cache = ptc.copy()
  ctypes._c_functype_cache = cfc.copy()
  ctypes._win_functype_cache = wfc.copy()
  gc.collect()
 test = unittest.makeSuite(testcase)
 for i in range(5):
  rc = sys.gettotalrefcount()
  runner.run(test)
  cleanup()
 COUNT = 5
 refcounts = ([None] * COUNT)
 for i in range(COUNT):
  rc = sys.gettotalrefcount()
  runner.run(test)
  cleanup()
  refcounts[i] = (sys.gettotalrefcount() - rc)
 if filter(None, refcounts):
  print ('%s leaks:\n DCTB ' % testcase), refcounts
 elif verbosity:
  print ('%s: ok.' % testcase)

def test_with_refcounts ( runner , verbosity , testcase ) : import gc import ctypes ptc = ctypes . _pointer_type_cache . copy ( ) cfc = ctypes . _c_functype_cache . copy ( ) wfc = ctypes . _win_functype_cache . copy ( ) def cleanup ( ) : ctypes . _pointer_type_cache = ptc . copy ( ) ctypes . _c_functype_cache = cfc . copy ( ) ctypes . _win_functype_cache = wfc . copy ( ) gc . collect ( ) test = unittest . makeSuite ( testcase ) for i in range ( 5 ) : rc = sys . gettotalrefcount ( ) runner . run ( test ) cleanup ( ) COUNT = 5 refcounts = ( [ None ] * COUNT ) for i in range ( COUNT ) : rc = sys . gettotalrefcount ( ) runner . run ( test ) cleanup ( ) refcounts [ i ] = ( sys . gettotalrefcount ( ) - rc ) if filter ( None , refcounts ) : print ( '%s leaks:\n DCTB ' % testcase ) , refcounts elif verbosity : print ( '%s: ok.' % testcase )
run testcase several times .