Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def server_for_test_app(app):
try:
from paste.exceptions.errormiddleware import ErrorMiddleware
error_app = ErrorMiddleware(app.app, debug=True, error_log="errors.log")
server = StopableWSGIServer.create(error_app)
except ImportError:
# paste.exceptions not available for Python 3.
error_app = app.app
server = StopableWSGIServer.create(error_app)
try:
server.wait()
yield server
finally:
server.shutdown()
# There seem to be persistent transient problems with the testing, sleeping
# between creation of test app instances for greater than .5 seconds seems
# to help (async loop length in code is .5 so this maybe makes some sense?)
if "TEST_WEBAPP_POST_SHUTDOWN_SLEEP" in environ:
time.sleep(int(environ.get("TEST_WEBAPP_POST_SHUTDOWN_SLEEP")))
def server_for_test_app(app):
try:
from paste.exceptions.errormiddleware import ErrorMiddleware
error_app = ErrorMiddleware(app.app, debug=True, error_log="errors.log")
server = StopableWSGIServer.create(error_app)
except ImportError:
# paste.exceptions not available for Python 3.
error_app = app.app
server = StopableWSGIServer.create(error_app)
try:
server.wait()
yield server
finally:
server.shutdown()
# There seem to be persistent transient problems with the testing, sleeping
# between creation of test app instances for greater than .5 seconds seems
# to help (async loop length in code is .5 so this maybe makes some sense?)
if "TEST_WEBAPP_POST_SHUTDOWN_SLEEP" in environ:
time.sleep(int(environ.get("TEST_WEBAPP_POST_SHUTDOWN_SLEEP")))
def test_shutdown_non_running(self):
host, port = http.get_free_port()
s = http.StopableWSGIServer(debug_app, host=host, port=port)
self.assertFalse(s.wait(retries=-1))
self.assertTrue(s.shutdown())
def setUp(self):
def app(environ, start_response):
start_response('200 OK', [('Content-Type', 'text/plain')])
time.sleep(2)
return [b'foobar\n']
self.s = http.StopableWSGIServer.create(app)
self.s.wait()
self.application_url = self.s.application_url.rstrip('/')
def backend_sample(request, settings, app_sample):
"""Return a http server with the adhocracy wsgi application."""
port = settings['port']
backend = StopableWSGIServer.create(app_sample, port=port)
request.addfinalizer(backend.shutdown)
return backend
def __init__(self, application, *args, **kwargs):
super(StopableWSGIServer, self).__init__(self.wrapper, *args, **kwargs)
self.runner = None
self.test_app = application
self.application_url = 'http://%s:%s/' % (self.adj.host, self.adj.port)
def setup_test(test):
for example in test.examples:
# urlopen as moved in py3
if PY3:
example.options.setdefault(SKIP, 1)
if not PY3:
server = http.StopableWSGIServer.create(input_app)
server.wait()
path_to_html_file = os.path.join('tests', 'test.html')
test.globs.update(
input_app=input_app,
server=server,
your_url=server.application_url.rstrip('/') + '/html',
path_to_html_file=path_to_html_file,
)
def setup_test(test):
server = http.StopableWSGIServer.create(debug_app)
server.wait()
path_to_html_file = os.path.join('tests', 'test.html')
test.globs.update(
urlopen=urlopen,
server=server,
your_url=server.application_url,
path_to_html_file=path_to_html_file,
)
def setup_test(test):
server = http.StopableWSGIServer.create(input_app)
server.wait()
test.globs.update(
server=server,
your_url=server.application_url.rstrip('/') + '/html',
)