Permalink
Browse files

backported changes from commits #ce1d0, 3808f and 99513.

  • Loading branch information...
mmerickel committed Nov 22, 2011
1 parent cdc3b98 commit ebb663f86e1c1db29506e9926c1699716c6f9f74
Showing with 72 additions and 17 deletions.
  1. +22 −16 pyramid/paster.py
  2. +50 −1 pyramid/tests/test_paster.py
View
@@ -129,7 +129,7 @@ class PShellCommand(PCommand):
parser = Command.standard_parser(simulate=True)
parser.add_option('-p', '--python-shell',
action='store', type='string', dest='python_shell',
- default = '', help='ipython | bpython | python')
+ default='', help='ipython | bpython | python')
parser.add_option('--setup',
dest='setup',
help=("A callable that will be passed the environment "
@@ -221,30 +221,36 @@ def command(self, shell=None):
for var in sorted(self.object_help.keys()):
help += '\n %-12s %s' % (var, self.object_help[var])
+ if shell is None:
+ shell = self.make_shell()
+
+ try:
+ shell(env, help)
+ finally:
+ closer()
+
+ def make_shell(self):
+ shell = None
user_shell = self.options.python_shell.lower()
if not user_shell:
+ shell = self.make_ipython_v0_11_shell()
if shell is None:
- shell = self.make_ipython_v0_11_shell()
- if shell is None:
- shell = self.make_ipython_v0_10_shell()
- if shell is None:
- shell = self.make_bpython_shell()
+ shell = self.make_ipython_v0_10_shell()
+ if shell is None:
+ shell = self.make_bpython_shell()
- if shell is None and user_shell == 'ipython':
+ elif user_shell == 'ipython':
shell = self.make_ipython_v0_11_shell()
if shell is None:
shell = self.make_ipython_v0_10_shell()
- if shell is None and user_shell == 'bpython':
+ elif user_shell == 'bpython':
shell = self.make_bpython_shell()
if shell is None:
shell = self.make_default_shell()
- try:
- shell(env, help)
- finally:
- closer()
+ return shell
def make_default_shell(self, interact=interact):
def shell(env, help):
@@ -254,15 +260,15 @@ def shell(env, help):
interact(banner, local=env)
return shell
- def make_bpython_shell(self, BPShellFactory=None):
- if BPShellFactory is None: # pragma: no cover
+ def make_bpython_shell(self, BPShell=None):
+ if BPShell is None: # pragma: no cover
try:
from bpython import embed
- BPShellFactory = embed
+ BPShell = embed
except ImportError:
return None
def shell(env, help):
- BPShell = BPShellFactory(locals_=env, banner=help + '\n')
+ BPShell(locals_=env, banner=help + '\n')
return shell
def make_ipython_v0_11_shell(self, IPShellFactory=None):
@@ -81,7 +81,7 @@ def test_command_loads_default_shell(self):
self.assertTrue(self.bootstrap.closer.called)
self.assertTrue(shell.help)
- def test_command_loads_default_shell_with_unknow_shell(self):
+ def test_command_loads_default_shell_with_unknown_shell(self):
command = self._makeOne()
shell = DummyShell()
bad_shell = DummyShell()
@@ -170,6 +170,55 @@ def test_command_loads_bpython_shell(self):
self.assertTrue(self.bootstrap.closer.called)
self.assertTrue(shell.banner)
+ def test_shell_ipython_ordering(self):
+ command = self._makeOne()
+ shell0_11 = DummyShell()
+ shell0_10 = DummyShell()
+ command.make_ipython_v0_11_shell = lambda: shell0_11
+ command.make_ipython_v0_10_shell = lambda: shell0_10
+ command.make_bpython_shell = lambda: None
+ shell = command.make_shell()
+ self.assertEqual(shell, shell0_11)
+
+ command.options.python_shell = 'ipython'
+ shell = command.make_shell()
+ self.assertEqual(shell, shell0_11)
+
+ def test_shell_ordering(self):
+ command = self._makeOne()
+ ipshell = DummyShell()
+ bpshell = DummyShell()
+ dshell = DummyShell()
+ command.make_ipython_v0_11_shell = lambda: None
+ command.make_ipython_v0_10_shell = lambda: None
+ command.make_bpython_shell = lambda: None
+ command.make_default_shell = lambda: dshell
+
+ shell = command.make_shell()
+ self.assertEqual(shell, dshell)
+
+ command.options.python_shell = 'ipython'
+ shell = command.make_shell()
+ self.assertEqual(shell, dshell)
+
+ command.options.python_shell = 'bpython'
+ shell = command.make_shell()
+ self.assertEqual(shell, dshell)
+
+ command.make_ipython_v0_11_shell = lambda: ipshell
+ command.make_bpython_shell = lambda: bpshell
+ command.options.python_shell = 'ipython'
+ shell = command.make_shell()
+ self.assertEqual(shell, ipshell)
+
+ command.options.python_shell = 'bpython'
+ shell = command.make_shell()
+ self.assertEqual(shell, bpshell)
+
+ command.options.python_shell = 'python'
+ shell = command.make_shell()
+ self.assertEqual(shell, dshell)
+
def test_command_loads_custom_items(self):
command = self._makeOne()
model = Dummy()

0 comments on commit ebb663f

Please sign in to comment.