10a8c90248264a8b26970b4473770bcc3df8515fJosh Gaoimport unittest
20a8c90248264a8b26970b4473770bcc3df8515fJosh Gaofrom test import test_support
30a8c90248264a8b26970b4473770bcc3df8515fJosh Gaoimport pstats
40a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
50a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
60a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
70a8c90248264a8b26970b4473770bcc3df8515fJosh Gaoclass AddCallersTestCase(unittest.TestCase):
80a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    """Tests for pstats.add_callers helper."""
90a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
100a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    def test_combine_results(self):
110a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        """pstats.add_callers should combine the call results of both target
120a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        and source by adding the call time. See issue1269."""
130a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        # new format: used by the cProfile module
140a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        target = {"a": (1, 2, 3, 4)}
150a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        source = {"a": (1, 2, 3, 4), "b": (5, 6, 7, 8)}
160a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        new_callers = pstats.add_callers(target, source)
170a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        self.assertEqual(new_callers, {'a': (2, 4, 6, 8), 'b': (5, 6, 7, 8)})
180a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        # old format: used by the profile module
190a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        target = {"a": 1}
200a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        source = {"a": 1, "b": 5}
210a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        new_callers = pstats.add_callers(target, source)
220a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        self.assertEqual(new_callers, {'a': 2, 'b': 5})
230a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
240a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
250a8c90248264a8b26970b4473770bcc3df8515fJosh Gaodef test_main():
260a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    test_support.run_unittest(
270a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        AddCallersTestCase
280a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    )
290a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
300a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
310a8c90248264a8b26970b4473770bcc3df8515fJosh Gaoif __name__ == "__main__":
320a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    test_main()
33