diff options
| author | Chris McDonough <chrism@agendaless.com> | 2010-06-23 17:16:09 +0000 |
|---|---|---|
| committer | Chris McDonough <chrism@agendaless.com> | 2010-06-23 17:16:09 +0000 |
| commit | 62f5af501a1a90bdc41e0dfb38cbda7e10121f71 (patch) | |
| tree | e85bd52b4dcaddef966d05338a8ea7e7f37251c9 | |
| parent | 8989b3d7eae74b1720b72de46c8d7c7c31fc5119 (diff) | |
| download | pyramid-62f5af501a1a90bdc41e0dfb38cbda7e10121f71.tar.gz pyramid-62f5af501a1a90bdc41e0dfb38cbda7e10121f71.tar.bz2 pyramid-62f5af501a1a90bdc41e0dfb38cbda7e10121f71.zip | |
- Undocumented hook: make ``get_app`` and ``get_root`` of the
``repoze.bfg.paster.BFGShellCommand`` hookable in cases where
endware may interfere with the default versions.
| -rw-r--r-- | CHANGES.txt | 7 | ||||
| -rw-r--r-- | repoze/bfg/paster.py | 6 | ||||
| -rw-r--r-- | repoze/bfg/tests/test_paster.py | 54 |
3 files changed, 64 insertions, 3 deletions
diff --git a/CHANGES.txt b/CHANGES.txt index cac15589e..65690e73e 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,6 +1,13 @@ Next release ============ +Features +-------- + +- Undocumented hook: make ``get_app`` and ``get_root`` of the + ``repoze.bfg.paster.BFGShellCommand`` hookable in cases where + endware may interfere with the default versions. + Documentation ------------- diff --git a/repoze/bfg/paster.py b/repoze/bfg/paster.py index e0d17f6b4..e8ce46ce2 100644 --- a/repoze/bfg/paster.py +++ b/repoze/bfg/paster.py @@ -74,6 +74,8 @@ class BFGShellCommand(Command): interact = (interact,) # for testing loadapp = (loadapp,) # for testing + get_app = staticmethod(get_app) # hook point + get_root = staticmethod(get_root) # hook point verbose = 3 def __init__(self, *arg, **kw): @@ -93,8 +95,8 @@ class BFGShellCommand(Command): banner = "Python %s on %s\n%s" % (sys.version, sys.platform, cprt) config_file, section_name = self.args self.logging_file_config(config_file) - app = get_app(config_file, section_name, loadapp=self.loadapp[0]) - root, closer = get_root(app) + app = self.get_app(config_file, section_name, loadapp=self.loadapp[0]) + root, closer = self.get_root(app) if IPShell is not None and not self.options.disable_ipython: try: shell = IPShell(argv=[], user_ns={'root':root}) diff --git a/repoze/bfg/tests/test_paster.py b/repoze/bfg/tests/test_paster.py index c2bbb12ad..147e9854d 100644 --- a/repoze/bfg/tests/test_paster.py +++ b/repoze/bfg/tests/test_paster.py @@ -15,7 +15,6 @@ class TestBFGShellCommand(unittest.TestCase): loadapp = DummyLoadApp(app) command.interact = (interact,) command.loadapp = (loadapp,) - command.IPShellEmbed = True # fake out command.args = ('/foo/bar/myapp.ini', 'myapp') class Options(object): pass command.options = Options() @@ -55,6 +54,59 @@ class TestBFGShellCommand(unittest.TestCase): self.failUnless('\n\n' in dummy_shell_factory.shell.IP.BANNER) self.assertEqual(len(app.threadlocal_manager.popped), 1) + def test_command_get_app_hookable(self): + from paste.deploy import loadapp + command = self._makeOne() + app = DummyApp() + apped = [] + def get_app(*arg, **kw): + apped.append((arg, kw)) + return app + command.get_app = get_app + interact = DummyInteractor() + app = DummyApp() + command.interact = (interact,) + command.args = ('/foo/bar/myapp.ini', 'myapp') + class Options(object): pass + command.options = Options() + command.options.disable_ipython =True + command.command(IPShell=None) + self.assertEqual(len(app.threadlocal_manager.pushed), 1) + pushed = app.threadlocal_manager.pushed[0] + self.assertEqual(pushed['registry'], dummy_registry) + self.assertEqual(pushed['request'].registry, dummy_registry) + self.assertEqual(interact.local, {'root':dummy_root}) + self.failUnless(interact.banner) + self.assertEqual(len(app.threadlocal_manager.popped), 1) + self.assertEqual(apped, [(('/foo/bar/myapp.ini', 'myapp'), + {'loadapp': loadapp})]) + + def test_command_get_root_hookable(self): + command = self._makeOne() + interact = DummyInteractor() + app = DummyApp() + loadapp = DummyLoadApp(app) + command.interact = (interact,) + command.loadapp = (loadapp,) + root = Dummy() + apps = [] + def get_root(app): + apps.append(app) + return root, lambda *arg: None + command.get_root =get_root + command.args = ('/foo/bar/myapp.ini', 'myapp') + class Options(object): pass + command.options = Options() + command.options.disable_ipython =True + command.command(IPShell=None) + self.assertEqual(loadapp.config_name, 'config:/foo/bar/myapp.ini') + self.assertEqual(loadapp.section_name, 'myapp') + self.failUnless(loadapp.relative_to) + self.assertEqual(len(app.threadlocal_manager.pushed), 0) + self.assertEqual(interact.local, {'root':root}) + self.failUnless(interact.banner) + self.assertEqual(apps, [app]) + class TestGetApp(unittest.TestCase): def _callFUT(self, config_file, section_name, loadapp): from repoze.bfg.paster import get_app |
