summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_tracemalloc.py
diff options
context:
space:
mode:
authorDaniel Hahler <git@thequod.de>2020-12-16 21:38:32 (GMT)
committerGitHub <noreply@github.com>2020-12-16 21:38:32 (GMT)
commit051b9818671625d125dee8198e0d2af5ad4c85b8 (patch)
tree472f877a688381cdd95312919c1920f7d4fd6448 /Lib/test/test_tracemalloc.py
parent66d3b589c44fcbcf9afe1e442d9beac3bd8bcd34 (diff)
downloadcpython-051b9818671625d125dee8198e0d2af5ad4c85b8.zip
cpython-051b9818671625d125dee8198e0d2af5ad4c85b8.tar.gz
cpython-051b9818671625d125dee8198e0d2af5ad4c85b8.tar.bz2
bpo-37961: Fix regression in tracemalloc.Traceback.__repr__ (GH-23805)
Regression in 8d59eb1b66c51b2b918da9881c57d07d08df43b7.
Diffstat (limited to 'Lib/test/test_tracemalloc.py')
-rw-r--r--Lib/test/test_tracemalloc.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/Lib/test/test_tracemalloc.py b/Lib/test/test_tracemalloc.py
index a0037f8..5566567 100644
--- a/Lib/test/test_tracemalloc.py
+++ b/Lib/test/test_tracemalloc.py
@@ -85,6 +85,25 @@ def traceback_filename(filename):
return traceback_lineno(filename, 0)
+class TestTraceback(unittest.TestCase):
+ def test_repr(self):
+ def get_repr(*args) -> str:
+ return repr(tracemalloc.Traceback(*args))
+
+ self.assertEqual(get_repr(()), "<Traceback ()>")
+ self.assertEqual(get_repr((), 0), "<Traceback () total_nframe=0>")
+
+ frames = (("f1", 1), ("f2", 2))
+ exp_repr_frames = (
+ "(<Frame filename='f2' lineno=2>,"
+ " <Frame filename='f1' lineno=1>)"
+ )
+ self.assertEqual(get_repr(frames),
+ f"<Traceback {exp_repr_frames}>")
+ self.assertEqual(get_repr(frames, 2),
+ f"<Traceback {exp_repr_frames} total_nframe=2>")
+
+
class TestTracemallocEnabled(unittest.TestCase):
def setUp(self):
if tracemalloc.is_tracing():
@@ -1065,6 +1084,7 @@ class TestCAPI(unittest.TestCase):
def test_main():
support.run_unittest(
+ TestTraceback,
TestTracemallocEnabled,
TestSnapshot,
TestFilters,