52
52
TEST_EXIT_PASSED = 0
53
53
TEST_EXIT_SKIPPED = 77
54
54
55
+ # 20 minutes represented in seconds
56
+ TRAVIS_TIMEOUT_DURATION = 20 * 60
57
+
55
58
BASE_SCRIPTS = [
56
59
# Scripts that are run by the travis build process.
57
60
# Longest test should go first, to favor running tests in parallel
@@ -236,26 +239,24 @@ def main():
236
239
if tests :
237
240
# Individual tests have been specified. Run specified tests that exist
238
241
# in the ALL_SCRIPTS list. Accept the name with or without .py extension.
239
- tests = [re .sub ("\.py$" , "" , t ) + ".py" for t in tests ]
242
+ tests = [re .sub ("\.py$" , "" , test ) + ".py" for test in tests ]
240
243
test_list = []
241
- for t in tests :
242
- if t in ALL_SCRIPTS :
243
- test_list .append (t )
244
+ for test in tests :
245
+ if test in ALL_SCRIPTS :
246
+ test_list .append (test )
244
247
else :
245
- print ("{}WARNING!{} Test '{}' not found in full test list." .format (BOLD [1 ], BOLD [0 ], t ))
248
+ print ("{}WARNING!{} Test '{}' not found in full test list." .format (BOLD [1 ], BOLD [0 ], test ))
249
+ elif args .extended :
250
+ # Include extended tests
251
+ test_list = ALL_SCRIPTS
246
252
else :
247
- # No individual tests have been specified.
248
- # Run all base tests, and optionally run extended tests.
253
+ # Run base tests only
249
254
test_list = BASE_SCRIPTS
250
- if args .extended :
251
- # place the EXTENDED_SCRIPTS first since the three longest ones
252
- # are there and the list is shorter
253
- test_list = EXTENDED_SCRIPTS + test_list
254
255
255
256
# Remove the test cases that the user has explicitly asked to exclude.
256
257
if args .exclude :
257
- tests_excl = [re .sub ("\.py$" , "" , t ) + ".py" for t in args .exclude .split (',' )]
258
- for exclude_test in tests_excl :
258
+ exclude_tests = [re .sub ("\.py$" , "" , test ) + ".py" for test in args .exclude .split (',' )]
259
+ for exclude_test in exclude_tests :
259
260
if exclude_test in test_list :
260
261
test_list .remove (exclude_test )
261
262
else :
@@ -320,7 +321,7 @@ def run_tests(test_list, src_dir, build_dir, exeext, tmpdir, jobs=1, enable_cove
320
321
321
322
#Run Tests
322
323
job_queue = TestHandler (jobs , tests_dir , tmpdir , test_list , flags )
323
- time0 = time .time ()
324
+ start_time = time .time ()
324
325
test_results = []
325
326
326
327
max_len_name = len (max (test_list , key = len ))
@@ -346,7 +347,7 @@ def run_tests(test_list, src_dir, build_dir, exeext, tmpdir, jobs=1, enable_cove
346
347
combined_logs , _ = subprocess .Popen ([sys .executable , os .path .join (tests_dir , 'combine_logs.py' ), '-c' , testdir ], universal_newlines = True , stdout = subprocess .PIPE ).communicate ()
347
348
print ("\n " .join (deque (combined_logs .splitlines (), combined_logs_len )))
348
349
349
- print_results (test_results , max_len_name , (int (time .time () - time0 )))
350
+ print_results (test_results , max_len_name , (int (time .time () - start_time )))
350
351
351
352
if coverage :
352
353
coverage .report_rpc_coverage ()
@@ -403,15 +404,15 @@ def get_next(self):
403
404
while self .num_running < self .num_jobs and self .test_list :
404
405
# Add tests
405
406
self .num_running += 1
406
- t = self .test_list .pop (0 )
407
+ test = self .test_list .pop (0 )
407
408
portseed = len (self .test_list ) + self .portseed_offset
408
409
portseed_arg = ["--portseed={}" .format (portseed )]
409
410
log_stdout = tempfile .SpooledTemporaryFile (max_size = 2 ** 16 )
410
411
log_stderr = tempfile .SpooledTemporaryFile (max_size = 2 ** 16 )
411
- test_argv = t .split ()
412
+ test_argv = test .split ()
412
413
testdir = "{}/{}_{}" .format (self .tmpdir , re .sub (".py$" , "" , test_argv [0 ]), portseed )
413
414
tmpdir_arg = ["--tmpdir={}" .format (testdir )]
414
- self .jobs .append ((t ,
415
+ self .jobs .append ((test ,
415
416
time .time (),
416
417
subprocess .Popen ([sys .executable , self .tests_dir + test_argv [0 ]] + test_argv [1 :] + self .flags + portseed_arg + tmpdir_arg ,
417
418
universal_newlines = True ,
@@ -425,15 +426,14 @@ def get_next(self):
425
426
while True :
426
427
# Return first proc that finishes
427
428
time .sleep (.5 )
428
- for j in self .jobs :
429
- (name , time0 , proc , testdir , log_out , log_err ) = j
430
- if os .getenv ('TRAVIS' ) == 'true' and int (time .time () - time0 ) > 20 * 60 :
431
- # In travis, timeout individual tests after 20 minutes (to stop tests hanging and not
432
- # providing useful output.
429
+ for job in self .jobs :
430
+ (name , start_time , proc , testdir , log_out , log_err ) = job
431
+ if os .getenv ('TRAVIS' ) == 'true' and int (time .time () - start_time ) > TRAVIS_TIMEOUT_DURATION :
432
+ # In travis, timeout individual tests (to stop tests hanging and not providing useful output).
433
433
proc .send_signal (signal .SIGINT )
434
434
if proc .poll () is not None :
435
435
log_out .seek (0 ), log_err .seek (0 )
436
- [stdout , stderr ] = [l .read ().decode ('utf-8' ) for l in (log_out , log_err )]
436
+ [stdout , stderr ] = [file .read ().decode ('utf-8' ) for file in (log_out , log_err )]
437
437
log_out .close (), log_err .close ()
438
438
if proc .returncode == TEST_EXIT_PASSED and stderr == "" :
439
439
status = "Passed"
@@ -442,9 +442,9 @@ def get_next(self):
442
442
else :
443
443
status = "Failed"
444
444
self .num_running -= 1
445
- self .jobs .remove (j )
445
+ self .jobs .remove (job )
446
446
447
- return TestResult (name , status , int (time .time () - time0 )), testdir , stdout , stderr
447
+ return TestResult (name , status , int (time .time () - start_time )), testdir , stdout , stderr
448
448
print ('.' , end = '' , flush = True )
449
449
450
450
class TestResult ():
@@ -490,7 +490,7 @@ def check_script_list(src_dir):
490
490
Check that there are no scripts in the functional tests directory which are
491
491
not being run by pull-tester.py."""
492
492
script_dir = src_dir + '/test/functional/'
493
- python_files = set ([t for t in os .listdir (script_dir ) if t [ - 3 :] == ".py" ])
493
+ python_files = set ([file for file in os .listdir (script_dir ) if file . endswith ( ".py" ) ])
494
494
missed_tests = list (python_files - set (map (lambda x : x .split ()[0 ], ALL_SCRIPTS + NON_SCRIPTS )))
495
495
if len (missed_tests ) != 0 :
496
496
print ("%sWARNING!%s The following scripts are not being run: %s. Check the test lists in test_runner.py." % (BOLD [1 ], BOLD [0 ], str (missed_tests )))
@@ -526,7 +526,7 @@ def report_rpc_coverage(self):
526
526
527
527
if uncovered :
528
528
print ("Uncovered RPC commands:" )
529
- print ("" .join ((" - %s\n " % i ) for i in sorted (uncovered )))
529
+ print ("" .join ((" - %s\n " % command ) for command in sorted (uncovered )))
530
530
else :
531
531
print ("All RPC commands covered." )
532
532
@@ -550,17 +550,17 @@ def _get_uncovered_rpc_commands(self):
550
550
if not os .path .isfile (coverage_ref_filename ):
551
551
raise RuntimeError ("No coverage reference found" )
552
552
553
- with open (coverage_ref_filename , 'r' ) as f :
554
- all_cmds .update ([i .strip () for i in f .readlines ()])
553
+ with open (coverage_ref_filename , 'r' ) as file :
554
+ all_cmds .update ([line .strip () for line in file .readlines ()])
555
555
556
556
for root , dirs , files in os .walk (self .dir ):
557
557
for filename in files :
558
558
if filename .startswith (coverage_file_prefix ):
559
559
coverage_filenames .add (os .path .join (root , filename ))
560
560
561
561
for filename in coverage_filenames :
562
- with open (filename , 'r' ) as f :
563
- covered_cmds .update ([i .strip () for i in f .readlines ()])
562
+ with open (filename , 'r' ) as file :
563
+ covered_cmds .update ([line .strip () for line in file .readlines ()])
564
564
565
565
return all_cmds - covered_cmds
566
566
0 commit comments