[Python-checkins] cpython: Issue #15463: Write a test for faulthandler truncating the name of functions

victor.stinner python-checkins at python.org
Wed Aug 1 19:49:38 CEST 2012


http://hg.python.org/cpython/rev/6e03f9b72c61
changeset:   78373:6e03f9b72c61
user:        Victor Stinner <victor.stinner at gmail.com>
date:        Wed Aug 01 19:45:34 2012 +0200
summary:
  Issue #15463: Write a test for faulthandler truncating the name of functions
to 500 characters.

files:
  Lib/test/test_faulthandler.py |  24 +++++++++++++++++++++++
  1 files changed, 24 insertions(+), 0 deletions(-)


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
@@ -316,6 +316,30 @@
         with temporary_filename() as filename:
             self.check_dump_traceback(filename)
 
+    def test_truncate(self):
+        maxlen = 500
+        func_name = 'x' * (maxlen + 50)
+        truncated = 'x' * maxlen + '...'
+        code = """
+import faulthandler
+
+def {func_name}():
+    faulthandler.dump_traceback(all_threads=False)
+
+{func_name}()
+""".strip()
+        code = code.format(
+            func_name=func_name,
+        )
+        expected = [
+            'Traceback (most recent call first):',
+            '  File "<string>", line 4 in %s' % truncated,
+            '  File "<string>", line 6 in <module>'
+        ]
+        trace, exitcode = self.get_output(code)
+        self.assertEqual(trace, expected)
+        self.assertEqual(exitcode, 0)
+
     @unittest.skipIf(not HAVE_THREADS, 'need threads')
     def check_dump_traceback_threads(self, filename):
         """

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list