summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_traceback.py
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2013-04-29 20:09:39 (GMT)
committerBenjamin Peterson <benjamin@python.org>2013-04-29 20:09:39 (GMT)
commitd9fec15e9b0e31fb530ec4af270269068a8d69ea (patch)
tree02de38cf0928cdca01c9ccbcd7070b13b2403dd0 /Lib/test/test_traceback.py
parent0bb83f812f2a253d478c1a4f33e4b10685c5c5db (diff)
downloadcpython-d9fec15e9b0e31fb530ec4af270269068a8d69ea.zip
cpython-d9fec15e9b0e31fb530ec4af270269068a8d69ea.tar.gz
cpython-d9fec15e9b0e31fb530ec4af270269068a8d69ea.tar.bz2
refactor traceback.py to reduce code duplication (closes #17646)
Patch by Martin Morrison.
Diffstat (limited to 'Lib/test/test_traceback.py')
-rw-r--r--Lib/test/test_traceback.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/Lib/test/test_traceback.py b/Lib/test/test_traceback.py
index 5bce2af..24753a8 100644
--- a/Lib/test/test_traceback.py
+++ b/Lib/test/test_traceback.py
@@ -160,11 +160,26 @@ class TracebackFormatTests(unittest.TestCase):
file_ = StringIO()
traceback_print(tb, file_)
python_fmt = file_.getvalue()
+ # Call all _tb and _exc functions
+ with captured_output("stderr") as tbstderr:
+ traceback.print_tb(tb)
+ tbfile = StringIO()
+ traceback.print_tb(tb, file=tbfile)
+ with captured_output("stderr") as excstderr:
+ traceback.print_exc()
+ excfmt = traceback.format_exc()
+ excfile = StringIO()
+ traceback.print_exc(file=excfile)
else:
raise Error("unable to create test traceback string")
# Make sure that Python and the traceback module format the same thing
self.assertEqual(traceback_fmt, python_fmt)
+ # Now verify the _tb func output
+ self.assertEqual(tbstderr.getvalue(), tbfile.getvalue())
+ # Now verify the _exc func output
+ self.assertEqual(excstderr.getvalue(), excfile.getvalue())
+ self.assertEqual(excfmt, excfile.getvalue())
# Make sure that the traceback is properly indented.
tb_lines = python_fmt.splitlines()
@@ -174,6 +189,19 @@ class TracebackFormatTests(unittest.TestCase):
self.assertTrue(location.startswith(' File'))
self.assertTrue(source_line.startswith(' raise'))
+ def test_stack_format(self):
+ # Verify _stack functions. Note we have to use _getframe(1) to
+ # compare them without this frame appearing in the output
+ with captured_output("stderr") as ststderr:
+ traceback.print_stack(sys._getframe(1))
+ stfile = StringIO()
+ traceback.print_stack(sys._getframe(1), file=stfile)
+ self.assertEqual(ststderr.getvalue(), stfile.getvalue())
+
+ stfmt = traceback.format_stack(sys._getframe(1))
+
+ self.assertEqual(ststderr.getvalue(), "".join(stfmt))
+
cause_message = (
"\nThe above exception was the direct cause "