Example #1
0
    def test_shell_override(self):
        command = self._makeOne()
        ipshell = dummy.DummyShell()
        bpshell = dummy.DummyShell()
        dshell = dummy.DummyShell()

        self._makeEntryPoints(command, {})

        command.default_runner = dshell

        shell = command.make_shell()
        self.assertEqual(shell, dshell)

        command.args.python_shell = 'ipython'
        self.assertRaises(ValueError, command.make_shell)

        self._makeEntryPoints(command, {
            'ipython': ipshell,
            'bpython': bpshell,
            'python': dshell,
        })

        command.args.python_shell = 'ipython'
        shell = command.make_shell()
        self.assertEqual(shell, ipshell)

        command.args.python_shell = 'bpython'
        shell = command.make_shell()
        self.assertEqual(shell, bpshell)

        command.args.python_shell = 'python'
        shell = command.make_shell()
        self.assertEqual(shell, dshell)
Example #2
0
    def test_command_loads_default_shell_with_unknown_shell(self):
        command = self._makeOne()
        out_calls = []

        def out(msg):
            out_calls.append(msg)

        command.out = out

        shell = dummy.DummyShell()
        bad_shell = dummy.DummyShell()

        self._makeEntryPoints(command, {
            'ipython': lambda: bad_shell,
            'bpython': lambda: bad_shell,
        })

        command.make_default_shell = lambda: shell
        command.options.python_shell = 'unknown_python_shell'
        result = command.run()
        self.assertEqual(result, 1)
        self.assertEqual(
            out_calls, ['could not find a shell named "unknown_python_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.assertTrue(self.bootstrap.closer.called)
Example #3
0
    def test_command_loads_ipython(self):
        command = self._makeOne()
        shell = dummy.DummyShell()
        bad_shell = dummy.DummyShell()
        self._makeEntryPoints(
            command,
            {
                'ipython': shell,
                'bpython': bad_shell,
            }
        )

        command.args.python_shell = 'ipython'

        command.run()
        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':self.bootstrap.root,
            'registry':self.bootstrap.registry,
            'request':self.bootstrap.request,
            'root_factory':self.bootstrap.root_factory,
        })
        self.assertTrue(self.bootstrap.closer.called)
        self.assertTrue(shell.help)
Example #4
0
 def test_command_loads_default_shell_with_unknown_shell(self):
     command = self._makeOne()
     shell = dummy.DummyShell()
     bad_shell = dummy.DummyShell()
     command.make_ipython_v0_11_shell = lambda: bad_shell
     command.make_ipython_v0_10_shell = lambda: bad_shell
     command.make_bpython_shell = lambda: bad_shell
     command.make_default_shell = lambda: shell
     command.options.python_shell = 'unknow_python_shell'
     command.run()
     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': self.bootstrap.root,
             'registry': self.bootstrap.registry,
             'request': self.bootstrap.request,
             'root_factory': self.bootstrap.root_factory,
         })
     self.assertEqual(bad_shell.env, {})
     self.assertTrue(self.bootstrap.closer.called)
     self.assertTrue(shell.help)
Example #5
0
    def test_shell_ordering(self):
        command = self._makeOne()
        ipshell = dummy.DummyShell()
        bpshell = dummy.DummyShell()
        dshell = dummy.DummyShell()
        command.make_ipython_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_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)
Example #6
0
    def test_shell_ordering(self):
        command = self._makeOne()
        ipshell = dummy.DummyShell()
        bpshell = dummy.DummyShell()
        dshell = dummy.DummyShell()

        self._makeEntryPoints(
            command,
            {
                'ipython': ipshell,
                'bpython': bpshell,
                'python': dshell,
            }
        )

        command.default_runner = dshell

        command.preferred_shells = ['ipython', 'bpython']
        shell = command.make_shell()
        self.assertEqual(shell, ipshell)

        command.preferred_shells = ['bpython', 'python']
        shell = command.make_shell()
        self.assertEqual(shell, bpshell)

        command.preferred_shells = ['python', 'ipython']
        shell = command.make_shell()
        self.assertEqual(shell, dshell)
Example #7
0
    def test_shell_ipython_ordering(self):
        command = self._makeOne()
        shell0_11 = dummy.DummyShell()
        shell0_10 = dummy.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)
Example #8
0
    def test_command_loads_setup_from_options(self):
        command = self._makeOne()

        def setup(env):
            env['a'] = 1
            env['root'] = 'root override'

        model = dummy.Dummy()
        self.config_factory.items = [('setup', 'abc'), ('m', model)]
        command.options.setup = setup
        shell = dummy.DummyShell()
        command.run(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)
Example #9
0
    def test_command_setup(self):
        command = self._makeOne()

        def setup(env):
            env['a'] = 1
            env['root'] = 'root override'

        self.config_factory.items = [('setup', setup)]
        shell = dummy.DummyShell()
        command.run(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,
            })
        self.assertTrue(self.bootstrap.closer.called)
        self.assertTrue(shell.help)
Example #10
0
    def test_list_shells(self):
        command = self._makeOne()

        dshell = dummy.DummyShell()
        out_calls = []

        def out(msg):
            out_calls.append(msg)

        command.out = out

        self._makeEntryPoints(
            command,
            {
                'ipython': dshell,
                'python': dshell,
            }
        )

        command.args.list = True
        result = command.run()
        self.assertEqual(result, 0)
        self.assertEqual(out_calls, [
            'Available shells:',
            '  ipython',
            '  python',
        ])
Example #11
0
    def test_command_errors_with_unknown_shell(self):
        command = self._makeOne()
        out_calls = []

        def out(msg):
            out_calls.append(msg)

        command.out = out

        shell = dummy.DummyShell()

        self._makeEntryPoints(command, {})

        command.default_runner = shell
        command.args.python_shell = 'unknown_python_shell'
        result = command.run()
        self.assertEqual(result, 1)
        self.assertEqual(
            out_calls, ['could not find a shell named "unknown_python_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.assertTrue(self.bootstrap.closer.called)
Example #12
0
    def test_command_loads_setup_from_options(self):
        command = self._makeOne()

        def setup(env):
            env['a'] = 1
            env['root'] = 'root override'

        model = dummy.Dummy()
        self.loader.settings = {'pshell': {'setup': 'abc', 'm': model}}
        command.args.setup = setup
        shell = dummy.DummyShell()
        command.run(shell)
        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)
Example #13
0
    def test_command_loads_check_variable_override_order(self):
        command = self._makeOne()
        model = dummy.Dummy()

        def setup(env):
            env['a'] = 1
            env['m'] = 'model override'
            env['root'] = 'root override'

        self.loader.settings = {'pshell': {'setup': setup, 'm': model}}
        shell = dummy.DummyShell()
        command.run(shell)
        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)
Example #14
0
 def test_command_default_shell_option(self):
     command = self._makeOne()
     ipshell = dummy.DummyShell()
     dshell = dummy.DummyShell()
     self._makeEntryPoints(command, {
         'ipython': ipshell,
         'python': dshell,
     })
     self.loader.settings = {
         'pshell': {
             'default_shell': 'bpython python\nipython'
         }
     }
     command.run()
     self.assertEqual(self.bootstrap.a[0], '/foo/bar/myapp.ini#myapp')
     self.assertTrue(dshell.called)
Example #15
0
 def test_command_default_shell_option(self):
     command = self._makeOne()
     ipshell = dummy.DummyShell()
     dshell = dummy.DummyShell()
     self._makeEntryPoints(command, {
         'ipython': ipshell,
         'python': dshell,
     })
     self.config_factory.items = [('default_shell',
                                   'bpython python\nipython')]
     command.run()
     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.assertTrue(dshell.called)
Example #16
0
    def test_shell_entry_points(self):
        command = self._makeOne()
        dshell = dummy.DummyShell()

        self._makeEntryPoints(command, {
            'ipython': lambda: dshell,
            'bpython': lambda: dhell,
        })

        command.make_default_shell = lambda: None
        shell = command.make_shell()
        self.assertEqual(shell, dshell)
Example #17
0
 def test_command_custom_section_override(self):
     command = self._makeOne()
     dummy_ = dummy.Dummy()
     self.config_factory.items = [('app', dummy_), ('root', dummy_),
                                  ('registry', dummy_), ('request', dummy_)]
     shell = dummy.DummyShell()
     command.run(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':dummy_, 'root':dummy_, 'registry':dummy_, 'request':dummy_,
         'root_factory':self.bootstrap.root_factory,
     })
     self.assertTrue(self.bootstrap.closer.called)
     self.assertTrue(shell.help)
Example #18
0
    def test_command_loads_default_shell(self):
        command = self._makeOne()
        shell = dummy.DummyShell()
        self._makeEntryPoints(command, {})

        command.default_runner = shell
        command.run()
        self.assertEqual(self.bootstrap.a[0], '/foo/bar/myapp.ini#myapp')
        self.assertEqual(
            shell.env, {
                'app': self.bootstrap.app,
                'root': self.bootstrap.root,
                'registry': self.bootstrap.registry,
                'request': self.bootstrap.request,
                'root_factory': self.bootstrap.root_factory,
            })
        self.assertTrue(self.bootstrap.closer.called)
        self.assertTrue(shell.help)
Example #19
0
 def test_command_loads_pythonstartup(self):
     command = self._makeOne()
     command.pystartup = (os.path.abspath(
         os.path.join(os.path.dirname(__file__), 'pystartup.py')))
     shell = dummy.DummyShell()
     command.run(shell)
     self.assertEqual(self.bootstrap.a[0], '/foo/bar/myapp.ini#myapp')
     self.assertEqual(
         shell.env, {
             'app': self.bootstrap.app,
             'root': self.bootstrap.root,
             'registry': self.bootstrap.registry,
             'request': self.bootstrap.request,
             'root_factory': self.bootstrap.root_factory,
             'foo': 1,
         })
     self.assertTrue(self.bootstrap.closer.called)
     self.assertTrue(shell.help)
Example #20
0
 def test_command_loads_custom_items(self):
     command = self._makeOne()
     model = dummy.Dummy()
     self.config_factory.items = [('m', model)]
     shell = dummy.DummyShell()
     command.run(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':self.bootstrap.root,
         'registry':self.bootstrap.registry,
         'request':self.bootstrap.request,
         'root_factory':self.bootstrap.root_factory,
         'm':model,
     })
     self.assertTrue(self.bootstrap.closer.called)
     self.assertTrue(shell.help)
Example #21
0
 def test_command_loads_custom_items(self):
     command = self._makeOne()
     model = dummy.Dummy()
     user = dummy.Dummy()
     self.loader.settings = {'pshell': {'m': model, 'User': user}}
     shell = dummy.DummyShell()
     command.run(shell)
     self.assertEqual(self.bootstrap.a[0], '/foo/bar/myapp.ini#myapp')
     self.assertEqual(
         shell.env, {
             'app': self.bootstrap.app,
             'root': self.bootstrap.root,
             'registry': self.bootstrap.registry,
             'request': self.bootstrap.request,
             'root_factory': self.bootstrap.root_factory,
             'm': model,
             'User': user,
         })
     self.assertTrue(self.bootstrap.closer.called)
     self.assertTrue(shell.help)
Example #22
0
    def test_command_setup(self):
        command = self._makeOne()

        def setup(env):
            env['a'] = 1
            env['root'] = 'root override'
            env['none'] = None

        self.loader.settings = {'pshell': {'setup': setup}}
        shell = dummy.DummyShell()
        command.run(shell)
        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,
                'none': None,
            })
        self.assertTrue(self.bootstrap.closer.called)
        self.assertTrue(shell.help)
Example #23
0
 def test_command_custom_section_override(self):
     command = self._makeOne()
     dummy_ = dummy.Dummy()
     self.loader.settings = {
         'pshell': {
             'app': dummy_,
             'root': dummy_,
             'registry': dummy_,
             'request': dummy_
         }
     }
     shell = dummy.DummyShell()
     command.run(shell)
     self.assertEqual(self.bootstrap.a[0], '/foo/bar/myapp.ini#myapp')
     self.assertEqual(
         shell.env, {
             'app': dummy_,
             'root': dummy_,
             'registry': dummy_,
             'request': dummy_,
             'root_factory': self.bootstrap.root_factory,
         })
     self.assertTrue(self.bootstrap.closer.called)
     self.assertTrue(shell.help)