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 | 34 | from IPython.utils.contexts import preserve_keys |
|
35 | 35 | from IPython.utils.path import filefind |
|
36 | 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 | #----------------------------------------------------------------------------- |
@@ -198,6 +198,12 b' class InteractiveShellApp(Configurable):' | |||
|
198 | 198 | ) |
|
199 | 199 | shell = Instance('IPython.core.interactiveshell.InteractiveShellABC') |
|
200 | 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() | |
|
206 | ||
|
201 | 207 | def init_path(self): |
|
202 | 208 | """Add current working directory, '', to sys.path""" |
|
203 | 209 | if sys.path[0] != '': |
@@ -393,6 +393,7 b' class IPKernelApp(BaseIPythonApplication, InteractiveShellApp):' | |||
|
393 | 393 | stdin_socket=self.stdin_socket, |
|
394 | 394 | log=self.log, |
|
395 | 395 | profile_dir=self.profile_dir, |
|
396 | user_ns=self.user_ns, | |
|
396 | 397 | ) |
|
397 | 398 | kernel.record_ports(self.ports) |
|
398 | 399 | self.kernel = kernel |
@@ -458,6 +459,7 b' class IPKernelApp(BaseIPythonApplication, InteractiveShellApp):' | |||
|
458 | 459 | except KeyboardInterrupt: |
|
459 | 460 | pass |
|
460 | 461 | |
|
462 | launch_new_instance = IPKernelApp.launch_instance | |
|
461 | 463 | |
|
462 | 464 | def main(): |
|
463 | 465 | """Run an IPKernel as an application""" |
@@ -334,7 +334,7 b' class TerminalIPythonApp(BaseIPythonApplication, InteractiveShellApp):' | |||
|
334 | 334 | # so the banner shows *before* all extension loading stuff. |
|
335 | 335 | self.shell = TerminalInteractiveShell.instance(parent=self, |
|
336 | 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 | 338 | self.shell.configurables.append(self) |
|
339 | 339 | |
|
340 | 340 | def init_banner(self): |
General Comments 0
You need to be logged in to leave comments.
Login now