Skip to content

Commit

Permalink
using pyramid.paster.bootstrap as context manager Pylons#1822
Browse files Browse the repository at this point in the history
  • Loading branch information
marioidival committed Jun 3, 2015
1 parent c1dbb50 commit 1d29cb5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
6 changes: 4 additions & 2 deletions pyramid/paster.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
from contextlib import contextmanager

from paste.deploy import (
loadapp,
Expand Down Expand Up @@ -81,6 +82,7 @@ def _getpathsec(config_uri, name):
section = name
return path, section

@contextmanager
def bootstrap(config_uri, request=None, options=None):
""" Load a WSGI application from the PasteDeploy config file specified
by ``config_uri``. The environment will be configured as if it is
Expand Down Expand Up @@ -121,7 +123,7 @@ def bootstrap(config_uri, request=None, options=None):
for you if none is provided. You can mutate the request's ``environ``
later to setup a specific host/port/scheme/etc.
``options`` Is passed to get_app for use as variable assignments like
``options`` Is passed to get_app for use as variable assignments like
{'http_port': 8080} and then use %(http_port)s in the
config file.
Expand All @@ -131,5 +133,5 @@ def bootstrap(config_uri, request=None, options=None):
app = get_app(config_uri, options=options)
env = prepare(request)
env['app'] = app
return env
yield env

8 changes: 4 additions & 4 deletions pyramid/tests/test_paster.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,10 @@ def tearDown(self):
def test_it_request_with_registry(self):
request = DummyRequest({})
request.registry = dummy_registry
result = self._callFUT('/foo/bar/myapp.ini', request)
self.assertEqual(result['app'], self.app)
self.assertEqual(result['root'], self.root)
self.assertTrue('closer' in result)
with self._callFUT('/foo/bar/myapp.ini', request) as result:
self.assertEqual(result['app'], self.app)
self.assertEqual(result['root'], self.root)
self.assertTrue('closer' in result)

class Dummy:
pass
Expand Down

0 comments on commit 1d29cb5

Please sign in to comment.