Skip to content

Commit 630184b

Browse files
committed
Back off test framework exception handling
The try block in TestCmd.start() is removed, it interferes with other things. TestCommon.start is supposed to handle exceptions, so inserting more stuff at a lower level (parent class) made a mess of the framework tests. Clean up a complaint with later Pythons (3.12+), and include (incomplete) new regex for Python 3.13+. Signed-off-by: Mats Wichmann <[email protected]>
1 parent 049d82a commit 630184b

File tree

6 files changed

+49
-27
lines changed

6 files changed

+49
-27
lines changed

CHANGES.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ RELEASE VERSION/DATE TO BE FILLED IN LATER
3434
tweak for how it's handled (should be more accurate in a few situations).
3535
- Test framework now uses a subdirectory named "scons" below the base
3636
temporary directory. This gives something invariant to tell antivirus
37-
software to ignore without having to exclude the tmpdir itself.
37+
to ignore without having to exclude tmpdir itself. Fixes #4509.
3838
- MSVS "live" tests of project files adjusted to look for the generated
3939
executable with an exe sufffix
4040

RELEASE.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,7 @@ IMPROVEMENTS
5050

5151
- Make the testing framework a little more resilient: the temporary
5252
directory for tests now includes a component named "scons" which can
53-
be given to antivirus software to exclude; tests which are aborted
54-
before startup by the operating system now generate a proper FAILED
55-
message and are recorded in the fails list.
53+
be given to antivirus software to exclude.
5654

5755
PACKAGING
5856
---------

testing/framework/TestCmd.py

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1543,23 +1543,12 @@ def start(self, program=None,
15431543
# It seems that all pythons up to py3.6 still set text mode if you set encoding.
15441544
# TODO: File enhancement request on python to propagate universal_newlines even
15451545
# if encoding is set.hg c
1546-
#
1547-
# Windows can fail the subprocess call itself (via exception), rather
1548-
# than having subprocess.Popen report failure - antivirus hit is an
1549-
# example. Catch this and report it up as a test fail, as it gets
1550-
# missed easily otherwise. "Failed to run the test" should ostensibly
1551-
# be a No Result, but in this case, let's behave diffferently.
1552-
try:
1553-
p = Popen(
1554-
cmd,
1555-
stdin=stdin,
1556-
stdout=PIPE,
1557-
stderr=stderr_value,
1558-
env=os.environ,
1559-
universal_newlines=False,
1560-
)
1561-
except OSError as e:
1562-
self.fail_test(message=repr(e))
1546+
p = Popen(cmd,
1547+
stdin=stdin,
1548+
stdout=PIPE,
1549+
stderr=stderr_value,
1550+
env=os.environ,
1551+
universal_newlines=False)
15631552

15641553
self.process = p
15651554
return p
@@ -1637,11 +1626,11 @@ def run(self, program=None,
16371626
Output and error output are saved for future retrieval via
16381627
the stdout() and stderr() methods.
16391628
1640-
The specified program will have the original directory
1629+
The specified *program* will have the original directory
16411630
prepended unless it is enclosed in a [list].
16421631
1643-
arguments: if a dict() then will create arguments with KEY+VALUE for
1644-
each entry in the dict.
1632+
If *arguments* is a dict then will create arguments with KEY+VALUE
1633+
for each entry in the dict.
16451634
"""
16461635
if self.external:
16471636
if not program:

testing/framework/TestCmdTests.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2605,6 +2605,7 @@ def test_send(self) -> None:
26052605
expect = f"script_recv: {input}"
26062606
assert result == expect, f"Result:[{result}] should match\nExpected:[{expect}]"
26072607

2608+
# TODO: Python 3.6+ ResourceWarning: unclosed file <_io.BufferedReader name=9>
26082609
p = test.start(stdin=1)
26092610
input = 'send() input to the receive script\n'
26102611
p.send(input)

testing/framework/TestCommonTests.py

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -810,7 +810,11 @@ def re_search(output, line):
810810
stdout = run_env.stdout()
811811
assert stdout == "", stdout
812812
stderr = run_env.stderr()
813-
assert stderr == "PASSED\n", stderr
813+
# Somehow, this fails on Py 3.12+ with:
814+
# AssertionError: <stdin>:13: SyntaxWarning: invalid escape sequence '\ '
815+
# assert stderr == "PASSED\n", stderr
816+
# So, just look for a substring:
817+
self.assertIn("PASSED", stderr)
814818

815819
def test_title(self) -> None:
816820
"""Test must_contain_exactly_lines(): title"""
@@ -1952,6 +1956,36 @@ def raise_exception(*args, **kw):
19521956
""")
19531957
expect_stderr = re.compile(expect_stderr, re.M)
19541958

1959+
# TODO: Python 3.13+ expanded error msgs again. This doesn't work yet.
1960+
expect_enhanced_stderr = lstrip(
1961+
fr"""Exception trying to execute: \[{re.escape(repr(sys.executable))}, '[^']*pass'\]
1962+
Traceback (most recent call last):
1963+
File "<stdin>", line \d+, in (\?|<module>)
1964+
File "[^"]+TestCommon.py", line \d+, in run
1965+
super\(\).run\(\*\*kw\)
1966+
~~~~~~~~~~~^^^^^^
1967+
File "[^"]+TestCmd.py", line \d+, in run
1968+
p = self.start\(program=program,
1969+
~~~~~~~~~~^^^^^^^^^^^^^^^^^
1970+
interpreter=interpreter,
1971+
^^^^^^^^^^^^^^^^^^^^^^^^
1972+
...<2 lines>...
1973+
timeout=timeout,
1974+
^^^^^^^^^^^^^^^^
1975+
stdin=stdin\)
1976+
^^^^^^^^^^^^
1977+
(?:\s*\^*\s)? File \"[^\"]+TestCommon.py\", line \d+, in start
1978+
raise e
1979+
File "[^"]+TestCommon.py", line \d+, in start
1980+
return super\(\).start\(program, interpreter, arguments,
1981+
~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1982+
universal_newlines, \*\*kw\)
1983+
^^^^^^^^^^^^^^^^^^^^^^^^^
1984+
(?:\s*\^*\s)? File \"<stdin>\", line \d+, in raise_exception
1985+
TypeError: forced TypeError
1986+
""")
1987+
expect_enhanced_stderr = re.compile(expect_enhanced_stderr, re.M)
1988+
19551989
self.run_execution_test(script, expect_stdout, expect_stderr)
19561990

19571991
def test_ignore_stderr(self) -> None:

testing/framework/TestSCons.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1288,7 +1288,7 @@ def checkConfigureLogAndStdout(self, checks,
12881288
logfile.find("scons: warning: The stored build information has an unexpected class.") >= 0):
12891289
self.fail_test()
12901290

1291-
log = r'file\ \S*%s\,line \d+:' % re.escape(sconstruct) + ls
1291+
log = r'file \S*%s\,line \d+:' % re.escape(sconstruct) + ls
12921292
if doCheckLog:
12931293
lastEnd = match_part_of_configlog(log, logfile, lastEnd)
12941294

@@ -1426,7 +1426,7 @@ def checkLogAndStdout(self, checks, results, cached,
14261426
sconf_dir = sconf_dir
14271427
sconstruct = sconstruct
14281428

1429-
log = r'file\ \S*%s\,line \d+:' % re.escape(sconstruct) + ls
1429+
log = r'file \S*%s\,line \d+:' % re.escape(sconstruct) + ls
14301430
if doCheckLog:
14311431
lastEnd = match_part_of_configlog(log, logfile, lastEnd)
14321432

0 commit comments

Comments
 (0)