blob: 6ad9418deb282b887d7bfee7a42a9baff620b30d [file] [log] [blame]
Georg Brandl66e73632008-01-21 10:24:59 +00001import unittest
2from test import test_support
3import pstats
4
5
6
7class 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 Brandla2a92cf2010-08-02 17:34:58 +000013 # new format: used by the cProfile module
Georg Brandl66e73632008-01-21 10:24:59 +000014 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 Brandla2a92cf2010-08-02 17:34:58 +000018 # 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})
Georg Brandl66e73632008-01-21 10:24:59 +000023
24
25def test_main():
26 test_support.run_unittest(
27 AddCallersTestCase
28 )
29
30
31if __name__ == "__main__":
32 test_main()