@@ -16,7 +16,9 @@ class ProfileTest(unittest.TestCase):
1616
1717 profilerclass = profile .Profile
1818 methodnames = ['print_stats' , 'print_callers' , 'print_callees' ]
19- expected_output = {}
19+
20+ def get_expected_output (self ):
21+ return _ProfileOutput
2022
2123 @classmethod
2224 def do_profiling (cls ):
@@ -41,14 +43,15 @@ def do_profiling(cls):
4143
4244 def test_cprofile (self ):
4345 results = self .do_profiling ()
46+ expected = self .get_expected_output ()
4447 self .assertEqual (results [0 ], 1000 )
4548 for i , method in enumerate (self .methodnames ):
46- if results [i + 1 ] != self . expected_output [method ]:
49+ if results [i + 1 ] != expected [method ]:
4750 print ("Stats.%s output for %s doesn't fit expectation!" %
4851 (method , self .profilerclass .__name__ ))
4952 print ('\n ' .join (unified_diff (
5053 results [i + 1 ].split ('\n ' ),
51- self . expected_output [method ].split ('\n ' ))))
54+ expected [method ].split ('\n ' ))))
5255
5356
5457def regenerate_expected_output (filename , cls ):
@@ -65,9 +68,10 @@ def regenerate_expected_output(filename, cls):
6568
6669 with open (filename , 'w' ) as f :
6770 f .writelines (newfile )
71+ f .write ("_ProfileOutput = {}\n " )
6872 for i , method in enumerate (cls .methodnames ):
69- f .write ('%s.expected_output [%r] = """\\ \n %s"""\n ' % (
70- cls . __name__ , method , results [i + 1 ]))
73+ f .write ('_ProfileOutput [%r] = """\\ \n %s"""\n ' % (
74+ method , results [i + 1 ]))
7175 f .write ('\n if __name__ == "__main__":\n main()\n ' )
7276
7377
@@ -83,7 +87,8 @@ def main():
8387
8488# Don't remove this comment. Everything below it is auto-generated.
8589#--cut--------------------------------------------------------------------------
86- ProfileTest .expected_output ['print_stats' ] = """\
90+ _ProfileOutput = {}
91+ _ProfileOutput ['print_stats' ] = """\
8792 28 27.972 0.999 27.972 0.999 profilee.py:110(__getattr__)
8893 1 269.996 269.996 999.769 999.769 profilee.py:25(testfunc)
8994 23/3 149.937 6.519 169.917 56.639 profilee.py:35(factorial)
@@ -93,7 +98,7 @@ def main():
9398 2 -0.006 -0.003 139.946 69.973 profilee.py:84(helper2_indirect)
9499 8 311.976 38.997 399.912 49.989 profilee.py:88(helper2)
95100 8 63.976 7.997 79.960 9.995 profilee.py:98(subhelper)"""
96- ProfileTest . expected_output ['print_callers' ] = """\
101+ _ProfileOutput ['print_callers' ] = """\
97102 :0(append) <- profilee.py:73(helper1)(4) 119.964
98103:0(exc_info) <- profilee.py:73(helper1)(4) 119.964
99104:0(hasattr) <- profilee.py:73(helper1)(4) 119.964
@@ -111,7 +116,7 @@ def main():
111116profilee.py:88(helper2) <- profilee.py:55(helper)(6) 599.830
112117 profilee.py:84(helper2_indirect)(2) 139.946
113118profilee.py:98(subhelper) <- profilee.py:88(helper2)(8) 399.912"""
114- ProfileTest . expected_output ['print_callees' ] = """\
119+ _ProfileOutput ['print_callees' ] = """\
115120 :0(hasattr) -> profilee.py:110(__getattr__)(12) 27.972
116121<string>:1(<module>) -> profilee.py:25(testfunc)(1) 999.769
117122profilee.py:110(__getattr__) ->
0 commit comments