diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2014-02-16 22:53:38 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2014-02-16 22:53:38 (GMT) |
commit | a91ff1423fbd57e7bd0853ac494d8cdea1fb5bb9 (patch) | |
tree | b8c65ceade43aeacb44551211d63be995e07a493 /Lib/test | |
parent | 34c15400092bba37ea36e155d151cfcbfa846db7 (diff) | |
download | cpython-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.py | 20 |
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 |