summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2015-09-18 07:07:18 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2015-09-18 07:07:18 (GMT)
commite3bcbd2bbade81a3591d69f607e1722c6016a489 (patch)
tree7dd1e18421cbce553038cf0285ac1c1bb02e571d /Lib/test
parent2a5f9da56cbdecd487965e7e08988d5d2af28cae (diff)
downloadcpython-e3bcbd2bbade81a3591d69f607e1722c6016a489.zip
cpython-e3bcbd2bbade81a3591d69f607e1722c6016a489.tar.gz
cpython-e3bcbd2bbade81a3591d69f607e1722c6016a489.tar.bz2
Issue #25108: Backported tests for traceback functions print_stack(),
format_stack(), and extract_stack() called without arguments.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_traceback.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/Lib/test/test_traceback.py b/Lib/test/test_traceback.py
index c295563..d6c9df2 100644
--- a/Lib/test/test_traceback.py
+++ b/Lib/test/test_traceback.py
@@ -242,6 +242,31 @@ class TracebackFormatTests(unittest.TestCase):
self.assertEqual(ststderr.getvalue(), "".join(stfmt))
+ def test_print_stack(self):
+ def prn():
+ traceback.print_stack()
+ with captured_output("stderr") as stderr:
+ prn()
+ lineno = prn.__code__.co_firstlineno
+ self.assertEqual(stderr.getvalue().splitlines()[-4:], [
+ ' File "%s", line %d, in test_print_stack' % (__file__, lineno+3),
+ ' prn()',
+ ' File "%s", line %d, in prn' % (__file__, lineno+1),
+ ' traceback.print_stack()',
+ ])
+
+ def test_format_stack(self):
+ def fmt():
+ return traceback.format_stack()
+ result = fmt()
+ lineno = fmt.__code__.co_firstlineno
+ self.assertEqual(result[-2:], [
+ ' File "%s", line %d, in test_format_stack\n'
+ ' result = fmt()\n' % (__file__, lineno+2),
+ ' File "%s", line %d, in fmt\n'
+ ' return traceback.format_stack()\n' % (__file__, lineno+1),
+ ])
+
cause_message = (
"\nThe above exception was the direct cause "
@@ -443,6 +468,16 @@ class MiscTracebackCases(unittest.TestCase):
# Local variable dict should now be empty.
self.assertEqual(len(inner_frame.f_locals), 0)
+ def test_extract_stack(self):
+ def extract():
+ return traceback.extract_stack()
+ result = extract()
+ lineno = extract.__code__.co_firstlineno
+ self.assertEqual(result[-2:], [
+ (__file__, lineno+2, 'test_extract_stack', 'result = extract()'),
+ (__file__, lineno+1, 'extract', 'return traceback.extract_stack()'),
+ ])
+
def test_main():
run_unittest(__name__)