diff options
author | Benjamin Peterson <benjamin@python.org> | 2008-10-06 22:05:00 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2008-10-06 22:05:00 (GMT) |
commit | 7d7665384c7276e87570fcbf2b61e97d9ab2db5b (patch) | |
tree | 93adeb0635ab14e0e1f2c196ba73cb8fabd8cd64 /Lib/test/test_profile.py | |
parent | 4e299c709be166d76dfcaa0fafefa5f6375a94bf (diff) | |
download | cpython-7d7665384c7276e87570fcbf2b61e97d9ab2db5b.zip cpython-7d7665384c7276e87570fcbf2b61e97d9ab2db5b.tar.gz cpython-7d7665384c7276e87570fcbf2b61e97d9ab2db5b.tar.bz2 |
a trival fix to let test_profile pass if it runs after test_cprofile
Diffstat (limited to 'Lib/test/test_profile.py')
-rwxr-xr-x | Lib/test/test_profile.py | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/Lib/test/test_profile.py b/Lib/test/test_profile.py index 84167dd..c972fc6 100755 --- a/Lib/test/test_profile.py +++ b/Lib/test/test_profile.py @@ -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__) -> |