summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2014-02-16 22:53:38 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2014-02-16 22:53:38 (GMT)
commita91ff1423fbd57e7bd0853ac494d8cdea1fb5bb9 (patch)
treeb8c65ceade43aeacb44551211d63be995e07a493 /Lib/test
parent34c15400092bba37ea36e155d151cfcbfa846db7 (diff)
downloadcpython-a91ff1423fbd57e7bd0853ac494d8cdea1fb5bb9.zip
cpython-a91ff1423fbd57e7bd0853ac494d8cdea1fb5bb9.tar.gz
cpython-a91ff1423fbd57e7bd0853ac494d8cdea1fb5bb9.tar.bz2
Issue #20616: Add a format() method to tracemalloc.Traceback.
Diffstat (limited to 'Lib/test')
-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 3d2333f..d1e5aef 100644
--- a/Lib/test/test_tracemalloc.py
+++ b/Lib/test/test_tracemalloc.py
@@ -510,6 +510,26 @@ class TestSnapshot(unittest.TestCase):
self.assertEqual(traceback[:2],
(traceback[0], traceback[1]))
+ def test_format_traceback(self):
+ snapshot, snapshot2 = create_snapshots()
+ def getline(filename, lineno):
+ return ' <%s, %s>' % (filename, lineno)
+ with unittest.mock.patch('tracemalloc.linecache.getline',
+ side_effect=getline):
+ tb = snapshot.traces[0].traceback
+ self.assertEqual(tb.format(),
+ [' File "a.py", line 2',
+ ' <a.py, 2>',
+ ' File "b.py", line 4',
+ ' <b.py, 4>'])
+
+ self.assertEqual(tb.format(limit=1),
+ [' File "a.py", line 2',
+ ' <a.py, 2>'])
+
+ self.assertEqual(tb.format(limit=-1),
+ [])
+
class TestFilters(unittest.TestCase):
maxDiff = 2048