cherrypy.test.helper module

A library of helper functions for the CherryPy test suite.

class cherrypy.test.helper.CPProcess(wait=False, daemonize=False, ssl=False, socket_host=None, socket_port=None)[source]

Bases: object

CherryPy Process Spawning Helper.

_join_daemon()[source]
access_log = '/home/docs/checkouts/readthedocs.org/user_builds/cherrypy/envs/latest/lib/python3.6/site-packages/cherrypy/test/test.access.log'
config_file = '/home/docs/checkouts/readthedocs.org/user_builds/cherrypy/envs/latest/lib/python3.6/site-packages/cherrypy/test/test.conf'
config_template = "[global]\nserver.socket_host: '%(host)s'\nserver.socket_port: %(port)s\nchecker.on: False\nlog.screen: False\nlog.error_file: r'%(error_log)s'\nlog.access_file: r'%(access_log)s'\n%(ssl)s\n%(extra)s\n"
error_log = '/home/docs/checkouts/readthedocs.org/user_builds/cherrypy/envs/latest/lib/python3.6/site-packages/cherrypy/test/test.error.log'
get_pid()[source]

Get the server process ID.

join()[source]

Wait for the process to exit.

pid_file = '/home/docs/checkouts/readthedocs.org/user_builds/cherrypy/envs/latest/lib/python3.6/site-packages/cherrypy/test/test.pid'
start(imports=None)[source]

Start cherryd in a subprocess.

write_conf(extra='')[source]

Write the server config to disk.

class cherrypy.test.helper.CPWebCase(methodName='runTest')[source]

Bases: WebCase

CherryPy web test case base.

classmethod _setup_server(supervisor, conf)[source]
assertEqualDates(dt1, dt2, seconds=None)[source]

Assert abs(dt1 - dt2) is within Y seconds.

assertErrorPage(status, message=None, pattern='')[source]

Compare the response body with a built in error page.

The function will optionally look for the regexp pattern, within the exception embedded in the error page.

available_servers = {'cpmodpy': <function get_cpmodpy_supervisor>, 'modfastcgi': <function get_modfastcgi_supervisor>, 'modfcgid': <function get_modfcgid_supervisor>, 'modpygw': <function get_modpygw_supervisor>, 'modwsgi': <function get_modwsgi_supervisor>, 'native': <class 'cherrypy.test.helper.NativeServerSupervisor'>, 'wsgi': <class 'cherrypy.test.helper.LocalWSGISupervisor'>, 'wsgi_u': <function get_wsgi_u_supervisor>}
base()[source]

Construct the base server URL.

date_tolerance = 2
default_server = 'wsgi'
do_gc_test = False
exit()[source]

Terminate the program.

getPage(url, *args, **kwargs)[source]

Open the url.

prefix()[source]

Get an HTTP handler prefix.

scheme = 'http'
script_name = ''
classmethod setup_class()[source]

Invoke a test server.

skip(msg='skipped ')[source]

Skip the currently running test.

classmethod teardown_class()[source]

Tear down the test server.

test_gc()[source]

Perform the garbage collection testing.

class cherrypy.test.helper.LocalSupervisor(**kwargs)[source]

Bases: Supervisor

Base for modeling/controlling servers which run in the same process.

When the server side runs in a different process, start/stop can dump all state between each test module easily. When the server side runs in the same process as the client, however, we have to do a bit more work to ensure config and mounted apps are reset between tests.

start(modulename=None)[source]

Load and start the HTTP server.

stop()[source]

Stop the HTTP server.

sync_apps()[source]

Tell the server about any apps which the setup functions mounted.

using_apache = False
using_wsgi = False
class cherrypy.test.helper.LocalWSGISupervisor(**kwargs)[source]

Bases: LocalSupervisor

Server supervisor for the builtin WSGI server.

get_app(app=None)[source]

Obtain a new (decorated) WSGI app to hook into the origin server.

httpserver_class = 'cherrypy._cpwsgi_server.CPWSGIServer'
sync_apps()[source]

Connect a new WSGI app into the origin server.

using_apache = False
using_wsgi = True
class cherrypy.test.helper.NativeServerSupervisor(**kwargs)[source]

Bases: LocalSupervisor

Server supervisor for the builtin HTTP server.

httpserver_class = 'cherrypy._cpnative_server.CPHTTPServer'
using_apache = False
using_wsgi = False
class cherrypy.test.helper.Supervisor(**kwargs)[source]

Bases: object

Base class for modeling and controlling servers during testing.

cherrypy.test.helper._test_method_sorter(_, x, y)[source]

Monkeypatch the test sorter to always run test_gc last in each suite.

cherrypy.test.helper.get_cpmodpy_supervisor(**options)[source]

Load a CherryPy mod_python supervisor.

cherrypy.test.helper.get_modfastcgi_supervisor(**options)[source]

Load a CherryPy mod_fastcgi supervisor.

cherrypy.test.helper.get_modfcgid_supervisor(**options)[source]

Load a CherryPy mod_fcgi supervisor.

cherrypy.test.helper.get_modpygw_supervisor(**options)[source]

Load a CherryPy mod_python gateway supervisor.

cherrypy.test.helper.get_modwsgi_supervisor(**options)[source]

Load a CherryPy mod_wsgi supervisor.

cherrypy.test.helper.get_wsgi_u_supervisor(**options)[source]

Load a CherryPy WSGI supervisor.

cherrypy.test.helper.log_to_stderr(msg, level)[source]

Log to Standard Error.

cherrypy.test.helper.setup_client()[source]

Set up the WebCase classes to match the server’s socket settings.