diff options
| author | Michael Merickel <michael@merickel.org> | 2011-08-16 02:07:16 -0500 |
|---|---|---|
| committer | Michael Merickel <michael@merickel.org> | 2011-08-16 02:07:16 -0500 |
| commit | a5d9ff4e135feb8a8132cfd93dcb51fa2eacd35d (patch) | |
| tree | c721283dd09128d58741f083a8a80a43b0154d8c | |
| parent | 87b0c53830fed9de60bd97996630b4b20228df09 (diff) | |
| download | pyramid-a5d9ff4e135feb8a8132cfd93dcb51fa2eacd35d.tar.gz pyramid-a5d9ff4e135feb8a8132cfd93dcb51fa2eacd35d.tar.bz2 pyramid-a5d9ff4e135feb8a8132cfd93dcb51fa2eacd35d.zip | |
Added support for --import option to pshell.
| -rw-r--r-- | pyramid/paster.py | 9 | ||||
| -rw-r--r-- | pyramid/tests/test_paster.py | 23 |
2 files changed, 32 insertions, 0 deletions
diff --git a/pyramid/paster.py b/pyramid/paster.py index 87abdddd4..99ead1af3 100644 --- a/pyramid/paster.py +++ b/pyramid/paster.py @@ -129,6 +129,11 @@ class PShellCommand(PCommand): action='store_true', dest='disable_ipython', help="Don't use IPython even if it is available") + parser.add_option('--import-script', + dest='use_script', + help=("Execute the script and import all variables from " + "a dotted Python path. This option will override " + "the 'import' key in the [pshell] ini section.")) ConfigParser = ConfigParser.ConfigParser # testing @@ -176,6 +181,10 @@ class PShellCommand(PCommand): env_help['root_factory'] = ( 'Default root factory used to create `root`.') + # override use_script with command-line options + if self.options.use_script: + self.use_script = self.options.use_script + if self.use_script: # store the env before muddling it with the script orig_env = env.copy() diff --git a/pyramid/tests/test_paster.py b/pyramid/tests/test_paster.py index 45e36f129..cb30dcc12 100644 --- a/pyramid/tests/test_paster.py +++ b/pyramid/tests/test_paster.py @@ -21,6 +21,7 @@ class TestPShellCommand(unittest.TestCase): class Options(object): pass self.options = Options() self.options.disable_ipython = True + self.options.use_script = None cmd.options = self.options return cmd @@ -196,6 +197,28 @@ class TestPShellCommand(unittest.TestCase): self.assertTrue(self.bootstrap.closer.called) self.assertTrue(shell.help) + def test_command_loads_use_script_override(self): + command = self._makeOne() + model = Dummy() + self.config_factory.items = [('import', 'abc'), + ('m', model)] + command.options.use_script = 'pyramid.tests.pshellapp' + shell = DummyShell() + command.command(shell) + self.assertTrue(self.config_factory.parser) + self.assertEqual(self.config_factory.parser.filename, + '/foo/bar/myapp.ini') + self.assertEqual(self.bootstrap.a[0], '/foo/bar/myapp.ini#myapp') + self.assertEqual(shell.env, { + 'app':self.bootstrap.app, 'root':'root override', + 'registry':self.bootstrap.registry, + 'request':self.bootstrap.request, + 'root_factory':self.bootstrap.root_factory, + 'a':1, 'm':model, + }) + self.assertTrue(self.bootstrap.closer.called) + self.assertTrue(shell.help) + def test_command_custom_section_override(self): command = self._makeOne() dummy = Dummy() |
