2424"""
2525A testing framework for the SCons software construction tool.
2626
27- A TestSCons environment object is created via the usual invocation :
27+ Create a TestSCons environment object by instantiating the class :
2828
29- test = TestSCons()
29+ import TestSCons
30+ test = TestSCons.TestSCons()
3031
31- TestScons is a subclass of TestCommon, which in turn is a subclass
32- of TestCmd), and hence has available all of the methods and attributes
33- from those classes, as well as any overridden or additional methods or
34- attributes defined in this subclass.
32+ :class:`TestScons' is a subclass of :class:`TestCommon,` which in turn
33+ is a subclass of :class:`TestCmd`, and hence has available all of the
34+ methods and attributes from those classes, as well as any overridden or
35+ additional methods or attributes defined in this subclass.
36+
37+ This class is further specialized for specific testing purposes in
38+ modules :mod:`TestSConsMSVS`, :mod:`TestSConsTar`, :mod:`TestSCons_time`,
39+ :mod:`TestSConsign` as well as in this file in :class:`TimeSCons`.
3540"""
3641
3742from __future__ import annotations
4752
4853from SCons .Util import get_hash_format , get_current_hash_algorithm_used
4954from TestCommon import *
50- from TestCommon import __all__ , _python_
55+ from TestCommon import __all__
5156
5257# Some tests which verify that SCons has been packaged properly need to
5358# look for specific version file names. Replicating the version number
@@ -146,7 +151,7 @@ def re_escape(str):
146151# Helper functions that we use as a replacement to the default re.match
147152# when searching for special strings in stdout/stderr.
148153#
149- def search_re (out , l ) :
154+ def search_re (out : str , l : str ) -> int | None :
150155 """Search the regular expression 'l' in the output 'out'
151156 and return the start index when successful.
152157 """
@@ -157,7 +162,7 @@ def search_re(out, l):
157162 return None
158163
159164
160- def search_re_in_list (out , l ) :
165+ def search_re_in_list (out : str , l : str ) -> int | None :
161166 """Search the regular expression 'l' in each line of
162167 the given string list 'out' and return the line's index
163168 when successful.
@@ -203,12 +208,20 @@ def deprecated_python_version(version=sys.version_info):
203208 deprecated_python_msg = ""
204209
205210
206- def initialize_sconsflags (ignore_python_version ):
207- """
208- Add the --warn=no-python-version option to SCONSFLAGS for every
209- command so test scripts don't have to filter out Python version
210- deprecation warnings.
211- Same for --warn=no-visual-c-missing.
211+ def initialize_sconsflags (ignore_python_version : bool ) -> str | None :
212+ """Set up SCONSFLAGS for every command.
213+
214+ Used so test scripts don't need to worry about unexpected warnings
215+ in their output.
216+
217+ ``--warn=no-python-version`` is used to suppress Python version
218+ deprecation warnings while such are active.
219+
220+ ``--warn=no-visual-c-missing`` is used so Windows systems which don't
221+ have Visual C++ installed don't get warnings about it.
222+
223+ Returns:
224+ the original ``SCONSFLAGS`` value, if any, so it can be restored
212225 """
213226 save_sconsflags = os .environ .get ('SCONSFLAGS' )
214227 if save_sconsflags :
@@ -229,7 +242,8 @@ def initialize_sconsflags(ignore_python_version):
229242 return save_sconsflags
230243
231244
232- def restore_sconsflags (sconsflags ) -> None :
245+ def restore_sconsflags (sconsflags : str | None ) -> None :
246+ """Restore the original SCONSFLAGS value, if any."""
233247 if sconsflags is None :
234248 del os .environ ['SCONSFLAGS' ]
235249 else :
@@ -249,18 +263,14 @@ def restore_sconsflags(sconsflags) -> None:
249263
250264
251265class NoMatch (Exception ):
252- """
253- Exception for matchPart to indicate there was no match found in the passed logfile
254- """
266+ """There was no match in the passed logfile."""
255267
256268 def __init__ (self , p ) -> None :
257269 self .pos = p
258270
259271
260272def match_part_of_configlog (log , logfile , lastEnd , NoMatch = NoMatch ):
261- """
262- Match part of the logfile
263- """
273+ """Match part of the logfile."""
264274 # print("Match:\n%s\n==============\n%s" % (log , logfile[lastEnd:]))
265275 m = re .match (log , logfile [lastEnd :])
266276 if not m :
@@ -368,8 +378,7 @@ def Environment(self, ENV=None, *args, **kw):
368378 return None
369379
370380 def detect (self , var , prog = None , ENV = None , norm = None ):
371- """
372- Return the detected path to a tool program.
381+ """Return the detected path to a tool program.
373382
374383 Searches first the named construction variable, then
375384 the SCons path.
@@ -401,7 +410,7 @@ def detect(self, var, prog=None, ENV=None, norm=None):
401410
402411 return self .where_is (prog )
403412
404- def detect_tool (self , tool , prog = None , ENV = None ):
413+ def detect_tool (self , tool , prog = None , ENV = None ) -> bool :
405414 """
406415 Given a tool (i.e., tool specification that would be passed
407416 to the "tools=" parameter of Environment()) and a program that
@@ -410,12 +419,11 @@ def detect_tool(self, tool, prog=None, ENV=None):
410419
411420 By default, prog is set to the value passed into the tools parameter.
412421 """
413-
414422 if not prog :
415423 prog = tool
416424 env = self .Environment (ENV , tools = [tool ])
417425 if env is None :
418- return None
426+ return False
419427 return env .Detect ([prog ])
420428
421429 def where_is (self , prog , path = None , pathext = None ):
@@ -476,8 +484,9 @@ def wrap_stdout(
476484 )
477485
478486 def run (self , * args , ** kw ) -> None :
479- """
480- Set up SCONSFLAGS for every command so test scripts don't need
487+ """Run a command.
488+
489+ Sets up ``SCONSFLAGS`` first so test scripts don't need
481490 to worry about unexpected warnings in their output.
482491 """
483492 sconsflags = initialize_sconsflags (self .ignore_python_version )
@@ -1810,9 +1819,8 @@ def venv_path():
18101819
18111820 return (python , incpath , libpath , libname + _lib )
18121821
1813- def start (self , * args , ** kw ):
1814- """
1815- Starts SCons in the test environment.
1822+ def start (self , * args , ** kw ) -> Popen :
1823+ """Starts SCons in the test environment.
18161824
18171825 This method exists to tell Test{Cmd,Common} that we're going to
18181826 use standard input without forcing every .start() call in the
0 commit comments