Michael Merickel
2011-08-16 a5d9ff4e135feb8a8132cfd93dcb51fa2eacd35d
Added support for --import option to pshell.
2 files modified
32 ■■■■■ changed files
pyramid/paster.py 9 ●●●●● patch | view | raw | blame | history
pyramid/tests/test_paster.py 23 ●●●●● patch | view | raw | blame | history
pyramid/paster.py
@@ -129,6 +129,11 @@
                      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 @@
        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()
pyramid/tests/test_paster.py
@@ -21,6 +21,7 @@
            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 @@
        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()