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

_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]
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]
class cherrypy.test.helper.CPWebCase(methodName='runTest')[source]

Bases: WebCase

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]
date_tolerance = 2
default_server = 'wsgi'
do_gc_test = False
exit()[source]
getPage(url, *args, **kwargs)[source]

Open the url.

prefix()[source]
scheme = 'http'
script_name = ''
classmethod setup_class()[source]
skip(msg='skipped ')[source]
classmethod teardown_class()[source]
test_gc()[source]
class cherrypy.test.helper.LocalSupervisor(**kwargs)[source]

Bases: Supervisor

Base class 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]
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]

Hook 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]
cherrypy.test.helper.get_modfastcgi_supervisor(**options)[source]
cherrypy.test.helper.get_modfcgid_supervisor(**options)[source]
cherrypy.test.helper.get_modpygw_supervisor(**options)[source]
cherrypy.test.helper.get_modwsgi_supervisor(**options)[source]
cherrypy.test.helper.get_wsgi_u_supervisor(**options)[source]
cherrypy.test.helper.log_to_stderr(msg, level)[source]
cherrypy.test.helper.setup_client()[source]

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