66#
77# The SCons test suite consists of:
88#
9- # - unit tests - included in *Tests.py files from src / dir
9+ # - unit tests - included in *Tests.py files from SCons / dir
1010# - end-to-end tests - these are *.py files in test/ directory that
1111# require custom SCons framework from testing/
1212#
1313# This script adds SCons/ and testing/ directories to PYTHONPATH,
1414# performs test discovery and processes them according to options.
15- #
16- # With -p (--package) option, script tests specified package from
17- # build directory and sets PYTHONPATH to reference modules unpacked
18- # during build process for testing purposes (build/test-*).
1915
2016"""
2117Options:
2218 -a --all Run all tests.
2319 -b --baseline BASE Run test scripts against baseline BASE.
24- --builddir DIR Directory in which packages were built.
2520 -d --debug Run test scripts under the Python debugger.
2621 -D --devmode Run tests in Python's development mode (3.7+ only)
2722 --e2e-only Run only the end-to-end tests
3833 chars! You might run into some deadlocks else.
3934 -o --output FILE Save the output from a test run to the log file.
4035 -P PYTHON Use the specified Python interpreter.
41- -p --package PACKAGE Test against the specified PACKAGE:
42- deb Debian
43- local-tar-gz .tar.gz standalone package
44- local-zip .zip standalone package
45- rpm Red Hat
46- src-tar-gz .tar.gz source package
47- src-zip .zip source package
48- tar-gz .tar.gz distribution
49- zip .zip distribution
5036 --passed Summarize which tests passed.
5137 -q --quiet Don't print the test being executed.
5238 --quit-on-failure Quit on any test failure.
8975cwd = os .getcwd ()
9076
9177baseline = None
92- builddir = os .path .join (cwd , 'build' )
9378external = 0
9479devmode = False
9580debug = ''
9681execute_tests = True
9782jobs = 1
9883list_only = False
9984printcommand = True
100- package = None
10185print_passed_summary = False
10286scons = None
10387scons_exec = False
10488testlistfile = None
10589version = ''
10690print_times = False
10791python = None
108- sp = []
10992print_progress = True
11093catch_output = False
11194suppress_output = False
@@ -156,7 +139,6 @@ def _process_short_opts(self, rargs, values):
156139 "b:dDef:hj:klnP:p:qsv:Xx:t" ,
157140 [
158141 "baseline=" ,
159- "builddir=" ,
160142 "debug" ,
161143 "devmode" ,
162144 "external" ,
@@ -167,7 +149,6 @@ def _process_short_opts(self, rargs, values):
167149 "list" ,
168150 "no-exec" ,
169151 "nopipefiles" ,
170- "package=" ,
171152 "passed" ,
172153 "python=" ,
173154 "quiet" ,
@@ -186,10 +167,6 @@ def _process_short_opts(self, rargs, values):
186167for o , a in opts :
187168 if o in ['-b' , '--baseline' ]:
188169 baseline = a
189- elif o in ['--builddir' ]:
190- builddir = a
191- if not os .path .isabs (builddir ):
192- builddir = os .path .normpath (os .path .join (cwd , builddir ))
193170 elif o in ['-d' , '--debug' ]:
194171 for d in sys .path :
195172 pdb = os .path .join (d , 'pdb.py' )
@@ -220,8 +197,6 @@ def _process_short_opts(self, rargs, values):
220197 execute_tests = False
221198 elif o in ['--nopipefiles' ]:
222199 allow_pipe_files = False
223- elif o in ['-p' , '--package' ]:
224- package = a
225200 elif o in ['--passed' ]:
226201 print_passed_summary = True
227202 elif o in ['-P' , '--python' ]:
@@ -252,7 +227,7 @@ def _process_short_opts(self, rargs, values):
252227 unit_only = True
253228
254229
255- class Unbuffered () :
230+ class Unbuffered :
256231 """ class to arrange for stdout/stderr to be unbuffered """
257232 def __init__ (self , file ):
258233 self .file = file
@@ -270,7 +245,7 @@ def __getattr__(self, attr):
270245
271246if options .output :
272247 logfile = open (options .output , 'w' )
273- class Tee () :
248+ class Tee :
274249 def __init__ (self , openfile , stream ):
275250 self .file = openfile
276251 self .stream = stream
@@ -305,13 +280,9 @@ def whereis(file):
305280 return f
306281 return None
307282
308- sp .append (builddir )
309- sp .append (cwd )
310283
311- #
312284_ws = re .compile (r'\s' )
313285
314-
315286def escape (s ):
316287 if _ws .search (s ):
317288 s = '"' + s + '"'
@@ -423,7 +394,7 @@ class PopenExecutor(RuntestBase):
423394 by calling subprocess.run (behind the covers uses Popen.
424395 Very similar to SystemExecutor, but uses command_str
425396 instead of command_args, and doesn't allow for not catching
426- the output.
397+ the output) .
427398 """
428399 # For an explanation of the following 'if ... else'
429400 # and the 'allow_pipe_files' option, please check out the
@@ -571,25 +542,29 @@ def footer(self, f):
571542#
572543# Each test path, whichever of the three sources it comes from,
573544# specifies either a test file or a directory to search for
574- # SCons tests. SCons code layout assumes that any file under the 'src '
545+ # SCons tests. SCons code layout assumes that any file under the 'SCons '
575546# subdirectory that ends with 'Tests.py' is a unit test, and any Python
576547# script (*.py) under the 'test' subdirectory is an end-to-end test.
577548# We need to track these because they are invoked differently.
578549# find_unit_tests and find_e2e_tests are used for this searching.
579550#
580- # Note that there are some tests under 'src ' that *begin* with
551+ # Note that there are some tests under 'SCons ' that *begin* with
581552# 'test_', but they're packaging and installation tests, not
582553# functional tests, so we don't execute them by default. (They can
583554# still be executed by hand, though).
584555#
585556# Test exclusions, if specified, are then applied.
586557
587- tests = []
588- excludetests = []
589558unittests = []
590559endtests = []
591560
592561
562+ def scanlist (testlist ):
563+ """Process a testlist file"""
564+ tests = [t .strip () for t in testlist if not t .startswith ('#' )]
565+ return [t for t in tests if t ]
566+
567+
593568def find_unit_tests (directory ):
594569 """ Look for unit tests """
595570 result = []
@@ -613,7 +588,7 @@ def find_e2e_tests(directory):
613588 continue
614589 try :
615590 with open (os .path .join (dirpath , ".exclude_tests" )) as f :
616- excludes = [ e . split ( "#" , 1 )[ 0 ]. strip () for e in f . readlines ()]
591+ excludes = scanlist ( f )
617592 except EnvironmentError :
618593 excludes = []
619594 for fname in filenames :
@@ -622,10 +597,10 @@ def find_e2e_tests(directory):
622597 return sorted (result )
623598
624599
600+ # initial selection:
625601if testlistfile :
626602 with open (testlistfile , 'r' ) as f :
627- tests = [x [:- 1 ].strip () for x in f if not x .startswith ('#' )]
628- tests = [x for x in tests if x ]
603+ tests = scanlist (f )
629604else :
630605 testpaths = []
631606 if options .all :
@@ -644,41 +619,37 @@ def find_e2e_tests(directory):
644619 # sys.stderr.write("to:%s\n"%tp)
645620 for path in glob .glob (tp ):
646621 if os .path .isdir (path ):
647- if path .startswith (('SCons' , 'testing' )) and not e2e_only :
648- for p in find_unit_tests (path ):
649- unittests .append (p )
650- elif path .startswith ('test' ) and not unit_only :
651- for p in find_e2e_tests (path ):
652- endtests .append (p )
622+ if path .startswith (('SCons' , 'testing' )):
623+ unittests .extend (find_unit_tests (path ))
624+ elif path .startswith ('test' ):
625+ endtests .extend (find_e2e_tests (path ))
653626 else :
654- if path .endswith ("Tests.py" ) and not e2e_only :
627+ if path .endswith ("Tests.py" ):
655628 unittests .append (path )
656- else :
657- if not unit_only :
658- endtests .append (path )
659-
660- tests .extend (unittests )
661- tests .extend (endtests )
662- tests .sort ()
629+ elif path .endswith (".py" ):
630+ endtests .append (path )
631+ tests = unittests + endtests
632+
633+ # Remove exclusions:
634+ if e2e_only :
635+ tests = [t for t in tests if not t .endswith ("Tests.py" )]
636+ if unit_only :
637+ tests = [t for t in tests if t .endswith ("Tests.py" )]
638+ if excludelistfile :
639+ with open (excludelistfile , 'r' ) as f :
640+ excludetests = scanlist (f )
641+ tests = [t for t in tests if t not in excludetests ]
663642
664643if not tests :
665644 sys .stderr .write (usagestr + """
666- runtest.py: No tests were found.
667- Tests can be specified on the command line, read from file
668- with -f option, or discovered with -a to run all tests.
645+ runtest: no tests were found.
646+ Tests can be specified on the command line, read from a file with
647+ the -f/--file option, or discovered with -a/--all to run all tests.
669648""" )
670649 sys .exit (1 )
671650
672- if excludelistfile :
673- with open (excludelistfile , 'r' ) as f :
674- excludetests = f .readlines ()
675- excludetests = [x for x in excludetests if x [0 ] != '#' ]
676- excludetests = [x [:- 1 ] for x in excludetests ]
677- excludetests = [x .strip () for x in excludetests ]
678- excludetests = [x for x in excludetests if x ]
679651
680652# ---[ test processing ]-----------------------------------
681- tests = [t for t in tests if t not in excludetests ]
682653tests = [Test (t , n + 1 ) for n , t in enumerate (tests )]
683654
684655if list_only :
0 commit comments