I have added support for coverage analysis using coverage.py from Gareth Rees and Ned Batchelder, as well as support for profiling using either the profile or hotshot modules from the Python standard library, to Zope 2's test runner test.py.

Justification:

- coverage.py will let you interactively focus on the modules you want to check for coverage.

- profile is slow to collect data but quick for analysis.

- hotshot is fast when collecting but very slow for analysis. On the other hand, one can feed the great KCacheGrind tool with hotshot data after some transformation and this is the best way I have found so far for interactively exploring profile data.

Since I'm not a regular Zope commiter, I'd like to ask for comments and permission first before commiting.

The test.py file is here:
http://blogs.nuxeo.com/sections/blogs/fermigier/2005_08_21_coverage-py-profile

BTW: the patch is absolutely trivial (see attached file).

        S.
--
Stéfane Fermigier, Tel: +33 (0)6 63 04 12 77 (mobile).
Nuxeo Collaborative Portal Server: http://www.nuxeo.com/cps
Gestion de contenu web / portail collaboratif / groupware / open source!
1c1
< #!/home/fermigier/bin/python
---
> #!/usr/bin/env python2.3
124,143d123
< --coverage
<     Use the coverage.py module from Gareth Rees
<     (http://www.nedbatchelder.com/code/modules/coverage.html) to collect data
<     for code coverage.  This will output trace data in a file called
<     '.coverage'. You will need to call coverage.py after the test run to
<     analyse the data (-r for a line count report, -a for annotated file).
< 
< --profile
<     Use the profile module from the standard library to collect profiling 
data.
<     This will output data in a file called '.profile'. You will need to use 
the
<     pstats module from the standard library after the test run to analyse the
<     data.
< 
< --hotshot
<     Use the hotshot module from the standard library to collect profiling 
data.
<     This will output data in a file called '.hotshot'. You will need to use 
the
<     hotshot.pstats module from the standard library after the test run to
<     analyse the data. You may also use the hotshot2cg script from the
<     KCacheGrind sources to create data suitable for analysis by KCacheGrind.
< 
772,774d751
<     COVERAGE = False
<     PROFILE = False
<     HOTSHOT = False
797,798c774
<                                     "config-file=", "import-testing",
<                                     "coverage", "profile", "hotshot"])
---
>                                     "config-file=", "import-testing"])
850,855d825
<         elif k == "--coverage":
<             COVERAGE = True
<         elif k == "--profile":
<             PROFILE = True
<         elif k == "--hotshot":
<             HOTSHOT = True
936,958d905
< 
<         elif COVERAGE:
<             try:
<                 from coverage import the_coverage
<             except:
<                 print "You need to install coverage.py from "
<                 print 
"http://www.nedbatchelder.com/code/modules/coverage.html";
<                 sys.exit()
<             the_coverage.start()
<             main(module_filter, test_filter, libdir)
< 
<         elif PROFILE:
<             import profile
<             profile.runctx("main(module_filter, test_filter, libdir)",
<                            globals=globals(), locals=vars(), 
<                            filename=".profile")
< 
<         elif HOTSHOT:
<             import hotshot
<             profile = hotshot.Profile(".hotshot")
<             profile.runctx("main(module_filter, test_filter, libdir)",
<                            globals=globals(), locals=vars())
< 
begin:vcard
fn:Stefane Fermigier
n:Fermigier;Stefane
org:Nuxeo
adr:;;14, rue Soleillet;Paris;;75020;France
email;internet:[EMAIL PROTECTED]
title:Directeur / CEO
tel;work:+33 1 40 33 79 87
tel;fax:+33 1 43 58 14 15
tel;cell:+33 6 63 04 12 77
x-mozilla-html:FALSE
url:http://www.nuxeo.com/
version:2.1
end:vcard

_______________________________________________
Zope-Dev maillist  -  Zope-Dev@zope.org
http://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope )

Reply via email to