summaryrefslogtreecommitdiff
path: root/cherrypy/test/modpy.py
diff options
context:
space:
mode:
authorRobert Brewer <fumanchu@aminus.org>2009-01-29 07:35:41 +0000
committerRobert Brewer <fumanchu@aminus.org>2009-01-29 07:35:41 +0000
commit99a5da1c7ebf1511a6cad13ca2de9450feedac22 (patch)
treece7341ba19b2b1797f0ca6deeffe1aea620f404f /cherrypy/test/modpy.py
parent3c9ea2678259ea62d59bdbd404ba714dc14f4c72 (diff)
downloadcherrypy-git-99a5da1c7ebf1511a6cad13ca2de9450feedac22.tar.gz
Rework of test suite to start the engine once per module, and only for modules that have a 'setup_server' function. This allows us to include modules which do not need to start a server in the normal test.py testList and exercise them at every full run. See, for example, that test_bus and test_states are now included.
Diffstat (limited to 'cherrypy/test/modpy.py')
-rw-r--r--cherrypy/test/modpy.py96
1 files changed, 31 insertions, 65 deletions
diff --git a/cherrypy/test/modpy.py b/cherrypy/test/modpy.py
index 811929bb..13b45ea1 100644
--- a/cherrypy/test/modpy.py
+++ b/cherrypy/test/modpy.py
@@ -63,15 +63,15 @@ conf_modpython_gateway = """
ServerName 127.0.0.1
DocumentRoot "/"
-Listen %s
+Listen %(port)s
LoadModule python_module modules/mod_python.so
SetHandler python-program
PythonFixupHandler cherrypy.test.modpy::wsgisetup
-PythonOption testmod %s
+PythonOption testmod %(modulename)s
PythonHandler modpython_gateway::handler
PythonOption wsgi.application cherrypy::tree
-PythonOption socket_host %s
+PythonOption socket_host %(host)s
PythonDebug On
"""
@@ -80,35 +80,44 @@ conf_cpmodpy = """
ServerName 127.0.0.1
DocumentRoot "/"
-Listen %s
+Listen %(port)s
LoadModule python_module modules/mod_python.so
SetHandler python-program
PythonFixupHandler cherrypy.test.modpy::cpmodpysetup
PythonHandler cherrypy._cpmodpy::handler
-PythonOption cherrypy.setup cherrypy.test.%s::setup_server
-PythonOption socket_host %s
+PythonOption cherrypy.setup cherrypy.test.%(modulename)s::setup_server
+PythonOption socket_host %(host)s
PythonDebug On
"""
-def start(testmod, host, port, conf_template):
- mpconf = CONF_PATH
- if not os.path.isabs(mpconf):
- mpconf = os.path.join(curdir, mpconf)
+class ServerControl(object):
- f = open(mpconf, 'wb')
- try:
- f.write(conf_template % (port, testmod, host))
- finally:
- f.close()
+ def __init__(self, host, port, template):
+ self.host = host
+ self.port = port
+ self.template = template
- result = read_process(APACHE_PATH, "-k start -f %s" % mpconf)
- if result:
- print result
-
-def stop():
- """Gracefully shutdown a server that is serving forever."""
- read_process(APACHE_PATH, "-k stop")
+ def start(self, modulename):
+ mpconf = CONF_PATH
+ if not os.path.isabs(mpconf):
+ mpconf = os.path.join(curdir, mpconf)
+
+ f = open(mpconf, 'wb')
+ try:
+ f.write(self.template %
+ {'port': self.port, 'modulename': modulename,
+ 'host': self.host})
+ finally:
+ f.close()
+
+ result = read_process(APACHE_PATH, "-k start -f %s" % mpconf)
+ if result:
+ print result
+
+ def stop(self):
+ """Gracefully shutdown a server that is serving forever."""
+ read_process(APACHE_PATH, "-k stop")
loaded = False
@@ -150,46 +159,3 @@ def cpmodpysetup(req):
from mod_python import apache
return apache.OK
-
-class ModPythonTestHarness(test.TestHarness):
- """TestHarness for ModPython and CherryPy."""
-
- use_wsgi = False
-
- def _run(self, conf):
- import cherrypy
- cherrypy.server.using_apache = True
-
- from cherrypy.test import webtest
- webtest.WebCase.PORT = self.port
- webtest.WebCase.harness = self
- webtest.WebCase.scheme = "http"
- webtest.WebCase.interactive = self.interactive
- print
- print "Running tests:", self.server
-
- if self.use_wsgi:
- cherrypy.server.using_wsgi = True
- conf_template = conf_modpython_gateway
- else:
- cherrypy.server.using_wsgi = False
- conf_template = conf_cpmodpy
-
- # mod_python, since it runs in the Apache process, must be
- # started separately for each test, and then *that* process
- # must run the setup_server() function for the test.
- # Then our process can run the actual test.
- success = True
- for testmod in self.tests:
- try:
- start(testmod, self.host, self.port, conf_template)
- suite = webtest.ReloadingTestLoader().loadTestsFromName(testmod)
- result = webtest.TerseTestRunner(verbosity=2).run(suite)
- success &= result.wasSuccessful()
- finally:
- stop()
- if success:
- return 0
- else:
- return 1
-