mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
a trival fix to let test_profile pass if it runs after test_cprofile
This commit is contained in:
parent
4e299c709b
commit
7d7665384c
2 changed files with 20 additions and 11 deletions
|
@ -10,6 +10,9 @@ from test.test_profile import ProfileTest, regenerate_expected_output
|
|||
class CProfileTest(ProfileTest):
|
||||
profilerclass = cProfile.Profile
|
||||
|
||||
def get_expected_output(self):
|
||||
return _ProfileOutput
|
||||
|
||||
|
||||
def test_main():
|
||||
run_unittest(CProfileTest)
|
||||
|
@ -23,7 +26,8 @@ def main():
|
|||
|
||||
# Don't remove this comment. Everything below it is auto-generated.
|
||||
#--cut--------------------------------------------------------------------------
|
||||
CProfileTest.expected_output['print_stats'] = """\
|
||||
_ProfileOutput = {}
|
||||
_ProfileOutput['print_stats'] = """\
|
||||
28 0.028 0.001 0.028 0.001 profilee.py:110(__getattr__)
|
||||
1 0.270 0.270 1.000 1.000 profilee.py:25(testfunc)
|
||||
23/3 0.150 0.007 0.170 0.057 profilee.py:35(factorial)
|
||||
|
@ -33,7 +37,7 @@ CProfileTest.expected_output['print_stats'] = """\
|
|||
2 0.000 0.000 0.140 0.070 profilee.py:84(helper2_indirect)
|
||||
8 0.312 0.039 0.400 0.050 profilee.py:88(helper2)
|
||||
8 0.064 0.008 0.080 0.010 profilee.py:98(subhelper)"""
|
||||
CProfileTest.expected_output['print_callers'] = """\
|
||||
_ProfileOutput['print_callers'] = """\
|
||||
profilee.py:110(__getattr__) <- 16 0.016 0.016 profilee.py:98(subhelper)
|
||||
profilee.py:25(testfunc) <- 1 0.270 1.000 <string>:1(<module>)
|
||||
profilee.py:35(factorial) <- 1 0.014 0.130 profilee.py:25(testfunc)
|
||||
|
@ -50,7 +54,7 @@ profilee.py:98(subhelper) <- 8 0.064 0.080
|
|||
{built-in method hasattr} <- 4 0.000 0.004 profilee.py:73(helper1)
|
||||
8 0.000 0.008 profilee.py:88(helper2)
|
||||
{method 'append' of 'list' objects} <- 4 0.000 0.000 profilee.py:73(helper1)"""
|
||||
CProfileTest.expected_output['print_callees'] = """\
|
||||
_ProfileOutput['print_callees'] = """\
|
||||
<string>:1(<module>) -> 1 0.270 1.000 profilee.py:25(testfunc)
|
||||
profilee.py:110(__getattr__) ->
|
||||
profilee.py:25(testfunc) -> 1 0.014 0.130 profilee.py:35(factorial)
|
||||
|
|
|
@ -16,7 +16,9 @@ class ProfileTest(unittest.TestCase):
|
|||
|
||||
profilerclass = profile.Profile
|
||||
methodnames = ['print_stats', 'print_callers', 'print_callees']
|
||||
expected_output = {}
|
||||
|
||||
def get_expected_output(self):
|
||||
return _ProfileOutput
|
||||
|
||||
@classmethod
|
||||
def do_profiling(cls):
|
||||
|
@ -41,14 +43,15 @@ class ProfileTest(unittest.TestCase):
|
|||
|
||||
def test_cprofile(self):
|
||||
results = self.do_profiling()
|
||||
expected = self.get_expected_output()
|
||||
self.assertEqual(results[0], 1000)
|
||||
for i, method in enumerate(self.methodnames):
|
||||
if results[i+1] != self.expected_output[method]:
|
||||
if results[i+1] != expected[method]:
|
||||
print("Stats.%s output for %s doesn't fit expectation!" %
|
||||
(method, self.profilerclass.__name__))
|
||||
print('\n'.join(unified_diff(
|
||||
results[i+1].split('\n'),
|
||||
self.expected_output[method].split('\n'))))
|
||||
expected[method].split('\n'))))
|
||||
|
||||
|
||||
def regenerate_expected_output(filename, cls):
|
||||
|
@ -65,9 +68,10 @@ def regenerate_expected_output(filename, cls):
|
|||
|
||||
with open(filename, 'w') as f:
|
||||
f.writelines(newfile)
|
||||
f.write("_ProfileOutput = {}\n")
|
||||
for i, method in enumerate(cls.methodnames):
|
||||
f.write('%s.expected_output[%r] = """\\\n%s"""\n' % (
|
||||
cls.__name__, method, results[i+1]))
|
||||
f.write('_ProfileOutput[%r] = """\\\n%s"""\n' % (
|
||||
method, results[i+1]))
|
||||
f.write('\nif __name__ == "__main__":\n main()\n')
|
||||
|
||||
|
||||
|
@ -83,7 +87,8 @@ def main():
|
|||
|
||||
# Don't remove this comment. Everything below it is auto-generated.
|
||||
#--cut--------------------------------------------------------------------------
|
||||
ProfileTest.expected_output['print_stats'] = """\
|
||||
_ProfileOutput = {}
|
||||
_ProfileOutput['print_stats'] = """\
|
||||
28 27.972 0.999 27.972 0.999 profilee.py:110(__getattr__)
|
||||
1 269.996 269.996 999.769 999.769 profilee.py:25(testfunc)
|
||||
23/3 149.937 6.519 169.917 56.639 profilee.py:35(factorial)
|
||||
|
@ -93,7 +98,7 @@ ProfileTest.expected_output['print_stats'] = """\
|
|||
2 -0.006 -0.003 139.946 69.973 profilee.py:84(helper2_indirect)
|
||||
8 311.976 38.997 399.912 49.989 profilee.py:88(helper2)
|
||||
8 63.976 7.997 79.960 9.995 profilee.py:98(subhelper)"""
|
||||
ProfileTest.expected_output['print_callers'] = """\
|
||||
_ProfileOutput['print_callers'] = """\
|
||||
:0(append) <- profilee.py:73(helper1)(4) 119.964
|
||||
:0(exc_info) <- profilee.py:73(helper1)(4) 119.964
|
||||
:0(hasattr) <- profilee.py:73(helper1)(4) 119.964
|
||||
|
@ -111,7 +116,7 @@ profilee.py:84(helper2_indirect) <- profilee.py:55(helper)(2) 599.830
|
|||
profilee.py:88(helper2) <- profilee.py:55(helper)(6) 599.830
|
||||
profilee.py:84(helper2_indirect)(2) 139.946
|
||||
profilee.py:98(subhelper) <- profilee.py:88(helper2)(8) 399.912"""
|
||||
ProfileTest.expected_output['print_callees'] = """\
|
||||
_ProfileOutput['print_callees'] = """\
|
||||
:0(hasattr) -> profilee.py:110(__getattr__)(12) 27.972
|
||||
<string>:1(<module>) -> profilee.py:25(testfunc)(1) 999.769
|
||||
profilee.py:110(__getattr__) ->
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue