2121
2222def _show_info (test_args ):
2323 import ctools
24+
2425 title = "Testing Information"
2526 print ("\n -" * len (title ))
2627 print (title )
2728 print ("-" * len (title ))
2829 print ("Python: " , sys .executable )
29- print ('Ctools:' , ctools .__version__ , "(debug build)" if ctools .build_with_debug () else "" )
30- print ("Arguments:" , " " .join (test_args ), '\n ' )
30+ print (
31+ "Ctools:" ,
32+ ctools .__version__ ,
33+ "(debug build)" if ctools .build_with_debug () else "" ,
34+ )
35+ print ("Arguments:" , " " .join (test_args ), "\n " )
3136
3237
3338class Tester (object ):
3439 def __init__ (self , module_name ):
3540 self .module_name = module_name
3641
37- def __call__ (self , extra_argv = None , coverage = False , include_sys_argv = True , tests = None ,
38- verbose = True ):
42+ def __call__ (
43+ self ,
44+ extra_argv = None ,
45+ coverage = False ,
46+ include_sys_argv = True ,
47+ tests = None ,
48+ verbose = True ,
49+ ):
3950 import pytest
4051
4152 module = sys .modules [self .module_name ]
@@ -55,11 +66,11 @@ def __call__(self, extra_argv=None, coverage=False, include_sys_argv=True, tests
5566 test_args .extend (sys .argv [1 :])
5667
5768 test_args += ["--pyargs" ] + list (tests )
58- test_args += ["--deselect" , os .path .join (here , ' tests' , ' _bases.py' )]
69+ test_args += ["--deselect" , os .path .join (here , " tests" , " _bases.py" )]
5970
6071 if verbose :
6172 for i in test_args :
62- if i .startswith ('-v' ):
73+ if i .startswith ("-v" ):
6374 break
6475 else :
6576 test_args .append ("-vvv" )
@@ -74,11 +85,13 @@ def __call__(self, extra_argv=None, coverage=False, include_sys_argv=True, tests
7485 return code
7586
7687
77- _memory_report = namedtuple ('MemoryReport' , "exc_code,cycles,max_rss,last_rss,max_incr,cum_incr,escaped" )
88+ _memory_report = namedtuple (
89+ "MemoryReport" , "exc_code,cycles,max_rss,last_rss,max_incr,cum_incr,escaped"
90+ )
7891
7992
8093def memory_leak_test (
81- test , max_rss = None , max_incr = None , cycles = None , multi = 10 , log_prefix = "" , log = True ,
94+ test , max_rss = None , max_incr = None , cycles = None , multi = 10 , log_prefix = "" , log = True
8295):
8396 import time
8497 import psutil
@@ -90,7 +103,7 @@ def memory_leak_test(
90103
91104 pid = os .getpid ()
92105 process = psutil .Process (pid )
93- print_ (' PID =' , pid )
106+ print_ (" PID =" , pid )
94107
95108 cycle_count = 1
96109 last_rss = None
@@ -124,15 +137,17 @@ def memory_leak_test(
124137 incr_limit = multi * cum_incr
125138
126139 print_ (log_prefix , end = " " )
127- print_ (f"loop={ cycle_count } , escaped={ spend } , rss={ rss_bytes :,} , increase={ incr :,} " )
140+ print_ (
141+ f"loop={ cycle_count } , escaped={ spend } , rss={ rss_bytes :,} , increase={ incr :,} "
142+ )
128143
129144 if rss_limit and rss_bytes > rss_limit :
130145 print_ (f"rss { rss_bytes :,} touch roof { rss_limit :,} " )
131146 exc_code = 1
132147 break
133148
134149 if incr_limit and cum_incr > incr_limit :
135- print_ (f' rss increase { cum_incr :,} touch roof { incr_limit :,} ' )
150+ print_ (f" rss increase { cum_incr :,} touch roof { incr_limit :,} " )
136151 exc_code = 1
137152 break
138153
@@ -145,8 +160,14 @@ def memory_leak_test(
145160 break
146161
147162 except KeyboardInterrupt :
148- print_ (_memory_report (exc_code , cycle_count , max_rss , last_rss , max_incr , cum_incr , escaped ))
163+ print_ (
164+ _memory_report (
165+ exc_code , cycle_count , max_rss , last_rss , max_incr , cum_incr , escaped
166+ )
167+ )
149168 raise
150- report = _memory_report (exc_code , cycle_count , max_rss , last_rss , max_incr , cum_incr , escaped )
169+ report = _memory_report (
170+ exc_code , cycle_count , max_rss , last_rss , max_incr , cum_incr , escaped
171+ )
151172 print_ (report )
152173 return report
0 commit comments