Discussion:
[Python-3000-checkins] r66818 - in python/branches/py3k/Lib/test: test_cprofile.py test_profile.py
benjamin.peterson
2008-10-06 22:05:00 UTC
Permalink
Author: benjamin.peterson
Date: Tue Oct 7 00:05:00 2008
New Revision: 66818

Log:
a trival fix to let test_profile pass if it runs after test_cprofile

Modified:
python/branches/py3k/Lib/test/test_cprofile.py
python/branches/py3k/Lib/test/test_profile.py

Modified: python/branches/py3k/Lib/test/test_cprofile.py
==============================================================================
--- python/branches/py3k/Lib/test/test_cprofile.py (original)
+++ python/branches/py3k/Lib/test/test_cprofile.py Tue Oct 7 00:05:00 2008
@@ -10,6 +10,9 @@
class CProfileTest(ProfileTest):
profilerclass = cProfile.Profile

+ def get_expected_output(self):
+ return _ProfileOutput
+

def test_main():
run_unittest(CProfileTest)
@@ -23,7 +26,8 @@

# 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 @@
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 @@
{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)

Modified: python/branches/py3k/Lib/test/test_profile.py
==============================================================================
--- python/branches/py3k/Lib/test/test_profile.py (original)
+++ python/branches/py3k/Lib/test/test_profile.py Tue Oct 7 00:05:00 2008
@@ -16,7 +16,9 @@

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 @@

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 @@

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 @@

# 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 @@
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: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...