mirror of
https://github.com/python/cpython.git
synced 2025-08-30 21:48:47 +00:00
parent
0a37a30037
commit
14709144b5
3 changed files with 52 additions and 1 deletions
|
@ -1,3 +1,4 @@
|
|||
import re
|
||||
import types
|
||||
import unittest
|
||||
import weakref
|
||||
|
@ -159,5 +160,45 @@ class FrameLocalsTest(unittest.TestCase):
|
|||
self.assertEqual(inner.f_locals, {})
|
||||
|
||||
|
||||
class ReprTest(unittest.TestCase):
|
||||
"""
|
||||
Tests for repr(frame).
|
||||
"""
|
||||
|
||||
def test_repr(self):
|
||||
def outer():
|
||||
x = 5
|
||||
y = 6
|
||||
def inner():
|
||||
z = x + 2
|
||||
1/0
|
||||
t = 9
|
||||
return inner()
|
||||
|
||||
offset = outer.__code__.co_firstlineno
|
||||
try:
|
||||
outer()
|
||||
except ZeroDivisionError as e:
|
||||
tb = e.__traceback__
|
||||
frames = []
|
||||
while tb:
|
||||
frames.append(tb.tb_frame)
|
||||
tb = tb.tb_next
|
||||
else:
|
||||
self.fail("should have raised")
|
||||
|
||||
f_this, f_outer, f_inner = frames
|
||||
file_repr = re.escape(repr(__file__))
|
||||
self.assertRegex(repr(f_this),
|
||||
r"^<frame at 0x[0-9a-fA-F]+, file %s, line %d, code test_repr>$"
|
||||
% (file_repr, offset + 23))
|
||||
self.assertRegex(repr(f_outer),
|
||||
r"^<frame at 0x[0-9a-fA-F]+, file %s, line %d, code outer>$"
|
||||
% (file_repr, offset + 7))
|
||||
self.assertRegex(repr(f_inner),
|
||||
r"^<frame at 0x[0-9a-fA-F]+, file %s, line %d, code inner>$"
|
||||
% (file_repr, offset + 5))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue