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