Skip to content
Snippets Groups Projects
Commit 44d536b8 authored by John Chilton's avatar John Chilton
Browse files

Allow puslar test app to yield plain app instead of webapp.

parent 7f7c9fd5
No related branches found
No related tags found
No related merge requests found
...@@ -230,11 +230,12 @@ def test_pulsar_server(global_conf={}, app_conf={}, test_conf={}): ...@@ -230,11 +230,12 @@ def test_pulsar_server(global_conf={}, app_conf={}, test_conf={}):
class RestartablePulsarAppProvider(object): class RestartablePulsarAppProvider(object):
def __init__(self, global_conf={}, app_conf={}, test_conf={}): def __init__(self, global_conf={}, app_conf={}, test_conf={}, web=True):
self.staging_directory = mkdtemp() self.staging_directory = mkdtemp()
self.global_conf = global_conf self.global_conf = global_conf
self.app_conf = app_conf self.app_conf = app_conf
self.test_conf = test_conf self.test_conf = test_conf
self.web = web
@contextmanager @contextmanager
def new_app(self): def new_app(self):
...@@ -242,7 +243,8 @@ class RestartablePulsarAppProvider(object): ...@@ -242,7 +243,8 @@ class RestartablePulsarAppProvider(object):
self.global_conf, self.global_conf,
self.app_conf, self.app_conf,
self.test_conf, self.test_conf,
staging_directory=self.staging_directory staging_directory=self.staging_directory,
web=self.web,
) as app: ) as app:
yield app yield app
...@@ -264,7 +266,13 @@ def restartable_pulsar_app_provider(**kwds): ...@@ -264,7 +266,13 @@ def restartable_pulsar_app_provider(**kwds):
@nottest @nottest
@contextmanager @contextmanager
def test_pulsar_app(global_conf={}, app_conf={}, test_conf={}, staging_directory=None): def test_pulsar_app(
global_conf={},
app_conf={},
test_conf={},
staging_directory=None,
web=True,
):
clean_staging_directory = False clean_staging_directory = False
if staging_directory is None: if staging_directory is None:
staging_directory = mkdtemp() staging_directory = mkdtemp()
...@@ -277,7 +285,7 @@ def test_pulsar_app(global_conf={}, app_conf={}, test_conf={}, staging_directory ...@@ -277,7 +285,7 @@ def test_pulsar_app(global_conf={}, app_conf={}, test_conf={}, staging_directory
app_conf["file_cache_dir"] = cache_directory app_conf["file_cache_dir"] = cache_directory
app_conf["ensure_cleanup"] = True app_conf["ensure_cleanup"] = True
try: try:
with _yield_app(global_conf, app_conf, test_conf) as app: with _yield_app(global_conf, app_conf, test_conf, web) as app:
yield app yield app
finally: finally:
to_clean = [cache_directory] to_clean = [cache_directory]
...@@ -293,14 +301,26 @@ def test_pulsar_app(global_conf={}, app_conf={}, test_conf={}, staging_directory ...@@ -293,14 +301,26 @@ def test_pulsar_app(global_conf={}, app_conf={}, test_conf={}, staging_directory
@contextmanager @contextmanager
def _yield_app(global_conf, app_conf, test_conf): def _yield_app(global_conf, app_conf, test_conf, web):
# Yield either wsgi webapp of the underlying pulsar
# app object if the web layer is not needed.
try: try:
from pulsar.web.wsgi import app_factory if web:
app = app_factory(global_conf, **app_conf) from pulsar.web.wsgi import app_factory
yield TestApp(app, **test_conf) app = app_factory(global_conf, **app_conf)
yield TestApp(app, **test_conf)
else:
from pulsar.main import load_app_configuration
from pulsar.core import PulsarApp
app_conf = load_app_configuration(local_conf=app_conf)
app = PulsarApp(**app_conf)
yield app
finally: finally:
try: try:
app.shutdown() shutdown_args = []
if not web:
shutdown_args.append(2)
app.shutdown(*shutdown_args)
except Exception: except Exception:
pass pass
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment