From 6078eeabab06e701f1122b2bb6ef2a7e3b4c5eb3 2009-04-23 22:25:50 From: Fernando Perez Date: 2009-04-23 22:25:50 Subject: [PATCH] Fixes to frontend tests. Mostly robustness and isolation improvements. --- diff --git a/IPython/frontend/prefilterfrontend.py b/IPython/frontend/prefilterfrontend.py index e874333..ceb21c2 100644 --- a/IPython/frontend/prefilterfrontend.py +++ b/IPython/frontend/prefilterfrontend.py @@ -64,13 +64,18 @@ class PrefilterFrontEnd(LineFrontEndBase): debug = False - def __init__(self, ipython0=None, *args, **kwargs): + def __init__(self, ipython0=None, argv=None, *args, **kwargs): """ Parameters: ----------- ipython0: an optional ipython0 instance to use for command prefiltering and completion. + + argv : list, optional + Used as the instance's argv value. If not given, [] is used. """ + if argv is None: + argv = [] # This is a hack to avoid the IPython exception hook to trigger # on exceptions (https://bugs.launchpad.net/bugs/337105) # XXX: This is horrible: module-leve monkey patching -> side @@ -98,7 +103,7 @@ class PrefilterFrontEnd(LineFrontEndBase): old_rawinput = __builtin__.raw_input __builtin__.raw_input = my_rawinput # XXX: argv=[] is a bit bold. - ipython0 = make_IPython(argv=[], + ipython0 = make_IPython(argv=argv, user_ns=self.shell.user_ns, user_global_ns=self.shell.user_global_ns) __builtin__.raw_input = old_rawinput diff --git a/IPython/frontend/tests/test_prefilterfrontend.py b/IPython/frontend/tests/test_prefilterfrontend.py index 53e7b8b..317f1ed 100644 --- a/IPython/frontend/tests/test_prefilterfrontend.py +++ b/IPython/frontend/tests/test_prefilterfrontend.py @@ -12,14 +12,16 @@ __docformat__ = "restructuredtext en" # in the file COPYING, distributed as part of this software. #------------------------------------------------------------------------------- +from copy import copy, deepcopy from cStringIO import StringIO import string from nose.tools import assert_equal -from IPython.ipapi import get as get_ipython0 from IPython.frontend.prefilterfrontend import PrefilterFrontEnd -from copy import copy, deepcopy +from IPython.ipapi import get as get_ipython0 +from IPython.testing.plugin.ipdoctest import default_argv + def safe_deepcopy(d): """ Deep copy every key of the given dict, when possible. Elsewhere @@ -45,7 +47,7 @@ class TestPrefilterFrontEnd(PrefilterFrontEnd): def __init__(self): self.out = StringIO() - PrefilterFrontEnd.__init__(self) + PrefilterFrontEnd.__init__(self,argv=default_argv()) # Some more code for isolation (yeah, crazy) self._on_enter() self.out.flush() @@ -64,7 +66,7 @@ def isolate_ipython0(func): """ Decorator to isolate execution that involves an iptyhon0. Notes - ------ + ----- Apply only to functions with no arguments. Nose skips functions with arguments. @@ -153,6 +155,12 @@ def test_magic(): This test is fairly fragile and will break when magics change. """ f = TestPrefilterFrontEnd() + # Before checking the interactive namespace, make sure it's clear (it can + # otherwise pick up things stored in the user's local db) + f.input_buffer += '%reset -f' + f._on_enter() + f.complete_current_input() + # Now, run the %who magic and check output f.input_buffer += '%who' f._on_enter() out_value = f.out.getvalue()