[Python-3000] [Python-3000-checkins] r61155 - python/branches/py3k/Lib/test/test_profile.py
Guido van Rossum
guido at python.org
Sat Mar 1 16:55:29 CET 2008
Thanks for fixing this Brett!
test_cProfile.py is still failing, but I think that's because it's the
wrong file. In 2.6, test_cprofile and test_profile are rather similar.
But in 3.0, test_cProfile.py seems to be a clone of the 'profilee.py'
test program... Probably a manual-merge glitch. Maybe it should just
be deleted and replaced with a modified copy of test_profile.py?
--Guido
On Fri, Feb 29, 2008 at 8:28 PM, brett.cannon
<python-3000-checkins at python.org> wrote:
> Author: brett.cannon
> Date: Sat Mar 1 05:28:23 2008
> New Revision: 61155
>
> Modified:
> python/branches/py3k/Lib/test/test_profile.py
> Log:
> 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.
>
>
> 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 Sat Mar 1 05:28:23 2008
> @@ -29,7 +29,13 @@
> 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 @@
> 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 @@
> # 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 @@
> 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: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: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()
> _______________________________________________
> Python-3000-checkins mailing list
> Python-3000-checkins at python.org
> http://mail.python.org/mailman/listinfo/python-3000-checkins
>
--
--Guido van Rossum (home page: http://www.python.org/~guido/)
More information about the Python-3000
mailing list