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