[Checkins] SVN: zc.selenium/trunk/src/zc/selenium/selenium.py Added
the ability to run coverage tests over all selenium tests.
Stephan Richter
srichter at cosmos.phy.tufts.edu
Tue Jun 3 18:57:05 EDT 2008
Log message for revision 87133:
Added the ability to run coverage tests over all selenium tests.
Unfortunately, we need to use a different server in this case, because
ZServer uses the thread module, which ignores the trace that the
coverage tracer installs. It works well, but it is slow.
Changed:
U zc.selenium/trunk/src/zc/selenium/selenium.py
-=-
Modified: zc.selenium/trunk/src/zc/selenium/selenium.py
===================================================================
--- zc.selenium/trunk/src/zc/selenium/selenium.py 2008-06-03 22:15:18 UTC (rev 87132)
+++ zc.selenium/trunk/src/zc/selenium/selenium.py 2008-06-03 22:57:04 UTC (rev 87133)
@@ -25,7 +25,9 @@
import time
import urllib2
import webbrowser
+import wsgiref.simple_server
+from zope.testing import testrunner
# Compute a default port; this is simple and doesn't ensure that the
# port is available, but does better than just hardcoding a port
@@ -38,9 +40,19 @@
# This removes the script directory from sys.path, which we do
# since there are no modules here.
#
+
from zope.app.server.main import main
main(["-C", config, "-X", "http0/address=" + port] + sys.argv[1:])
+def make_wsgi_run_zope(app_path):
+ module, name = app_path.rsplit('.', 1)
+ app_factory = getattr(__import__(module, globals(), locals(), [1]), name)
+ def run_zope(config, port):
+ server = wsgiref.simple_server.make_server(
+ '0.0.0.0', int(port), app_factory(config))
+ server.serve_forever()
+ return run_zope
+
def run_tests(zope_thread, auto_start, browser_name, port, base_url):
start_time = time.time()
@@ -49,7 +61,8 @@
socket.setdefaulttimeout(5)
url = base_url %{'port': port}
url += ('/@@/selenium/TestRunner.html'
- '?test=tests%2FTestSuite.html&resultsUrl=/@@/selenium_results')
+ '?test=tests%%2FTestSuite.html&'
+ 'resultsUrl=%s/@@/selenium_results' %url)
time.sleep(1)
while zope_thread.isAlive():
try:
@@ -152,6 +165,19 @@
parser.add_option('-u', '--base-url', dest='base_url',
default='http://localhost:%(port)s/',
help='The base URL of the Zope site (may contain skin).')
+ parser.add_option(
+ '--coverage', action="store", type='string', dest='coverage',
+ help="""\
+ Perform code-coverage analysis, saving trace data to the directory
+ with the given name. A code coverage summary is printed to standard
+ out.
+ """)
+ parser.add_option(
+ '--package', '--dir', '-s', action="append", dest='package',
+ help="A package to be included in the coverage report.")
+ parser.add_option(
+ '--wsgi_app', '-w', action="store", dest='wsgi_app',
+ help="The path to the WSGI application to use.")
options, positional = parser.parse_args()
options.config = config
@@ -171,10 +197,20 @@
if options.random_port:
options.port = random_port()
+ if options.wsgi_app:
+ run_zope = make_wsgi_run_zope(options.wsgi_app)
+
if options.server_only:
run_zope(options.config, port=options.port)
sys.exit(0)
+ if options.coverage:
+ options.package = ('keas',)
+ options.prefix = (('/', 'keas'),)
+ options.test_path = []
+ tracer = testrunner.TestTrace(options, trace=False, count=True)
+ tracer.start()
+
zope_thread = threading.Thread(
target=run_zope, args=(options.config, options.port))
zope_thread.setDaemon(True)
@@ -183,6 +219,12 @@
zope_thread, options.auto_start, options.browser, options.port,
options.base_url)
+ if options.coverage:
+ tracer.stop()
+ coverdir = os.path.join(os.getcwd(), options.coverage)
+ res = tracer.results()
+ res.write_results(summary=True, coverdir=coverdir)
+
if options.keep_running or not options.auto_start:
while True:
time.sleep(10000)
More information about the Checkins
mailing list