Christian Heimes | e1c9811 | 2008-01-21 11:20:28 +0000 | [diff] [blame] | 1 | import unittest |
Benjamin Peterson | ee8712c | 2008-05-20 21:35:26 +0000 | [diff] [blame] | 2 | from test import support |
Christian Heimes | e1c9811 | 2008-01-21 11:20:28 +0000 | [diff] [blame] | 3 | import pstats |
| 4 | |
| 5 | |
| 6 | |
| 7 | class AddCallersTestCase(unittest.TestCase): |
| 8 | """Tests for pstats.add_callers helper.""" |
| 9 | |
| 10 | def test_combine_results(self): |
| 11 | """pstats.add_callers should combine the call results of both target |
| 12 | and source by adding the call time. See issue1269.""" |
Georg Brandl | 2d3c4e7 | 2010-08-02 17:24:49 +0000 | [diff] [blame] | 13 | # new format: used by the cProfile module |
Christian Heimes | e1c9811 | 2008-01-21 11:20:28 +0000 | [diff] [blame] | 14 | target = {"a": (1, 2, 3, 4)} |
| 15 | source = {"a": (1, 2, 3, 4), "b": (5, 6, 7, 8)} |
| 16 | new_callers = pstats.add_callers(target, source) |
| 17 | self.assertEqual(new_callers, {'a': (2, 4, 6, 8), 'b': (5, 6, 7, 8)}) |
Georg Brandl | 2d3c4e7 | 2010-08-02 17:24:49 +0000 | [diff] [blame] | 18 | # old format: used by the profile module |
| 19 | target = {"a": 1} |
| 20 | source = {"a": 1, "b": 5} |
| 21 | new_callers = pstats.add_callers(target, source) |
| 22 | self.assertEqual(new_callers, {'a': 2, 'b': 5}) |
Christian Heimes | e1c9811 | 2008-01-21 11:20:28 +0000 | [diff] [blame] | 23 | |
| 24 | |
| 25 | def test_main(): |
Benjamin Peterson | ee8712c | 2008-05-20 21:35:26 +0000 | [diff] [blame] | 26 | support.run_unittest( |
Christian Heimes | e1c9811 | 2008-01-21 11:20:28 +0000 | [diff] [blame] | 27 | AddCallersTestCase |
| 28 | ) |
| 29 | |
| 30 | |
| 31 | if __name__ == "__main__": |
| 32 | test_main() |