##// END OF EJS Templates
Merge pull request #4016 from takluyver/IPython-start-funcs...
Min RK -
r12189:d3e2f732 merge
parent child Browse files
Show More
@@ -0,0 +1,17 b''
1 import nose.tools as nt
2
3 from .test_embed_kernel import setup, teardown, setup_kernel
4
5 TIMEOUT = 15
6
7 def test_ipython_start_kernel_userns():
8 cmd = ('from IPython import start_kernel\n'
9 'ns = {"tre": 123}\n'
10 'start_kernel(user_ns=ns)')
11
12 with setup_kernel(cmd) as client:
13 msg_id = client.object_info('tre')
14 msg = client.get_shell_msg(block=True, timeout=TIMEOUT)
15 content = msg['content']
16 assert content['found']
17 nt.assert_equal(content['string_form'], u'123') No newline at end of file
@@ -34,7 +34,7 b' from IPython.utils import py3compat'
34 from IPython.utils.contexts import preserve_keys
34 from IPython.utils.contexts import preserve_keys
35 from IPython.utils.path import filefind
35 from IPython.utils.path import filefind
36 from IPython.utils.traitlets import (
36 from IPython.utils.traitlets import (
37 Unicode, Instance, List, Bool, CaselessStrEnum
37 Unicode, Instance, List, Bool, CaselessStrEnum, Dict
38 )
38 )
39
39
40 #-----------------------------------------------------------------------------
40 #-----------------------------------------------------------------------------
@@ -197,6 +197,12 b' class InteractiveShellApp(Configurable):'
197 """
197 """
198 )
198 )
199 shell = Instance('IPython.core.interactiveshell.InteractiveShellABC')
199 shell = Instance('IPython.core.interactiveshell.InteractiveShellABC')
200
201 user_ns = Dict(default_value=None)
202 def _user_ns_changed(self, name, old, new):
203 if self.shell is not None:
204 self.shell.user_ns = new
205 self.shell.init_user_ns()
200
206
201 def init_path(self):
207 def init_path(self):
202 """Add current working directory, '', to sys.path"""
208 """Add current working directory, '', to sys.path"""
@@ -393,6 +393,7 b' class IPKernelApp(BaseIPythonApplication, InteractiveShellApp):'
393 stdin_socket=self.stdin_socket,
393 stdin_socket=self.stdin_socket,
394 log=self.log,
394 log=self.log,
395 profile_dir=self.profile_dir,
395 profile_dir=self.profile_dir,
396 user_ns=self.user_ns,
396 )
397 )
397 kernel.record_ports(self.ports)
398 kernel.record_ports(self.ports)
398 self.kernel = kernel
399 self.kernel = kernel
@@ -458,6 +459,7 b' class IPKernelApp(BaseIPythonApplication, InteractiveShellApp):'
458 except KeyboardInterrupt:
459 except KeyboardInterrupt:
459 pass
460 pass
460
461
462 launch_new_instance = IPKernelApp.launch_instance
461
463
462 def main():
464 def main():
463 """Run an IPKernel as an application"""
465 """Run an IPKernel as an application"""
@@ -334,7 +334,7 b' class TerminalIPythonApp(BaseIPythonApplication, InteractiveShellApp):'
334 # so the banner shows *before* all extension loading stuff.
334 # so the banner shows *before* all extension loading stuff.
335 self.shell = TerminalInteractiveShell.instance(parent=self,
335 self.shell = TerminalInteractiveShell.instance(parent=self,
336 display_banner=False, profile_dir=self.profile_dir,
336 display_banner=False, profile_dir=self.profile_dir,
337 ipython_dir=self.ipython_dir)
337 ipython_dir=self.ipython_dir, user_ns=self.user_ns)
338 self.shell.configurables.append(self)
338 self.shell.configurables.append(self)
339
339
340 def init_banner(self):
340 def init_banner(self):
General Comments 0
You need to be logged in to leave comments. Login now