summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris McDonough <chrism@agendaless.com>2008-08-30 17:50:22 +0000
committerChris McDonough <chrism@agendaless.com>2008-08-30 17:50:22 +0000
commit7970bf558b303578e65fe95d064cf7408721cbe3 (patch)
treef8bf351989d990f9698b94d5ffc94bd4c7af16f8
parente6b6cce0e019964ba9168e33907c4b4a929ae733 (diff)
downloadpyramid-7970bf558b303578e65fe95d064cf7408721cbe3.tar.gz
pyramid-7970bf558b303578e65fe95d064cf7408721cbe3.tar.bz2
pyramid-7970bf558b303578e65fe95d064cf7408721cbe3.zip
Make WSGIApplicationEvent test work again.
-rw-r--r--repoze/bfg/registry.py27
-rw-r--r--repoze/bfg/router.py12
-rw-r--r--repoze/bfg/tests/test_router.py29
3 files changed, 43 insertions, 25 deletions
diff --git a/repoze/bfg/registry.py b/repoze/bfg/registry.py
index 9301b950b..7d27a7126 100644
--- a/repoze/bfg/registry.py
+++ b/repoze/bfg/registry.py
@@ -33,20 +33,19 @@ def setRegistryManager(manager): # for unit tests
return old_registry_manager
def makeRegistry(filename, package, options=None, lock=threading.Lock()):
- # This is absurd and probably not worth it. We want to try to
- # push our ZCML-defined configuration into an app-local component
- # registry in order to allow more than one bfg app to live in the
- # same process space without one unnecessarily stomping on the
- # other's component registrations (although I suspect directives
- # that side effects are going to fail). The only way to do that
- # currently is to override zope.component.getGlobalSiteManager for
- # the duration of the ZCML includes. We acquire a lock in case
- # another make_app runs in a different thread simultaneously, in a
- # vain attempt to prevent mixing of registrations. There's not
- # much we can do about non-make_app code that tries to use the
- # global site manager API directly in a different thread while we
- # hold the lock. Those registrations will end up in our
- # application's registry.
+ # We push our ZCML-defined configuration into an app-local
+ # component registry in order to allow more than one bfg app to
+ # live in the same process space without one unnecessarily
+ # stomping on the other's component registrations (although I
+ # suspect directives that have side effects are going to fail).
+ # The only way to do that currently is to override
+ # zope.component.getGlobalSiteManager for the duration of the ZCML
+ # includes. We acquire a lock in case another make_app runs in a
+ # different thread simultaneously, in a vain attempt to prevent
+ # mixing of registrations. There's not much we can do about
+ # non-make_app code that tries to use the global site manager API
+ # directly in a different thread while we hold the lock. Those
+ # registrations will end up in our application's registry.
lock.acquire()
try:
registry = Components(package.__name__)
diff --git a/repoze/bfg/router.py b/repoze/bfg/router.py
index af63af387..26a313d8a 100644
--- a/repoze/bfg/router.py
+++ b/repoze/bfg/router.py
@@ -19,6 +19,7 @@ from repoze.bfg.interfaces import ISecurityPolicy
from repoze.bfg.interfaces import IRequest
from repoze.bfg.registry import registry_manager
+from repoze.bfg.registry import makeRegistry
_marker = ()
@@ -89,12 +90,15 @@ def make_app(root_policy, package=None, filename='configure.zcml',
containing bfg-specific runtime options, with each key
representing the option and the key's value representing the
specific option value, e.g. ``{'reload_templates':True}``"""
- from repoze.bfg.registry import makeRegistry
registry = makeRegistry(filename, package, options)
app = Router(root_policy, registry)
- registry_manager.set(registry)
- dispatch(WSGIApplicationCreatedEvent(app))
- registry_manager.clear()
+
+ try:
+ registry_manager.set(registry)
+ dispatch(WSGIApplicationCreatedEvent(app))
+ finally:
+ registry_manager.clear()
+
return app
diff --git a/repoze/bfg/tests/test_router.py b/repoze/bfg/tests/test_router.py
index 87dcbba66..ed08710f1 100644
--- a/repoze/bfg/tests/test_router.py
+++ b/repoze/bfg/tests/test_router.py
@@ -287,15 +287,30 @@ class MakeAppTests(unittest.TestCase, PlacelessSetup):
def test_event(self):
def subscriber(event):
event.app.created = True
- from zope.component import getGlobalSiteManager
from repoze.bfg.interfaces import IWSGIApplicationCreatedEvent
+ import repoze.bfg.router
+ from zope.component import getGlobalSiteManager
+ old_registry_manager = repoze.bfg.router.registry_manager
+ repoze.bfg.router.registry_manager = DummyRegistryManager()
getGlobalSiteManager().registerHandler(
- subscriber, (IWSGIApplicationCreatedEvent,))
- from repoze.bfg.tests import fixtureapp
- make_app = self._getFUT()
- rootpolicy = make_rootpolicy(None)
- app = make_app(rootpolicy, fixtureapp)
- assert app.created is True
+ subscriber,
+ (IWSGIApplicationCreatedEvent,)
+ )
+ try:
+ from repoze.bfg.tests import fixtureapp
+ make_app = self._getFUT()
+ rootpolicy = make_rootpolicy(None)
+ app = make_app(rootpolicy, fixtureapp)
+ assert app.created is True
+ finally:
+ repoze.bfg.router.registry_manager = old_registry_manager
+
+class DummyRegistryManager:
+ def set(self, registry):
+ pass
+
+ def clear(self):
+ pass
class DummyContext:
pass