diff options
| author | Chris McDonough <chrism@plope.com> | 2011-04-17 00:43:46 -0400 |
|---|---|---|
| committer | Chris McDonough <chrism@plope.com> | 2011-04-17 00:43:46 -0400 |
| commit | 158433b14b0db863f3246f74025b404487b5d0b8 (patch) | |
| tree | 1c162310cbead67f943f55e0040b28953657f6b4 | |
| parent | 9ba4c93dbeb5b92ef33a41475d349cd7707a5a30 (diff) | |
| download | pyramid-158433b14b0db863f3246f74025b404487b5d0b8.tar.gz pyramid-158433b14b0db863f3246f74025b404487b5d0b8.tar.bz2 pyramid-158433b14b0db863f3246f74025b404487b5d0b8.zip | |
condition coverage
| -rw-r--r-- | pyramid/paster.py | 20 | ||||
| -rw-r--r-- | pyramid/tests/test_paster.py | 41 |
2 files changed, 50 insertions, 11 deletions
diff --git a/pyramid/paster.py b/pyramid/paster.py index def9a6f3e..f9f8925d7 100644 --- a/pyramid/paster.py +++ b/pyramid/paster.py @@ -91,7 +91,7 @@ class PShellCommand(PCommand): command will almost certainly fail. """ - summary = "Open an interactive shell with a pyramid app loaded" + summary = "Open an interactive shell with a Pyramid application loaded" min_args = 2 max_args = 2 @@ -103,10 +103,11 @@ class PShellCommand(PCommand): help="Don't use IPython even if it is available") def command(self, IPShell=_marker): - if IPShell is _marker: - try: #pragma no cover + # IPShell passed to command method is for testing purposes + if IPShell is _marker: # pragma: no cover + try: from IPython.Shell import IPShell - except ImportError: #pragma no cover + except ImportError: IPShell = None cprt =('Type "help" for more information. "root" is the Pyramid app ' 'root object, "registry" is the Pyramid registry object.') @@ -116,16 +117,17 @@ class PShellCommand(PCommand): app = self.get_app(config_file, section_name, loadapp=self.loadapp[0]) root, closer = self.get_root(app) shell_globals = {'root':root, 'registry':app.registry} - if IPShell is not None and not self.options.disable_ipython: + + if (IPShell is None) or self.options.disable_ipython: try: - shell = IPShell(argv=[], user_ns=shell_globals) - shell.IP.BANNER = shell.IP.BANNER + '\n\n' + banner - shell.mainloop() + self.interact[0](banner, local=shell_globals) finally: closer() else: try: - self.interact[0](banner, local=shell_globals) + shell = IPShell(argv=[], user_ns=shell_globals) + shell.IP.BANNER = shell.IP.BANNER + '\n\n' + banner + shell.mainloop() finally: closer() diff --git a/pyramid/tests/test_paster.py b/pyramid/tests/test_paster.py index e000e29d4..07ec4f7b7 100644 --- a/pyramid/tests/test_paster.py +++ b/pyramid/tests/test_paster.py @@ -42,7 +42,7 @@ class TestPShellCommand(unittest.TestCase): def _makeOne(self): return self._getTargetClass()('pshell') - def test_command_ipython_disabled(self): + def test_command_ipshell_is_None_ipython_enabled(self): command = self._makeOne() interact = DummyInteractor() app = DummyApp() @@ -52,7 +52,7 @@ class TestPShellCommand(unittest.TestCase): command.args = ('/foo/bar/myapp.ini', 'myapp') class Options(object): pass command.options = Options() - command.options.disable_ipython =True + command.options.disable_ipython = False command.command(IPShell=None) self.assertEqual(loadapp.config_name, 'config:/foo/bar/myapp.ini') self.assertEqual(loadapp.section_name, 'myapp') @@ -66,6 +66,30 @@ class TestPShellCommand(unittest.TestCase): self.failUnless(interact.banner) self.assertEqual(len(app.threadlocal_manager.popped), 1) + def test_command_ipshell_is_not_None_ipython_disabled(self): + command = self._makeOne() + interact = DummyInteractor() + app = DummyApp() + loadapp = DummyLoadApp(app) + command.interact = (interact,) + command.loadapp = (loadapp,) + command.args = ('/foo/bar/myapp.ini', 'myapp') + class Options(object): pass + command.options = Options() + command.options.disable_ipython = True + command.command(IPShell='notnone') + 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), 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, + 'registry':dummy_registry}) + self.failUnless(interact.banner) + self.assertEqual(len(app.threadlocal_manager.popped), 1) + def test_command_ipython_enabled(self): command = self._makeOne() app = DummyApp() @@ -167,6 +191,19 @@ class TestPRoutesCommand(unittest.TestCase): self.assertEqual(result, None) self.assertEqual(L, []) + def test_no_mapper(self): + command = self._makeOne() + command._get_mapper = lambda *arg:None + L = [] + command.out = L.append + app = DummyApp() + loadapp = DummyLoadApp(app) + command.loadapp = (loadapp,) + command.args = ('/foo/bar/myapp.ini', 'myapp') + result = command.command() + self.assertEqual(result, None) + self.assertEqual(L, []) + def test_single_route_no_route_registered(self): command = self._makeOne() route = DummyRoute('a', '/a') |
