1
- import locale
2
1
import os
3
- import platform
4
2
import random
5
3
import re
6
4
import sys
7
5
import time
8
- import unittest
9
6
10
7
from test import support
11
8
from test .support import os_helper
12
9
13
10
from .cmdline import _parse_args , Namespace
14
- from .findtests import findtests , split_test_packages
11
+ from .findtests import findtests , split_test_packages , list_cases
15
12
from .logger import Logger
16
13
from .result import State
17
14
from .runtests import RunTests , HuntRefleak
22
19
from .utils import (
23
20
StrPath , StrJSON , TestName , TestList , TestTuple , FilterTuple ,
24
21
strip_py_suffix , count , format_duration ,
25
- printlist , get_build_info , get_temp_dir , get_work_dir , exit_timeout ,
26
- abs_module_name )
22
+ printlist , get_temp_dir , get_work_dir , exit_timeout ,
23
+ display_header , cleanup_temp_dir )
27
24
28
25
29
26
class Regrtest :
@@ -214,36 +211,6 @@ def list_tests(tests: TestTuple):
214
211
for name in tests :
215
212
print (name )
216
213
217
- def _list_cases (self , suite ):
218
- for test in suite :
219
- if isinstance (test , unittest .loader ._FailedTest ):
220
- continue
221
- if isinstance (test , unittest .TestSuite ):
222
- self ._list_cases (test )
223
- elif isinstance (test , unittest .TestCase ):
224
- if support .match_test (test ):
225
- print (test .id ())
226
-
227
- def list_cases (self , tests : TestTuple ):
228
- support .verbose = False
229
- support .set_match_tests (self .match_tests , self .ignore_tests )
230
-
231
- skipped = []
232
- for test_name in tests :
233
- module_name = abs_module_name (test_name , self .test_dir )
234
- try :
235
- suite = unittest .defaultTestLoader .loadTestsFromName (module_name )
236
- self ._list_cases (suite )
237
- except unittest .SkipTest :
238
- skipped .append (test_name )
239
-
240
- if skipped :
241
- sys .stdout .flush ()
242
- stderr = sys .stderr
243
- print (file = stderr )
244
- print (count (len (skipped ), "test" ), "skipped:" , file = stderr )
245
- printlist (skipped , file = stderr )
246
-
247
214
def _rerun_failed_tests (self , runtests : RunTests ):
248
215
# Configure the runner to re-run tests
249
216
if self .num_workers == 0 :
@@ -363,45 +330,6 @@ def run_tests_sequentially(self, runtests):
363
330
364
331
return tracer
365
332
366
- @staticmethod
367
- def display_header ():
368
- # Print basic platform information
369
- print ("==" , platform .python_implementation (), * sys .version .split ())
370
- print ("==" , platform .platform (aliased = True ),
371
- "%s-endian" % sys .byteorder )
372
- print ("== Python build:" , ' ' .join (get_build_info ()))
373
- print ("== cwd:" , os .getcwd ())
374
- cpu_count = os .cpu_count ()
375
- if cpu_count :
376
- print ("== CPU count:" , cpu_count )
377
- print ("== encodings: locale=%s, FS=%s"
378
- % (locale .getencoding (), sys .getfilesystemencoding ()))
379
-
380
- # This makes it easier to remember what to set in your local
381
- # environment when trying to reproduce a sanitizer failure.
382
- asan = support .check_sanitizer (address = True )
383
- msan = support .check_sanitizer (memory = True )
384
- ubsan = support .check_sanitizer (ub = True )
385
- sanitizers = []
386
- if asan :
387
- sanitizers .append ("address" )
388
- if msan :
389
- sanitizers .append ("memory" )
390
- if ubsan :
391
- sanitizers .append ("undefined behavior" )
392
- if not sanitizers :
393
- return
394
-
395
- print (f"== sanitizers: { ', ' .join (sanitizers )} " )
396
- for sanitizer , env_var in (
397
- (asan , "ASAN_OPTIONS" ),
398
- (msan , "MSAN_OPTIONS" ),
399
- (ubsan , "UBSAN_OPTIONS" ),
400
- ):
401
- options = os .environ .get (env_var )
402
- if sanitizer and options is not None :
403
- print (f"== { env_var } ={ options !r} " )
404
-
405
333
def get_state (self ):
406
334
state = self .results .get_state (self .fail_env_changed )
407
335
if self .first_state :
@@ -445,20 +373,6 @@ def display_summary(self):
445
373
state = self .get_state ()
446
374
print (f"Result: { state } " )
447
375
448
- @staticmethod
449
- def cleanup_temp_dir (tmp_dir : StrPath ):
450
- import glob
451
-
452
- path = os .path .join (glob .escape (tmp_dir ), 'test_python_*' )
453
- print ("Cleanup %s directory" % tmp_dir )
454
- for name in glob .glob (path ):
455
- if os .path .isdir (name ):
456
- print ("Remove directory: %s" % name )
457
- os_helper .rmtree (name )
458
- else :
459
- print ("Remove file: %s" % name )
460
- os_helper .unlink (name )
461
-
462
376
def create_run_tests (self , tests : TestTuple ):
463
377
return RunTests (
464
378
tests ,
@@ -496,7 +410,7 @@ def _run_tests(self, selected: TestTuple, tests: TestList | None) -> int:
496
410
if (self .want_header
497
411
or not (self .pgo or self .quiet or self .single_test_run
498
412
or tests or self .cmdline_args )):
499
- self . display_header ()
413
+ display_header ()
500
414
501
415
if self .randomize :
502
416
print ("Using random seed" , self .random_seed )
@@ -554,7 +468,7 @@ def main(self, tests: TestList | None = None):
554
468
self .tmp_dir = get_temp_dir (self .tmp_dir )
555
469
556
470
if self .want_cleanup :
557
- self . cleanup_temp_dir (self .tmp_dir )
471
+ cleanup_temp_dir (self .tmp_dir )
558
472
sys .exit (0 )
559
473
560
474
if self .want_wait :
@@ -567,7 +481,10 @@ def main(self, tests: TestList | None = None):
567
481
if self .want_list_tests :
568
482
self .list_tests (selected )
569
483
elif self .want_list_cases :
570
- self .list_cases (selected )
484
+ list_cases (selected ,
485
+ match_tests = self .match_tests ,
486
+ ignore_tests = self .ignore_tests ,
487
+ test_dir = self .test_dir )
571
488
else :
572
489
exitcode = self .run_tests (selected , tests )
573
490
0 commit comments