diff --git a/Lib/test/test_faulthandler.py b/Lib/test/test_faulthandler.py --- a/Lib/test/test_faulthandler.py +++ b/Lib/test/test_faulthandler.py @@ -10,6 +10,7 @@ from test.script_helper import assert_python_ok import tempfile import unittest +from textwrap import dedent try: import threading @@ -51,6 +52,7 @@ build, and replace "Current thread 0x00007f8d8fbd9700" by "Current thread XXX". """ + code = dedent(code).strip() with support.SuppressCrashReport(): process = script_helper.spawn_python('-c', code) stdout, stderr = process.communicate() @@ -84,11 +86,11 @@ {header}: File "", line {lineno} in -""".strip() - regex = regex.format( + """ + regex = dedent(regex.format( lineno=line_number, name=name_regex, - header=re.escape(header)) + header=re.escape(header))).strip() if other_regex: regex += '|' + other_regex output, exitcode = self.get_output(code, filename) @@ -103,7 +105,7 @@ import faulthandler faulthandler.enable() faulthandler._read_null() -""".strip(), + """, 3, # Issue #12700: Read NULL raises SIGILL on Mac OS X Lion '(?:Segmentation fault|Bus error|Illegal instruction)') @@ -113,7 +115,7 @@ import faulthandler faulthandler.enable() faulthandler._sigsegv() -""".strip(), + """, 3, 'Segmentation fault') @@ -122,7 +124,7 @@ import faulthandler faulthandler.enable() faulthandler._sigabrt() -""".strip(), + """, 3, 'Aborted') @@ -133,7 +135,7 @@ import faulthandler faulthandler.enable() faulthandler._sigfpe() -""".strip(), + """, 3, 'Floating point exception') @@ -147,7 +149,7 @@ faulthandler.enable() _testcapi.raise_signal(signal.SIGBUS) -""".strip(), + """, 6, 'Bus error') @@ -161,7 +163,7 @@ faulthandler.enable() _testcapi.raise_signal(signal.SIGILL) -""".strip(), + """, 6, 'Illegal instruction') @@ -169,7 +171,7 @@ self.check_fatal_error(""" import faulthandler faulthandler._fatal_error(b'xyz') -""".strip(), + """, 2, 'xyz') @@ -183,7 +185,7 @@ import faulthandler faulthandler.enable() faulthandler._stack_overflow() -""".strip(), + """, 3, '(?:Segmentation fault|Bus error)', other_regex='unable to raise a stack overflow') @@ -193,7 +195,7 @@ import faulthandler faulthandler.enable() faulthandler._read_null(True) -""".strip(), + """, 3, '(?:Segmentation fault|Bus error|Illegal instruction)') @@ -204,7 +206,7 @@ output = open({filename}, 'wb') faulthandler.enable(output) faulthandler._sigsegv() -""".strip().format(filename=repr(filename)), + """.format(filename=repr(filename)), 4, 'Segmentation fault', filename=filename) @@ -214,7 +216,7 @@ import faulthandler faulthandler.enable(all_threads=False) faulthandler._sigsegv() -""".strip(), + """, 3, 'Segmentation fault', all_threads=False) @@ -225,7 +227,7 @@ faulthandler.enable() faulthandler.disable() faulthandler._sigsegv() -""".strip() + """ not_expected = 'Fatal Python error' stderr, exitcode = self.get_output(code) stder = '\n'.join(stderr) @@ -306,7 +308,7 @@ funcB() funcA() -""".strip() + """ code = code.format( filename=repr(filename), has_filename=bool(filename), @@ -343,7 +345,7 @@ faulthandler.dump_traceback(all_threads=False) {func_name}() -""".strip() + """ code = code.format( func_name=func_name, ) @@ -393,7 +395,7 @@ dump() waiter.stop.set() waiter.join() -""".strip() + """ code = code.format(filename=repr(filename)) output, exitcode = self.get_output(code, filename) output = '\n'.join(output) @@ -411,8 +413,8 @@ Current thread XXX \(most recent call first\): File "", line {lineno} in dump File "", line 28 in $ -""".strip() - regex = regex.format(lineno=lineno) + """ + regex = dedent(regex.format(lineno=lineno)).strip() self.assertRegex(output, regex) self.assertEqual(exitcode, 0) @@ -455,7 +457,7 @@ func(timeout, repeat, cancel, file, loops) if file is not None: file.close() -""".strip() + """ code = code.format( timeout=TIMEOUT, repeat=repeat, @@ -560,7 +562,7 @@ if file is not None: file.close() sys.exit(exitcode) -""".strip() + """ code = code.format( filename=repr(filename), has_filename=bool(filename),