diff --git a/IPython/frontend/prefilterfrontend.py b/IPython/frontend/prefilterfrontend.py index f1b941c..8479132 100644 --- a/IPython/frontend/prefilterfrontend.py +++ b/IPython/frontend/prefilterfrontend.py @@ -92,8 +92,10 @@ This is the wx frontend, by Gael Varoquaux. This is EXPERIMENTAL code.""" LineFrontEndBase.__init__(self, *args, **kwargs) # XXX: Hack: mix the two namespaces - self.shell.user_ns = self.ipython0.user_ns - self.shell.user_global_ns = self.ipython0.user_global_ns + self.shell.user_ns.update(self.ipython0.user_ns) + self.ipython0.user_ns = self.shell.user_ns + self.shell.user_global_ns.update(self.ipython0.user_global_ns) + self.ipython0.user_global_ns = self.shell.user_global_ns self.shell.output_trap = RedirectorOutputTrap( out_callback=self.write, diff --git a/IPython/frontend/tests/test_prefilterfrontend.py b/IPython/frontend/tests/test_prefilterfrontend.py index f786170..665a2c5 100644 --- a/IPython/frontend/tests/test_prefilterfrontend.py +++ b/IPython/frontend/tests/test_prefilterfrontend.py @@ -17,6 +17,7 @@ import string from IPython.ipapi import get as get_ipython0 from IPython.frontend.prefilterfrontend import PrefilterFrontEnd +from copy import deepcopy class TestPrefilterFrontEnd(PrefilterFrontEnd): @@ -49,6 +50,23 @@ class TestPrefilterFrontEnd(PrefilterFrontEnd): PrefilterFrontEnd._on_enter(self) +def isolate_ipython0(func): + """ Decorator to isolate execution that involves an iptyhon0. + """ + def my_func(*args, **kwargs): + ipython0 = get_ipython0().IP + user_ns = deepcopy(ipython0.user_ns) + global_ns = deepcopy(ipython0.global_ns) + try: + func(*args, **kwargs) + finally: + ipython0.user_ns = user_ns + ipython0.global_ns = global_ns + + return my_func + + +@isolate_ipython0 def test_execution(): """ Test execution of a command. """ @@ -59,6 +77,7 @@ def test_execution(): assert out_value == '1\n' +@isolate_ipython0 def test_multiline(): """ Test execution of a multiline command. """ @@ -84,6 +103,7 @@ def test_multiline(): assert out_value == '1\n' +@isolate_ipython0 def test_capture(): """ Test the capture of output in different channels. """ @@ -102,6 +122,7 @@ def test_capture(): assert out_value == '1' +@isolate_ipython0 def test_magic(): """ Test the magic expansion and history. @@ -114,6 +135,7 @@ def test_magic(): assert out_value == 'Interactive namespace is empty.\n' +@isolate_ipython0 def test_help(): """ Test object inspection. """ @@ -133,6 +155,7 @@ def test_help(): #assert out_value.split()[-1] == 'foobar' +@isolate_ipython0 def test_completion(): """ Test command-line completion. """