summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_frame.py
diff options
context:
space:
mode:
authorAntoine Pitrou <pitrou@free.fr>2017-12-31 21:35:22 (GMT)
committerGitHub <noreply@github.com>2017-12-31 21:35:22 (GMT)
commit14709144b521b9916f798a43aac9dc44fd44f6ca (patch)
treeda50e07a148af33b449d614687af504a09b45a9e /Lib/test/test_frame.py
parent0a37a30037073a4a9ba45e560c8445048e5f2ba2 (diff)
downloadcpython-14709144b521b9916f798a43aac9dc44fd44f6ca.zip
cpython-14709144b521b9916f798a43aac9dc44fd44f6ca.tar.gz
cpython-14709144b521b9916f798a43aac9dc44fd44f6ca.tar.bz2
bpo-32468: Better frame repr() (#5067)
bpo-32468: Better frame repr()
Diffstat (limited to 'Lib/test/test_frame.py')
-rw-r--r--Lib/test/test_frame.py41
1 files changed, 41 insertions, 0 deletions
diff --git a/Lib/test/test_frame.py b/Lib/test/test_frame.py
index cabfef2..fd79508 100644
--- a/Lib/test/test_frame.py
+++ b/Lib/test/test_frame.py
@@ -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()