MCPcopy Index your code
hub / github.com/python/cpython / test_snapshot

Method test_snapshot

Lib/test/test_tracemalloc.py:308–331  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

306 self.assertTrue(tracemalloc.is_tracing())
307
308 def test_snapshot(self):
309 obj, source = allocate_bytes(123)
310
311 # take a snapshot
312 snapshot = tracemalloc.take_snapshot()
313
314 # This can vary
315 self.assertGreater(snapshot.traces[1].traceback.total_nframe, 10)
316
317 # write on disk
318 snapshot.dump(os_helper.TESTFN)
319 self.addCleanup(os_helper.unlink, os_helper.TESTFN)
320
321 # load from disk
322 snapshot2 = tracemalloc.Snapshot.load(os_helper.TESTFN)
323 self.assertEqual(snapshot2.traces, snapshot.traces)
324
325 # tracemalloc must be tracing memory allocations to take a snapshot
326 tracemalloc.stop()
327 with self.assertRaises(RuntimeError) as cm:
328 tracemalloc.take_snapshot()
329 self.assertEqual(str(cm.exception),
330 "the tracemalloc module must be tracing memory "
331 "allocations to take a snapshot")
332
333 def test_snapshot_save_attr(self):
334 # take a snapshot with a new attribute

Callers

nothing calls this directly

Calls 9

allocate_bytesFunction · 0.85
strFunction · 0.85
assertGreaterMethod · 0.80
addCleanupMethod · 0.80
dumpMethod · 0.45
loadMethod · 0.45
assertEqualMethod · 0.45
stopMethod · 0.45
assertRaisesMethod · 0.45

Tested by

no test coverage detected