diff options
author | Benjamin Peterson <benjamin@python.org> | 2009-09-09 11:40:54 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2009-09-09 11:40:54 (GMT) |
commit | 8246968b1222b25352d1aade43336686dc388221 (patch) | |
tree | b5a6bcda00c91ace7a3123366e1ef53ae3ee8654 /Lib/test | |
parent | bed26a3ce371d5244898e1d160a3ca566aec4486 (diff) | |
download | cpython-8246968b1222b25352d1aade43336686dc388221.zip cpython-8246968b1222b25352d1aade43336686dc388221.tar.gz cpython-8246968b1222b25352d1aade43336686dc388221.tar.bz2 |
tabbify
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_traceback.py | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/Lib/test/test_traceback.py b/Lib/test/test_traceback.py index b29869a..d7dcbac 100644 --- a/Lib/test/test_traceback.py +++ b/Lib/test/test_traceback.py @@ -21,6 +21,50 @@ class TracebackCases(unittest.TestCase): else: raise ValueError, "call did not raise exception" + def test_tb_next(self): + def f(): + raise Exception + def g(): + f() + try: + g() + except Exception: + tb = sys.exc_info()[2] + self.assertEqual(tb.tb_frame.f_code.co_name, "test_tb_next") + g_tb = tb.tb_next + self.assertEqual(g_tb.tb_frame.f_code.co_name, "g") + f_tb = g_tb.tb_next + self.assertEqual(f_tb.tb_frame.f_code.co_name, "f") + self.assertIsNone(f_tb.tb_next) + tb.tb_next = None + self.assertIsNone(tb.tb_next) + self.assertRaises(ValueError, setattr, f_tb, "tb_next", g_tb) + self.assertRaises(TypeError, setattr, tb, "tb_next", 4) + g_tb.tb_next = None + f_tb.tb_next = g_tb + self.assertIs(f_tb.tb_next, g_tb) + self.assertRaises(ValueError, setattr, f_tb, "tb_next", f_tb) + self.assertRaises(TypeError, delattr, tb, "tb_next") + + def test_tb_frame(self): + def f(): + x = 2 + raise Exception + try: + f() + except Exception: + tb = sys.exc_info()[2] + self.assertIs(sys._getframe(), tb.tb_frame) + f_tb = tb.tb_next + self.assertEqual(f_tb.tb_frame.f_code.co_name, "f") + self.assertEqual(f_tb.tb_frame.f_locals["x"], 2) + f_tb.tb_frame = None + self.assertIsNone(f_tb.tb_frame) + self.assertRaises(TypeError, setattr, t_tb, "tb_frame", 4) + self.assertRaises(TypeError, delattr, t_tb, "tb_frame") + t_tb.tb_frame = sys._getframe() + self.assertIs(t_tb.tb_frame, tb.tb_frame) + def syntax_error_with_caret(self): compile("def fact(x):\n\treturn x!\n", "?", "exec") |