ยปCore Development>Code coverage>Lib/test/test_pstats.py

Python code coverage for Lib/test/test_pstats.py

#countcontent
1n/aimport unittest
2n/afrom test import support
3n/afrom io import StringIO
4n/aimport pstats
5n/a
6n/a
7n/a
8n/aclass AddCallersTestCase(unittest.TestCase):
9n/a """Tests for pstats.add_callers helper."""
10n/a
11n/a def test_combine_results(self):
12n/a # pstats.add_callers should combine the call results of both target
13n/a # and source by adding the call time. See issue1269.
14n/a # new format: used by the cProfile module
15n/a target = {"a": (1, 2, 3, 4)}
16n/a source = {"a": (1, 2, 3, 4), "b": (5, 6, 7, 8)}
17n/a new_callers = pstats.add_callers(target, source)
18n/a self.assertEqual(new_callers, {'a': (2, 4, 6, 8), 'b': (5, 6, 7, 8)})
19n/a # old format: used by the profile module
20n/a target = {"a": 1}
21n/a source = {"a": 1, "b": 5}
22n/a new_callers = pstats.add_callers(target, source)
23n/a self.assertEqual(new_callers, {'a': 2, 'b': 5})
24n/a
25n/a
26n/aclass StatsTestCase(unittest.TestCase):
27n/a def setUp(self):
28n/a stats_file = support.findfile('pstats.pck')
29n/a self.stats = pstats.Stats(stats_file)
30n/a
31n/a def test_add(self):
32n/a stream = StringIO()
33n/a stats = pstats.Stats(stream=stream)
34n/a stats.add(self.stats, self.stats)
35n/a
36n/a
37n/aif __name__ == "__main__":
38n/a unittest.main()