77 python3 run_tests.py
88 python3 run_tests.py -v # verbose mode
99"""
10- import faulthandler
10+ from __future__ import absolute_import
11+ from __future__ import print_function
1112import os .path
1213import shutil
1314import subprocess
1415import sys
16+ try :
17+ import faulthandler
18+ except ImportError :
19+ # Python 2
20+ faulthandler = None
1521
16-
17- VERBOSE = False
22+ # test.utils
23+ from utils import run_command , command_stdout
1824
1925
20- def run_command (args , ** kw ):
21- proc = subprocess .run (args )
22- if proc .returncode :
23- sys .exit (proc .returncode )
24- return proc
26+ VERBOSE = False
2527
2628
2729def display_title (title ):
@@ -43,13 +45,10 @@ def build_ext():
4345 run_command (cmd )
4446 print ()
4547 else :
46- proc = subprocess .run (cmd ,
47- stdout = subprocess .PIPE ,
48- stderr = subprocess .STDOUT ,
49- universal_newlines = True )
50- if proc .returncode :
51- print (proc .stdout .rstrip ())
52- sys .exit (proc .returncode )
48+ exitcode , stdout = command_stdout (cmd , stderr = subprocess .STDOUT )
49+ if exitcode :
50+ print (stdout .rstrip ())
51+ sys .exit (exitcode )
5352
5453
5554def import_tests ():
@@ -68,7 +67,8 @@ def import_tests():
6867def _run_tests (tests , verbose ):
6968 for name , test_func in tests :
7069 if verbose :
71- print (f"{ name } ()" , flush = True )
70+ print ("%s()" % name )
71+ sys .stdout .flush ()
7272 test_func ()
7373
7474
@@ -78,14 +78,14 @@ def _check_refleak(test_func, verbose):
7878 if verbose :
7979 if i > 1 :
8080 print ()
81- print (f "Run { i } / { nrun } :" )
81+ print ("Run %s/%s:" % ( i , nrun ) )
8282
8383 init_refcnt = sys .gettotalrefcount ()
8484 test_func ()
8585 diff = sys .gettotalrefcount () - init_refcnt
8686
8787 if i > 3 and diff :
88- raise AssertionError (f "refcnt leak, diff: { diff } " )
88+ raise AssertionError ("refcnt leak, diff: %s" % diff )
8989
9090
9191def run_tests (testmod ):
@@ -110,18 +110,19 @@ def test_func():
110110
111111 ver = sys .version_info
112112 build = 'debug' if hasattr (sys , 'gettotalrefcount' ) else 'release'
113- msg = f" { len ( tests ) } tests succeeded!"
114- msg = f "Python { ver .major } . { ver .minor } ( { build } build): { msg } "
113+ msg = "%s tests succeeded!" % len ( tests )
114+ msg = "Python %s.%s (%s build): %s" % ( ver .major , ver .minor , build , msg )
115115 if check_refleak :
116- msg = f" { msg } (no reference leak detected)"
116+ msg = "%s (no reference leak detected)" % msg
117117 print (msg )
118118
119119
120120def main ():
121121 global VERBOSE
122122 VERBOSE = "-v" in sys .argv [1 :]
123123
124- faulthandler .enable ()
124+ if faulthandler is not None :
125+ faulthandler .enable ()
125126
126127 src_dir = os .path .dirname (__file__ )
127128 if src_dir :
0 commit comments