summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_profile.py
diff options
context:
space:
mode:
authorBrett Cannon <bcannon@gmail.com>2008-03-01 04:28:23 (GMT)
committerBrett Cannon <bcannon@gmail.com>2008-03-01 04:28:23 (GMT)
commitc17b35c6b444817b178bffbc061b89d581ffc1e0 (patch)
tree98935c828209e2330dd51f2531cb92197a36c901 /Lib/test/test_profile.py
parent3af831bacac9626b62039f7bcf777a5f1202493b (diff)
downloadcpython-c17b35c6b444817b178bffbc061b89d581ffc1e0.zip
cpython-c17b35c6b444817b178bffbc061b89d581ffc1e0.tar.gz
cpython-c17b35c6b444817b178bffbc061b89d581ffc1e0.tar.bz2
Change test_profile to only compare data that originates from the test file.
Including the full output becomes hairy in the face of the I/O system being written in Python and thus profiled (i.e., running the test on its own and then under regrtest created a different profile thanks to an extra flush() call in the latter case). No need to backport as 2.x's I/O is entirely C-based and thus not profiled.
Diffstat (limited to 'Lib/test/test_profile.py')
-rwxr-xr-xLib/test/test_profile.py68
1 files changed, 11 insertions, 57 deletions
diff --git a/Lib/test/test_profile.py b/Lib/test/test_profile.py
index 632911d..398ab86 100755
--- a/Lib/test/test_profile.py
+++ b/Lib/test/test_profile.py
@@ -29,7 +29,13 @@ class ProfileTest(unittest.TestCase):
stats = pstats.Stats(prof, stream=s)
stats.strip_dirs().sort_stats("stdname")
getattr(stats, methodname)()
- results.append(s.getvalue())
+ output = s.getvalue().splitlines()
+ mod_name = testfunc.__module__.rsplit('.', 1)[1]
+ # Only compare against stats originating from the test file.
+ # Prevents outside code (e.g., the io module) from causing
+ # unexpected output.
+ output = [line.rstrip() for line in output if mod_name in line]
+ results.append('\n'.join(output))
return results
def test_cprofile(self):
@@ -53,7 +59,7 @@ def regenerate_expected_output(filename, cls):
with open(filename, 'r') as f:
for line in f:
newfile.append(line)
- if line[:6] == '#--cut':
+ if line.startswith('#--cut'):
break
with open(filename, 'w') as f:
@@ -77,22 +83,6 @@ def main():
# Don't remove this comment. Everything below it is auto-generated.
#--cut--------------------------------------------------------------------------
ProfileTest.expected_output['print_stats'] = """\
- 126 function calls (106 primitive calls) in 999.751 CPU seconds
-
- Ordered by: standard name
-
- ncalls tottime percall cumtime percall filename:lineno(function)
- 4 -0.004 -0.001 -0.004 -0.001 :0(append)
- 4 -0.004 -0.001 -0.004 -0.001 :0(exc_info)
- 1 -0.004 -0.004 999.753 999.753 :0(exec)
- 12 -0.024 -0.002 11.964 0.997 :0(hasattr)
- 1 0.000 0.000 0.000 0.000 :0(setprofile)
- 1 -0.002 -0.002 999.767 999.767 <string>:1(<module>)
- 2 -0.004 -0.002 -0.010 -0.005 io.py:1213(flush)
- 2 -0.002 -0.001 -0.002 -0.001 io.py:656(closed)
- 2 -0.004 -0.002 -0.006 -0.003 io.py:874(flush)
- 0 0.000 0.000 profile:0(profiler)
- 1 -0.002 -0.002 999.751 999.751 profile:0(testfunc())
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)
@@ -101,26 +91,12 @@ ProfileTest.expected_output['print_stats'] = """\
4 115.984 28.996 119.964 29.991 profilee.py:73(helper1)
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)
-
-
-"""
+ 8 63.976 7.997 79.960 9.995 profilee.py:98(subhelper)"""
ProfileTest.expected_output['print_callers'] = """\
- Ordered by: standard name
-
-Function was called by...
:0(append) <- profilee.py:73(helper1)(4) 119.964
:0(exc_info) <- profilee.py:73(helper1)(4) 119.964
-:0(exec) <- profile:0(testfunc())(1) 999.751
:0(hasattr) <- profilee.py:73(helper1)(4) 119.964
profilee.py:88(helper2)(8) 399.912
-:0(setprofile) <- profile:0(testfunc())(1) 999.751
-<string>:1(<module>) <- :0(exec)(1) 999.753
-io.py:1213(flush) <- :0(exec)(2) 999.753
-io.py:656(closed) <- io.py:874(flush)(2) -0.006
-io.py:874(flush) <- io.py:1213(flush)(2) -0.010
-profile:0(profiler) <-
-profile:0(testfunc()) <- profile:0(profiler)(1) 0.000
profilee.py:110(__getattr__) <- :0(hasattr)(12) 11.964
profilee.py:98(subhelper)(16) 79.960
profilee.py:25(testfunc) <- <string>:1(<module>)(1) 999.767
@@ -133,27 +109,10 @@ profilee.py:73(helper1) <- profilee.py:55(helper)(4) 599.830
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
-
-
-"""
+profilee.py:98(subhelper) <- profilee.py:88(helper2)(8) 399.912"""
ProfileTest.expected_output['print_callees'] = """\
- Ordered by: standard name
-
-Function called...
-:0(append) ->
-:0(exc_info) ->
-:0(exec) -> <string>:1(<module>)(1) 999.767
- io.py:1213(flush)(2) -0.010
:0(hasattr) -> profilee.py:110(__getattr__)(12) 27.972
-:0(setprofile) ->
<string>:1(<module>) -> profilee.py:25(testfunc)(1) 999.769
-io.py:1213(flush) -> io.py:874(flush)(2) -0.006
-io.py:656(closed) ->
-io.py:874(flush) -> io.py:656(closed)(2) -0.002
-profile:0(profiler) -> profile:0(testfunc())(1) 999.751
-profile:0(testfunc()) -> :0(exec)(1) 999.753
- :0(setprofile)(1) 0.000
profilee.py:110(__getattr__) ->
profilee.py:25(testfunc) -> profilee.py:35(factorial)(1) 169.917
profilee.py:55(helper)(2) 599.830
@@ -164,16 +123,11 @@ profilee.py:55(helper) -> profilee.py:73(helper1)(4) 119.964
profilee.py:84(helper2_indirect)(2) 139.946
profilee.py:88(helper2)(6) 399.912
profilee.py:73(helper1) -> :0(append)(4) -0.004
- :0(exc_info)(4) -0.004
- :0(hasattr)(4) 11.964
profilee.py:84(helper2_indirect) -> profilee.py:35(factorial)(2) 169.917
profilee.py:88(helper2)(2) 399.912
profilee.py:88(helper2) -> :0(hasattr)(8) 11.964
profilee.py:98(subhelper)(8) 79.960
-profilee.py:98(subhelper) -> profilee.py:110(__getattr__)(16) 27.972
-
-
-"""
+profilee.py:98(subhelper) -> profilee.py:110(__getattr__)(16) 27.972"""
if __name__ == "__main__":
main()