Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
Pulsar
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
NDIP
Pulsar
Commits
44d536b8
Commit
44d536b8
authored
9 years ago
by
John Chilton
Browse files
Options
Downloads
Patches
Plain Diff
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
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
test/test_utils.py
+29
-9
29 additions, 9 deletions
test/test_utils.py
with
29 additions
and
9 deletions
test/test_utils.py
+
29
−
9
View file @
44d536b8
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment