From 6080a84e81482b89fc4d4cc2d82b6557dfb32abf 2010-07-29 14:11:36 From: epatters Date: 2010-07-29 14:11:36 Subject: [PATCH] Merge branch 'master' of git://github.com/ipython/ipython into qtfrontend and fix conflicts in setupbase.py. Conflicts: setupbase.py --- diff --git a/IPython/Shell.py b/IPython/Shell.py index 7bdd833..7600f17 100644 --- a/IPython/Shell.py +++ b/IPython/Shell.py @@ -36,7 +36,7 @@ from IPython.core.embed import InteractiveShellEmbed as IPShellEmbed def start(user_ns=None, embedded=False): """Return an instance of :class:`InteractiveShell`.""" if embedded: - return InteractiveShellEmbed(user_ns=user_ns) + return IPShellEmbed(user_ns=user_ns) else: - return InteractiveShell(user_ns=user_ns) + return IPShell(user_ns=user_ns) diff --git a/IPython/core/crashhandler.py b/IPython/core/crashhandler.py index 5c9c3ab..00f0a68 100644 --- a/IPython/core/crashhandler.py +++ b/IPython/core/crashhandler.py @@ -115,12 +115,11 @@ class CrashHandler(object): # Use this ONLY for developer debugging (keep commented out for release) #color_scheme = 'Linux' # dbg - try: rptdir = self.app.ipython_dir except: rptdir = os.getcwd() - if not os.path.isdir(rptdir): + if rptdir is None or not os.path.isdir(rptdir): rptdir = os.getcwd() report_name = os.path.join(rptdir,self.crash_report_fname) # write the report filename into the instance dict so it can get diff --git a/IPython/core/magic.py b/IPython/core/magic.py index 21a817a..621743b 100644 --- a/IPython/core/magic.py +++ b/IPython/core/magic.py @@ -1126,32 +1126,40 @@ Currently the magic system has the following functions:\n""" Examples -------- + + We first fully reset the namespace so your output looks identical to + this example for pedagogical reasons; in practice you do not need a + full reset. - In [1]: a=1; b=2; c=3; b1m=4; b2m=5; b3m=6; b4m=7; b2s=8 + In [1]: %reset -f - In [2]: who_ls - Out[2]: ['a', 'b', 'b1', 'b1m', 'b2m', 'b2s', 'b3m', 'b4m', 'c'] + Now, with a clean namespace we can make a few variables and use + %reset_selective to only delete names that match our regexp: - In [3]: %reset_selective -f b[2-3]m + In [2]: a=1; b=2; c=3; b1m=4; b2m=5; b3m=6; b4m=7; b2s=8 - In [4]: who_ls - Out[4]: ['a', 'b', 'b1', 'b1m', 'b2s', 'c'] + In [3]: who_ls + Out[3]: ['a', 'b', 'b1m', 'b2m', 'b2s', 'b3m', 'b4m', 'c'] - In [5]: %reset_selective -f d + In [4]: %reset_selective -f b[2-3]m - In [6]: who_ls - Out[6]: ['a', 'b', 'b1', 'b1m', 'b2s', 'c'] + In [5]: who_ls + Out[5]: ['a', 'b', 'b1m', 'b2s', 'b4m', 'c'] - In [7]: %reset_selective -f c - - In [8]: who_ls - Out[8]:['a', 'b', 'b1', 'b1m', 'b2s'] + In [6]: %reset_selective -f d - In [9]: %reset_selective -f b - - In [10]: who_ls - Out[10]: ['a'] - + In [7]: who_ls + Out[7]: ['a', 'b', 'b1m', 'b2s', 'b4m', 'c'] + + In [8]: %reset_selective -f c + + In [9]: who_ls + Out[9]: ['a', 'b', 'b1m', 'b2s', 'b4m'] + + In [10]: %reset_selective -f b + + In [11]: who_ls + Out[11]: ['a'] """ opts, regex = self.parse_options(parameter_s,'f') diff --git a/IPython/core/prefilter.py b/IPython/core/prefilter.py index 747db7c..f2b80fe 100755 --- a/IPython/core/prefilter.py +++ b/IPython/core/prefilter.py @@ -995,7 +995,6 @@ class HelpHandler(PrefilterHandler): # Pass any other exceptions through to the normal handler return normal_handler.handle(line_info) else: - raise # If the code compiles ok, we should handle it normally return normal_handler.handle(line_info) diff --git a/IPython/core/tests/test_autocall.py b/IPython/core/tests/test_autocall.py new file mode 100644 index 0000000..8db5b49 --- /dev/null +++ b/IPython/core/tests/test_autocall.py @@ -0,0 +1,43 @@ +"""These kinds of tests are less than ideal, but at least they run. + +This was an old test that was being run interactively in the top-level tests/ +directory, which we are removing. For now putting this here ensures at least +we do run the test, though ultimately this functionality should all be tested +with better-isolated tests that don't rely on the global instance in iptest. +""" + +def doctest_autocall(): + """ + In [1]: def f1(a,b,c): + ...: return a+b+c + ...: + + In [2]: def f2(a): + ...: return a + a + ...: + + In [3]: ;f2 a b c + Out[3]: 'a b ca b c' + + In [4]: assert _ == "a b ca b c" + + In [5]: ,f1 a b c + Out[5]: 'abc' + + In [6]: assert _ == 'abc' + + In [7]: print _ + abc + + In [8]: /f1 1,2,3 + Out[8]: 6 + + In [9]: assert _ == 6 + + In [10]: /f2 4 + Out[10]: 8 + + In [11]: assert _ == 8 + + In [11]: del f1, f2 + """ diff --git a/test/test_handlers.py b/IPython/core/tests/test_handlers.py similarity index 56% rename from test/test_handlers.py rename to IPython/core/tests/test_handlers.py index 495239b..3e96661 100644 --- a/test/test_handlers.py +++ b/IPython/core/tests/test_handlers.py @@ -1,12 +1,41 @@ -"""Test the various handlers which do the actual rewriting of the line.""" +"""Tests for input handlers. +""" +#----------------------------------------------------------------------------- +# Module imports +#----------------------------------------------------------------------------- -from StringIO import StringIO -import sys -sys.path.append('..') +# third party +import nose.tools as nt + +# our own packages +from IPython.core import autocall +from IPython.testing import decorators as dec +from IPython.testing.globalipapp import get_ipython + +#----------------------------------------------------------------------------- +# Globals +#----------------------------------------------------------------------------- + +# Get the public instance of IPython +ip = get_ipython() failures = [] num_tests = 0 +#----------------------------------------------------------------------------- +# Test functions +#----------------------------------------------------------------------------- + +class CallableIndexable(object): + def __getitem__(self, idx): return True + def __call__(self, *args, **kws): return True + + +class Autocallable(autocall.IPyAutocall): + def __call__(self): + return "called" + + def run(tests): """Loop through a list of (pre, post) inputs, where pre is the string handed to ipython, and post is how that string looks after it's been @@ -24,87 +53,56 @@ def run(tests): pre, post, actual)) -# Shutdown stdout/stderr so that ipython isn't noisy during tests. Have to -# do this *before* importing IPython below. -# -# NOTE: this means that, if you stick print statements into code as part of -# debugging, you won't see the results (unless you comment out some of the -# below). I keep on doing this, so apparently it's easy. Or I am an idiot. -old_stdout = sys.stdout -old_stderr = sys.stderr - -sys.stdout = StringIO() -sys.stderr = StringIO() - -import IPython -import IPython.ipapi - -IPython.Shell.start() -ip = IPython.ipapi.get() - -class CallableIndexable(object): - def __getitem__(self, idx): return True - def __call__(self, *args, **kws): return True - - -try: +def test_handlers(): # alias expansion - + # We're using 'true' as our syscall of choice because it doesn't # write anything to stdout. # Turn off actual execution of aliases, because it's noisy old_system_cmd = ip.system ip.system = lambda cmd: None - - - ip.IP.alias_table['an_alias'] = (0, 'true') + + + ip.alias_manager.alias_table['an_alias'] = (0, 'true') # These are useful for checking a particular recursive alias issue - ip.IP.alias_table['top'] = (0, 'd:/cygwin/top') - ip.IP.alias_table['d'] = (0, 'true') - run([("an_alias", '_ip.system("true ")'), # alias + ip.alias_manager.alias_table['top'] = (0, 'd:/cygwin/top') + ip.alias_manager.alias_table['d'] = (0, 'true') + run([("an_alias", 'get_ipython().system("true ")'), # alias # Below: recursive aliases should expand whitespace-surrounded # chars, *not* initial chars which happen to be aliases: - ("top", '_ip.system("d:/cygwin/top ")'), + ("top", 'get_ipython().system("d:/cygwin/top ")'), ]) ip.system = old_system_cmd - call_idx = CallableIndexable() - ip.to_user_ns('call_idx') + ip.user_ns['call_idx'] = call_idx # For many of the below, we're also checking that leading whitespace # turns off the esc char, which it should unless there is a continuation # line. run([('"no change"', '"no change"'), # normal - ("!true", '_ip.system("true")'), # shell_escapes - ("!! true", '_ip.magic("sx true")'), # shell_escapes + magic - ("!!true", '_ip.magic("sx true")'), # shell_escapes + magic - ("%lsmagic", '_ip.magic("lsmagic ")'), # magic - ("lsmagic", '_ip.magic("lsmagic ")'), # magic - ("a = b # PYTHON-MODE", '_i'), # emacs -- avoids _in cache + ("!true", 'get_ipython().system("true")'), # shell_escapes + ("!! true", 'get_ipython().magic("sx true")'), # shell_escapes + magic + ("!!true", 'get_ipython().magic("sx true")'), # shell_escapes + magic + ("%lsmagic", 'get_ipython().magic("lsmagic ")'), # magic + ("lsmagic", 'get_ipython().magic("lsmagic ")'), # magic + #("a = b # PYTHON-MODE", '_i'), # emacs -- avoids _in cache # post-esc-char whitespace goes inside - ("! true", '_ip.system(" true")'), - - # Leading whitespace generally turns off escape characters - (" ! true", ' ! true'), - (" !true", ' !true'), + ("! true", 'get_ipython().system(" true")'), # handle_help # These are weak tests -- just looking at what the help handlers # logs, which is not how it really does its work. But it still # lets us check the key paths through the handler. - + ("x=1 # what?", "x=1 # what?"), # no help if valid python - ("len?", "#?len"), # this is what help logs when it runs - ("len??", "#?len?"), - ("?len", "#?len"), ]) # multi_line_specials - ip.options.multi_line_specials = 0 + ip.prefilter_manager.multi_line_specials = False # W/ multi_line_specials off, leading ws kills esc chars/autoexpansion run([ ('if 1:\n !true', 'if 1:\n !true'), @@ -112,18 +110,16 @@ try: ('if 1:\n an_alias', 'if 1:\n an_alias'), ]) - ip.options.multi_line_specials = 1 + ip.prefilter_manager.multi_line_specials = True # initial indents must be preserved. run([ - ('if 1:\n !true', 'if 1:\n _ip.system("true")'), - ('if 1:\n lsmagic', 'if 1:\n _ip.magic("lsmagic ")'), - ('if 1:\n an_alias', 'if 1:\n _ip.system("true ")'), + ('if 1:\n !true', 'if 1:\n get_ipython().system("true")'), + ('if 2:\n lsmagic', 'if 2:\n get_ipython().magic("lsmagic ")'), + ('if 1:\n an_alias', 'if 1:\n get_ipython().system("true ")'), # Weird one - ('if 1:\n !!true', 'if 1:\n _ip.magic("sx true")'), - + ('if 1:\n !!true', 'if 1:\n get_ipython().magic("sx true")'), - # Even with m_l_s on, all esc_chars except ! are off - ('if 1:\n %lsmagic', 'if 1:\n %lsmagic'), + # Even with m_l_s on, autocall is off even with special chars ('if 1:\n /fun 1 2', 'if 1:\n /fun 1 2'), ('if 1:\n ;fun 1 2', 'if 1:\n ;fun 1 2'), ('if 1:\n ,fun 1 2', 'if 1:\n ,fun 1 2'), @@ -131,18 +127,12 @@ try: # What about !! ]) - # Objects which are instances of IPyAutocall are *always* autocalled - import IPython.ipapi - class Autocallable(IPython.ipapi.IPyAutocall): - def __call__(self): - return "called" - autocallable = Autocallable() - ip.to_user_ns('autocallable') + ip.user_ns['autocallable'] = autocallable # auto - ip.options.autocall = 0 + ip.magic('autocall 0') # Only explicit escapes or instances of IPyAutocallable should get # expanded run([ @@ -152,7 +142,7 @@ try: (";list 1 2 3", 'list("1 2 3")'), ("/len range(1,4)", 'len(range(1,4))'), ]) - ip.options.autocall = 1 + ip.magic('autocall 1') run([ (",list 1 2 3", 'list("1", "2", "3")'), (";list 1 2 3", 'list("1 2 3")'), @@ -166,8 +156,7 @@ try: ('call_idx 1', 'call_idx(1)'), ('len', 'len '), # only at 2 does it auto-call on single args ]) - - ip.options.autocall = 2 + ip.magic('autocall 2') run([ (",list 1 2 3", 'list("1", "2", "3")'), (";list 1 2 3", 'list("1 2 3")'), @@ -180,23 +169,6 @@ try: # This is what's different: ('len', 'len()'), # only at 2 does it auto-call on single args ]) - ip.options.autocall = 1 - - # Ignoring handle_emacs, 'cause it doesn't do anything. -finally: - sys.stdout = old_stdout - sys.stderr = old_stderr - - - - -num_f = len(failures) -#if verbose: -# print - + ip.magic('autocall 1') -print "%s tests run, %s failure%s" % (num_tests, - num_f, - num_f != 1 and "s" or "") -for f in failures: - print f + nt.assert_equals(failures, []) diff --git a/IPython/core/tests/test_iplib.py b/IPython/core/tests/test_iplib.py index 2fa6633..8b4276c 100644 --- a/IPython/core/tests/test_iplib.py +++ b/IPython/core/tests/test_iplib.py @@ -243,3 +243,37 @@ SystemExit Traceback (most recent call last) SystemExit: (2, 'Mode = exit') """ + + +def test_runlines(): + import textwrap + ip.runlines(['a = 10', 'a+=1']) + ip.runlines('assert a == 11\nassert 1') + + nt.assert_equals(ip.user_ns['a'], 11) + complex = textwrap.dedent(""" + if 1: + print "hello" + if 1: + print "world" + + if 2: + print "foo" + + if 3: + print "bar" + + if 4: + print "bar" + + """) + # Simply verifies that this kind of input is run + ip.runlines(complex) + + +def test_db(): + """Test the internal database used for variable persistence.""" + ip.db['__unittest_'] = 12 + nt.assert_equals(ip.db['__unittest_'], 12) + del ip.db['__unittest_'] + assert '__unittest_' not in ip.db diff --git a/IPython/core/tests/test_magic.py b/IPython/core/tests/test_magic.py index efcecf7..7cf8d0e 100644 --- a/IPython/core/tests/test_magic.py +++ b/IPython/core/tests/test_magic.py @@ -267,8 +267,91 @@ def doctest_time(): Wall time: 0.00 s """ + def test_doctest_mode(): "Toggle doctest_mode twice, it should be a no-op and run without error" _ip.magic('doctest_mode') _ip.magic('doctest_mode') + + +def test_parse_options(): + """Tests for basic options parsing in magics.""" + # These are only the most minimal of tests, more should be added later. At + # the very least we check that basic text/unicode calls work OK. + nt.assert_equal(_ip.parse_options('foo', '')[1], 'foo') + nt.assert_equal(_ip.parse_options(u'foo', '')[1], u'foo') + + +def test_dirops(): + """Test various directory handling operations.""" + curpath = lambda :os.path.splitdrive(os.getcwd())[1].replace('\\','/') + + startdir = os.getcwd() + ipdir = _ip.ipython_dir + try: + _ip.magic('cd "%s"' % ipdir) + nt.assert_equal(curpath(), ipdir) + _ip.magic('cd -') + nt.assert_equal(curpath(), startdir) + _ip.magic('pushd "%s"' % ipdir) + nt.assert_equal(curpath(), ipdir) + _ip.magic('popd') + nt.assert_equal(curpath(), startdir) + finally: + os.chdir(startdir) + + +def check_cpaste(code, should_fail=False): + """Execute code via 'cpaste' and ensure it was executed, unless + should_fail is set. + """ + _ip.user_ns['code_ran'] = False + + src = StringIO() + src.write('\n') + src.write(code) + src.write('\n--\n') + src.seek(0) + + stdin_save = sys.stdin + sys.stdin = src + try: + _ip.magic('cpaste') + except: + if not should_fail: + raise AssertionError("Failure not expected : '%s'" % + code) + else: + assert _ip.user_ns['code_ran'] + if should_fail: + raise AssertionError("Failure expected : '%s'" % code) + finally: + sys.stdin = stdin_save + + +def test_cpaste(): + """Test cpaste magic""" + + def run(): + """Marker function: sets a flag when executed. + """ + _ip.user_ns['code_ran'] = True + return 'run' # return string so '+ run()' doesn't result in success + + tests = {'pass': ["> > > run()", + ">>> > run()", + "+++ run()", + "++ run()", + " >>> run()"], + + 'fail': ["+ + run()", + " ++ run()"]} + + _ip.user_ns['run'] = run + + for code in tests['pass']: + check_cpaste(code) + + for code in tests['fail']: + check_cpaste(code, should_fail=True) diff --git a/IPython/core/tests/test_prefilter.py b/IPython/core/tests/test_prefilter.py index 9b7161d..3575a98 100644 --- a/IPython/core/tests/test_prefilter.py +++ b/IPython/core/tests/test_prefilter.py @@ -53,7 +53,16 @@ def test_autocall_binops(): def test_issue114(): """Check that multiline string literals don't expand as magic see http://github.com/ipython/ipython/issues/#issue/114""" + template = '"""\n%s\n"""' - for mgk in ip.lsmagic(): - raw = template % mgk - yield nt.assert_equals(ip.prefilter(raw), raw) + # Store the current value of multi_line_specials and turn it off before + # running test, since it could be true (case in which the test doesn't make + # sense, as multiline string literals *will* expand as magic in that case). + msp = ip.prefilter_manager.multi_line_specials + ip.prefilter_manager.multi_line_specials = False + try: + for mgk in ip.lsmagic(): + raw = template % mgk + yield nt.assert_equals(ip.prefilter(raw), raw) + finally: + ip.prefilter_manager.multi_line_specials = msp diff --git a/IPython/frontend/cocoa/__init__.py b/IPython/deathrow/gui/__init__.py similarity index 100% rename from IPython/frontend/cocoa/__init__.py rename to IPython/deathrow/gui/__init__.py diff --git a/IPython/frontend/cocoa/tests/__init__.py b/IPython/deathrow/gui/wx/__init__.py similarity index 100% rename from IPython/frontend/cocoa/tests/__init__.py rename to IPython/deathrow/gui/wx/__init__.py diff --git a/IPython/gui/wx/ipshell_nonblocking.py b/IPython/deathrow/gui/wx/ipshell_nonblocking.py similarity index 100% rename from IPython/gui/wx/ipshell_nonblocking.py rename to IPython/deathrow/gui/wx/ipshell_nonblocking.py diff --git a/IPython/gui/wx/ipython_history.py b/IPython/deathrow/gui/wx/ipython_history.py similarity index 100% rename from IPython/gui/wx/ipython_history.py rename to IPython/deathrow/gui/wx/ipython_history.py diff --git a/IPython/gui/wx/ipython_view.py b/IPython/deathrow/gui/wx/ipython_view.py similarity index 100% rename from IPython/gui/wx/ipython_view.py rename to IPython/deathrow/gui/wx/ipython_view.py diff --git a/IPython/gui/wx/thread_ex.py b/IPython/deathrow/gui/wx/thread_ex.py similarity index 100% rename from IPython/gui/wx/thread_ex.py rename to IPython/deathrow/gui/wx/thread_ex.py diff --git a/IPython/gui/wx/wxIPython.py b/IPython/deathrow/gui/wx/wxIPython.py similarity index 100% rename from IPython/gui/wx/wxIPython.py rename to IPython/deathrow/gui/wx/wxIPython.py diff --git a/IPython/frontend/asyncfrontendbase.py b/IPython/deathrow/oldfrontend/asyncfrontendbase.py similarity index 100% rename from IPython/frontend/asyncfrontendbase.py rename to IPython/deathrow/oldfrontend/asyncfrontendbase.py diff --git a/IPython/frontend/tests/__init__.py b/IPython/deathrow/oldfrontend/cocoa/__init__.py similarity index 100% rename from IPython/frontend/tests/__init__.py rename to IPython/deathrow/oldfrontend/cocoa/__init__.py diff --git a/IPython/frontend/cocoa/cocoa_frontend.py b/IPython/deathrow/oldfrontend/cocoa/cocoa_frontend.py similarity index 100% rename from IPython/frontend/cocoa/cocoa_frontend.py rename to IPython/deathrow/oldfrontend/cocoa/cocoa_frontend.py diff --git a/IPython/frontend/cocoa/examples/IPython1Sandbox/English.lproj/InfoPlist.strings b/IPython/deathrow/oldfrontend/cocoa/examples/IPython1Sandbox/English.lproj/InfoPlist.strings similarity index 100% rename from IPython/frontend/cocoa/examples/IPython1Sandbox/English.lproj/InfoPlist.strings rename to IPython/deathrow/oldfrontend/cocoa/examples/IPython1Sandbox/English.lproj/InfoPlist.strings Binary files a/IPython/frontend/cocoa/examples/IPython1Sandbox/English.lproj/InfoPlist.strings and b/IPython/deathrow/oldfrontend/cocoa/examples/IPython1Sandbox/English.lproj/InfoPlist.strings differ diff --git a/IPython/frontend/cocoa/examples/IPython1Sandbox/English.lproj/MainMenu.xib b/IPython/deathrow/oldfrontend/cocoa/examples/IPython1Sandbox/English.lproj/MainMenu.xib similarity index 100% rename from IPython/frontend/cocoa/examples/IPython1Sandbox/English.lproj/MainMenu.xib rename to IPython/deathrow/oldfrontend/cocoa/examples/IPython1Sandbox/English.lproj/MainMenu.xib diff --git a/IPython/frontend/cocoa/examples/IPython1Sandbox/IPython1Sandbox.xcodeproj/project.pbxproj b/IPython/deathrow/oldfrontend/cocoa/examples/IPython1Sandbox/IPython1Sandbox.xcodeproj/project.pbxproj similarity index 100% rename from IPython/frontend/cocoa/examples/IPython1Sandbox/IPython1Sandbox.xcodeproj/project.pbxproj rename to IPython/deathrow/oldfrontend/cocoa/examples/IPython1Sandbox/IPython1Sandbox.xcodeproj/project.pbxproj diff --git a/IPython/frontend/cocoa/examples/IPython1Sandbox/IPython1SandboxAppDelegate.py b/IPython/deathrow/oldfrontend/cocoa/examples/IPython1Sandbox/IPython1SandboxAppDelegate.py similarity index 100% rename from IPython/frontend/cocoa/examples/IPython1Sandbox/IPython1SandboxAppDelegate.py rename to IPython/deathrow/oldfrontend/cocoa/examples/IPython1Sandbox/IPython1SandboxAppDelegate.py diff --git a/IPython/frontend/cocoa/examples/IPython1Sandbox/IPython1Sandbox_Prefix.pch b/IPython/deathrow/oldfrontend/cocoa/examples/IPython1Sandbox/IPython1Sandbox_Prefix.pch similarity index 100% rename from IPython/frontend/cocoa/examples/IPython1Sandbox/IPython1Sandbox_Prefix.pch rename to IPython/deathrow/oldfrontend/cocoa/examples/IPython1Sandbox/IPython1Sandbox_Prefix.pch diff --git a/IPython/frontend/cocoa/examples/IPython1Sandbox/IPythonCocoaController Tests-Info.plist b/IPython/deathrow/oldfrontend/cocoa/examples/IPython1Sandbox/IPythonCocoaController Tests-Info.plist similarity index 100% rename from IPython/frontend/cocoa/examples/IPython1Sandbox/IPythonCocoaController Tests-Info.plist rename to IPython/deathrow/oldfrontend/cocoa/examples/IPython1Sandbox/IPythonCocoaController Tests-Info.plist diff --git a/IPython/frontend/cocoa/examples/IPython1Sandbox/Info.plist b/IPython/deathrow/oldfrontend/cocoa/examples/IPython1Sandbox/Info.plist similarity index 100% rename from IPython/frontend/cocoa/examples/IPython1Sandbox/Info.plist rename to IPython/deathrow/oldfrontend/cocoa/examples/IPython1Sandbox/Info.plist diff --git a/IPython/frontend/cocoa/examples/IPython1Sandbox/main.m b/IPython/deathrow/oldfrontend/cocoa/examples/IPython1Sandbox/main.m similarity index 100% rename from IPython/frontend/cocoa/examples/IPython1Sandbox/main.m rename to IPython/deathrow/oldfrontend/cocoa/examples/IPython1Sandbox/main.m diff --git a/IPython/frontend/cocoa/examples/IPython1Sandbox/main.py b/IPython/deathrow/oldfrontend/cocoa/examples/IPython1Sandbox/main.py similarity index 100% rename from IPython/frontend/cocoa/examples/IPython1Sandbox/main.py rename to IPython/deathrow/oldfrontend/cocoa/examples/IPython1Sandbox/main.py diff --git a/IPython/frontend/cocoa/plugin/CocoaFrontendPlugin.xcodeproj/project.pbxproj b/IPython/deathrow/oldfrontend/cocoa/plugin/CocoaFrontendPlugin.xcodeproj/project.pbxproj similarity index 100% rename from IPython/frontend/cocoa/plugin/CocoaFrontendPlugin.xcodeproj/project.pbxproj rename to IPython/deathrow/oldfrontend/cocoa/plugin/CocoaFrontendPlugin.xcodeproj/project.pbxproj diff --git a/IPython/frontend/cocoa/plugin/IPythonCocoaFrontendLoader.py b/IPython/deathrow/oldfrontend/cocoa/plugin/IPythonCocoaFrontendLoader.py similarity index 100% rename from IPython/frontend/cocoa/plugin/IPythonCocoaFrontendLoader.py rename to IPython/deathrow/oldfrontend/cocoa/plugin/IPythonCocoaFrontendLoader.py diff --git a/IPython/frontend/cocoa/plugin/Makefile b/IPython/deathrow/oldfrontend/cocoa/plugin/Makefile similarity index 100% rename from IPython/frontend/cocoa/plugin/Makefile rename to IPython/deathrow/oldfrontend/cocoa/plugin/Makefile diff --git a/IPython/frontend/cocoa/plugin/Placeholder (Do Not Use)-Info.plist b/IPython/deathrow/oldfrontend/cocoa/plugin/Placeholder (Do Not Use)-Info.plist similarity index 100% rename from IPython/frontend/cocoa/plugin/Placeholder (Do Not Use)-Info.plist rename to IPython/deathrow/oldfrontend/cocoa/plugin/Placeholder (Do Not Use)-Info.plist diff --git a/IPython/frontend/cocoa/plugin/plugins.mk b/IPython/deathrow/oldfrontend/cocoa/plugin/plugins.mk similarity index 100% rename from IPython/frontend/cocoa/plugin/plugins.mk rename to IPython/deathrow/oldfrontend/cocoa/plugin/plugins.mk diff --git a/IPython/frontend/cocoa/plugin/setup.py b/IPython/deathrow/oldfrontend/cocoa/plugin/setup.py similarity index 100% rename from IPython/frontend/cocoa/plugin/setup.py rename to IPython/deathrow/oldfrontend/cocoa/plugin/setup.py diff --git a/IPython/frontend/wx/__init__.py b/IPython/deathrow/oldfrontend/cocoa/tests/__init__.py similarity index 100% rename from IPython/frontend/wx/__init__.py rename to IPython/deathrow/oldfrontend/cocoa/tests/__init__.py diff --git a/IPython/frontend/cocoa/tests/test_cocoa_frontend.py b/IPython/deathrow/oldfrontend/cocoa/tests/test_cocoa_frontend.py similarity index 100% rename from IPython/frontend/cocoa/tests/test_cocoa_frontend.py rename to IPython/deathrow/oldfrontend/cocoa/tests/test_cocoa_frontend.py diff --git a/IPython/frontend/frontendbase.py b/IPython/deathrow/oldfrontend/frontendbase.py similarity index 100% rename from IPython/frontend/frontendbase.py rename to IPython/deathrow/oldfrontend/frontendbase.py diff --git a/IPython/frontend/linefrontendbase.py b/IPython/deathrow/oldfrontend/linefrontendbase.py similarity index 100% rename from IPython/frontend/linefrontendbase.py rename to IPython/deathrow/oldfrontend/linefrontendbase.py diff --git a/IPython/frontend/prefilterfrontend.py b/IPython/deathrow/oldfrontend/prefilterfrontend.py similarity index 100% rename from IPython/frontend/prefilterfrontend.py rename to IPython/deathrow/oldfrontend/prefilterfrontend.py diff --git a/IPython/frontend/process/__init__.py b/IPython/deathrow/oldfrontend/process/__init__.py similarity index 100% rename from IPython/frontend/process/__init__.py rename to IPython/deathrow/oldfrontend/process/__init__.py diff --git a/IPython/frontend/process/killableprocess.py b/IPython/deathrow/oldfrontend/process/killableprocess.py similarity index 100% rename from IPython/frontend/process/killableprocess.py rename to IPython/deathrow/oldfrontend/process/killableprocess.py diff --git a/IPython/frontend/process/pipedprocess.py b/IPython/deathrow/oldfrontend/process/pipedprocess.py similarity index 100% rename from IPython/frontend/process/pipedprocess.py rename to IPython/deathrow/oldfrontend/process/pipedprocess.py diff --git a/IPython/frontend/process/winprocess.py b/IPython/deathrow/oldfrontend/process/winprocess.py similarity index 100% rename from IPython/frontend/process/winprocess.py rename to IPython/deathrow/oldfrontend/process/winprocess.py diff --git a/IPython/gui/__init__.py b/IPython/deathrow/oldfrontend/tests/__init__.py similarity index 100% rename from IPython/gui/__init__.py rename to IPython/deathrow/oldfrontend/tests/__init__.py diff --git a/IPython/frontend/tests/test_asyncfrontendbase.py b/IPython/deathrow/oldfrontend/tests/test_asyncfrontendbase.py similarity index 100% rename from IPython/frontend/tests/test_asyncfrontendbase.py rename to IPython/deathrow/oldfrontend/tests/test_asyncfrontendbase.py diff --git a/IPython/frontend/tests/test_frontendbase.py b/IPython/deathrow/oldfrontend/tests/test_frontendbase.py similarity index 100% rename from IPython/frontend/tests/test_frontendbase.py rename to IPython/deathrow/oldfrontend/tests/test_frontendbase.py diff --git a/IPython/frontend/tests/test_linefrontend.py b/IPython/deathrow/oldfrontend/tests/test_linefrontend.py similarity index 100% rename from IPython/frontend/tests/test_linefrontend.py rename to IPython/deathrow/oldfrontend/tests/test_linefrontend.py diff --git a/IPython/frontend/tests/test_prefilterfrontend.py b/IPython/deathrow/oldfrontend/tests/test_prefilterfrontend.py similarity index 100% rename from IPython/frontend/tests/test_prefilterfrontend.py rename to IPython/deathrow/oldfrontend/tests/test_prefilterfrontend.py diff --git a/IPython/frontend/tests/test_process.py b/IPython/deathrow/oldfrontend/tests/test_process.py similarity index 100% rename from IPython/frontend/tests/test_process.py rename to IPython/deathrow/oldfrontend/tests/test_process.py diff --git a/IPython/gui/wx/__init__.py b/IPython/deathrow/oldfrontend/wx/__init__.py similarity index 100% rename from IPython/gui/wx/__init__.py rename to IPython/deathrow/oldfrontend/wx/__init__.py diff --git a/IPython/frontend/wx/console_widget.py b/IPython/deathrow/oldfrontend/wx/console_widget.py similarity index 100% rename from IPython/frontend/wx/console_widget.py rename to IPython/deathrow/oldfrontend/wx/console_widget.py diff --git a/IPython/frontend/wx/ipythonx.py b/IPython/deathrow/oldfrontend/wx/ipythonx.py similarity index 100% rename from IPython/frontend/wx/ipythonx.py rename to IPython/deathrow/oldfrontend/wx/ipythonx.py diff --git a/IPython/frontend/wx/wx_frontend.py b/IPython/deathrow/oldfrontend/wx/wx_frontend.py similarity index 100% rename from IPython/frontend/wx/wx_frontend.py rename to IPython/deathrow/oldfrontend/wx/wx_frontend.py diff --git a/IPython/frontend/zopeinterface.py b/IPython/deathrow/oldfrontend/zopeinterface.py similarity index 100% rename from IPython/frontend/zopeinterface.py rename to IPython/deathrow/oldfrontend/zopeinterface.py diff --git a/test/test_prefilter.py b/IPython/deathrow/tests/test_prefilter.py similarity index 100% rename from test/test_prefilter.py rename to IPython/deathrow/tests/test_prefilter.py diff --git a/IPython/lib/irunner.py b/IPython/lib/irunner.py old mode 100644 new mode 100755 index 5b8162f..5c97cfa --- a/IPython/lib/irunner.py +++ b/IPython/lib/irunner.py @@ -306,8 +306,8 @@ class IPythonRunner(InteractiveRunner): args0 = ['--colors','NoColor', '-pi1','In [\\#]: ', '-pi2',' .\\D.: ', - '--noterm-title', - '--no-auto-indent'] + '--no-term-title', + '--no-autoindent'] if args is None: args = args0 else: args = args0 + args prompts = [r'In \[\d+\]: ',r' \.*: '] diff --git a/test/test_irunner.py b/IPython/lib/tests/test_irunner.py similarity index 92% rename from test/test_irunner.py rename to IPython/lib/tests/test_irunner.py index e5f4ca1..320654c 100755 --- a/test/test_irunner.py +++ b/IPython/lib/tests/test_irunner.py @@ -1,4 +1,3 @@ -#!/usr/bin/env python """Test suite for the irunner module. Not the most elegant or fine-grained, but it does cover at least the bulk @@ -13,7 +12,7 @@ import sys import unittest # IPython imports -from IPython import irunner +from IPython.lib import irunner # Testing code begins class RunnerTestCase(unittest.TestCase): @@ -29,12 +28,12 @@ class RunnerTestCase(unittest.TestCase): out = self.out.getvalue() #out = '' # this output contains nasty \r\n lineends, and the initial ipython - # banner. clean it up for comparison - output_l = output.split() - out_l = out.split() + # banner. clean it up for comparison, removing lines of whitespace + output_l = [l for l in output.splitlines() if l and not l.isspace()] + out_l = [l for l in out.splitlines() if l and not l.isspace()] mismatch = 0 - #if len(output_l) != len(out_l): - # self.fail('mismatch in number of lines') + if len(output_l) != len(out_l): + self.fail('mismatch in number of lines') for n in range(len(output_l)): # Do a line-by-line comparison ol1 = output_l[n].strip() @@ -53,7 +52,6 @@ class RunnerTestCase(unittest.TestCase): """Test the IPython runner.""" source = """ print 'hello, this is python' - # some more code x=1;y=2 x+y**2 @@ -99,11 +97,10 @@ In [7]: autocall 0 Automatic calling is: OFF In [8]: cos pi ------------------------------------------------------------- File "", line 1 cos pi ^ -: invalid syntax +SyntaxError: invalid syntax In [9]: cos(pi) @@ -163,6 +160,3 @@ hello, this is python that's all folks! """ self._test_runner(runner,source,output) - -if __name__ == '__main__': - unittest.main() diff --git a/IPython/testing/iptest.py b/IPython/testing/iptest.py index 2f8453f..76ac761 100644 --- a/IPython/testing/iptest.py +++ b/IPython/testing/iptest.py @@ -104,7 +104,6 @@ have['wx.aui'] = test_for('wx.aui') have['zope.interface'] = test_for('zope.interface') have['twisted'] = test_for('twisted') have['foolscap'] = test_for('foolscap') -have['objc'] = test_for('objc') have['pexpect'] = test_for('pexpect') have['gtk'] = test_for('gtk') have['gobject'] = test_for('gobject') @@ -154,7 +153,6 @@ def make_exclude(): ipjoin = lambda *paths: pjoin('IPython', *paths) exclusions = [ipjoin('external'), - ipjoin('frontend', 'process', 'winprocess.py'), # Deprecated old Shell and iplib modules, skip to avoid # warnings ipjoin('Shell'), @@ -175,19 +173,11 @@ def make_exclude(): ] if not have['wx']: - exclusions.append(ipjoin('gui')) - exclusions.append(ipjoin('frontend', 'wx')) exclusions.append(ipjoin('lib', 'inputhookwx')) if not have['gtk'] or not have['gobject']: exclusions.append(ipjoin('lib', 'inputhookgtk')) - if not have['wx.aui']: - exclusions.append(ipjoin('gui', 'wx', 'wxIPython')) - - if not have['objc']: - exclusions.append(ipjoin('frontend', 'cocoa')) - # These have to be skipped on win32 because the use echo, rm, cd, etc. # See ticket https://bugs.launchpad.net/bugs/366982 if sys.platform == 'win32': @@ -203,15 +193,7 @@ def make_exclude(): # how we are isolating dependencies in testing. if not (have['twisted'] and have['zope.interface'] and have['foolscap']): exclusions.extend( - [ipjoin('frontend', 'asyncfrontendbase'), - ipjoin('frontend', 'prefilterfrontend'), - ipjoin('frontend', 'frontendbase'), - ipjoin('frontend', 'linefrontendbase'), - ipjoin('frontend', 'tests', 'test_linefrontend'), - ipjoin('frontend', 'tests', 'test_frontendbase'), - ipjoin('frontend', 'tests', 'test_prefilterfrontend'), - ipjoin('frontend', 'tests', 'test_asyncfrontendbase'), - ipjoin('testing', 'parametric'), + [ipjoin('testing', 'parametric'), ipjoin('testing', 'util'), ipjoin('testing', 'tests', 'test_decorators_trial'), ] ) @@ -317,9 +299,6 @@ def make_runners(): # The machinery in kernel needs twisted for real testing trial_pkg_names = [] - if have['wx']: - nose_pkg_names.append('gui') - # And add twisted ones if conditions are met if have['zope.interface'] and have['twisted'] and have['foolscap']: # We only list IPython.kernel for testing using twisted.trial as diff --git a/IPython/utils/process.py b/IPython/utils/process.py index 45a7749..2d8919c 100644 --- a/IPython/utils/process.py +++ b/IPython/utils/process.py @@ -136,13 +136,12 @@ def arg_split(s, posix=False): function, but with a default of posix=False for splitting, so that quotes in inputs are respected.""" - # XXX - there may be unicode-related problems here!!! I'm not sure that - # shlex is truly unicode-safe, so it might be necessary to do - # - # s = s.encode(sys.stdin.encoding) - # - # first, to ensure that shlex gets a normal string. Input from anyone who - # knows more about unicode and shlex than I would be good to have here... + # Unfortunately, python's shlex module is buggy with unicode input: + # http://bugs.python.org/issue1170 + # At least encoding the input when it's unicode seems to help, but there + # may be more problems lurking. Apparently this is fixed in python3. + if isinstance(s, unicode): + s = s.encode(sys.stdin.encoding) lex = shlex.shlex(s, posix=posix) lex.whitespace_split = True return list(lex) diff --git a/IPython/utils/tests/test_process.py b/IPython/utils/tests/test_process.py index af8d270..c0bae05 100644 --- a/IPython/utils/tests/test_process.py +++ b/IPython/utils/tests/test_process.py @@ -18,7 +18,7 @@ import sys import nose.tools as nt -from IPython.utils.process import find_cmd, FindCmdError +from IPython.utils.process import find_cmd, FindCmdError, arg_split from IPython.testing import decorators as dec #----------------------------------------------------------------------------- @@ -59,4 +59,10 @@ def test_find_cmd_fail(): nt.assert_raises(FindCmdError,find_cmd,'asdfasdf') - +def test_arg_split(): + """Ensure that argument lines are correctly split like in a shell.""" + tests = [['hi', ['hi']], + [u'hi', [u'hi']], + ] + for argstr, argv in tests: + nt.assert_equal(arg_split(argstr), argv) diff --git a/test/test_wildcard.py b/IPython/utils/tests/test_wildcard.py similarity index 57% rename from test/test_wildcard.py rename to IPython/utils/tests/test_wildcard.py index 1e0ee6c..d2bc4df 100644 --- a/test/test_wildcard.py +++ b/IPython/utils/tests/test_wildcard.py @@ -1,38 +1,52 @@ -# -*- coding: UTF-8 -*- -import sys, unittest -sys.path.append ('..') +"""Some tests for the wildcard utilities.""" -from IPython import wildcard +#----------------------------------------------------------------------------- +# Library imports +#----------------------------------------------------------------------------- +# Stdlib +import sys +import unittest + +# Our own +from IPython.utils import wildcard + +#----------------------------------------------------------------------------- +# Globals for test +#----------------------------------------------------------------------------- class obj_t(object): pass -root=obj_t() -l=["arna","abel","ABEL","active","bob","bark","abbot"] -q=["kate","loop","arne","vito","lucifer","koppel"] +root = obj_t() +l = ["arna","abel","ABEL","active","bob","bark","abbot"] +q = ["kate","loop","arne","vito","lucifer","koppel"] for x in l: - o=obj_t() + o = obj_t() setattr(root,x,o) for y in q: - p=obj_t() + p = obj_t() setattr(o,y,p) -root._apan=obj_t() -root._apan.a=10 -root._apan._a=20 -root._apan.__a=20 -root.__anka=obj_t() -root.__anka.a=10 -root.__anka._a=20 -root.__anka.__a=20 +root._apan = obj_t() +root._apan.a = 10 +root._apan._a = 20 +root._apan.__a = 20 +root.__anka = obj_t() +root.__anka.a = 10 +root.__anka._a = 20 +root.__anka.__a = 20 + +root._APAN = obj_t() +root._APAN.a = 10 +root._APAN._a = 20 +root._APAN.__a = 20 +root.__ANKA = obj_t() +root.__ANKA.a = 10 +root.__ANKA._a = 20 +root.__ANKA.__a = 20 -root._APAN=obj_t() -root._APAN.a=10 -root._APAN._a=20 -root._APAN.__a=20 -root.__ANKA=obj_t() -root.__ANKA.a=10 -root.__ANKA._a=20 -root.__ANKA.__a=20 +#----------------------------------------------------------------------------- +# Test cases +#----------------------------------------------------------------------------- class Tests (unittest.TestCase): def test_case(self): @@ -46,7 +60,8 @@ class Tests (unittest.TestCase): ] for pat,res in tests: res.sort() - a=wildcard.list_namespace(ns,"all",pat,ignore_case=False,show_all=False).keys() + a=wildcard.list_namespace(ns,"all",pat,ignore_case=False, + show_all=False).keys() a.sort() self.assertEqual(a,res) @@ -61,7 +76,8 @@ class Tests (unittest.TestCase): ] for pat,res in tests: res.sort() - a=wildcard.list_namespace(ns,"all",pat,ignore_case=False,show_all=True).keys() + a=wildcard.list_namespace(ns,"all",pat,ignore_case=False, + show_all=True).keys() a.sort() self.assertEqual(a,res) @@ -70,14 +86,16 @@ class Tests (unittest.TestCase): ns=root.__dict__ tests=[ ("a*", ["abbot","abel","ABEL","active","arna",]), - ("?b*.?o*",["abbot.koppel","abbot.loop","abel.koppel","abel.loop","ABEL.koppel","ABEL.loop",]), + ("?b*.?o*",["abbot.koppel","abbot.loop","abel.koppel","abel.loop", + "ABEL.koppel","ABEL.loop",]), ("_a*", []), ("_*anka", ["__anka","__ANKA",]), ("_*a*", ["__anka","__ANKA",]), ] for pat,res in tests: res.sort() - a=wildcard.list_namespace(ns,"all",pat,ignore_case=True,show_all=False).keys() + a=wildcard.list_namespace(ns,"all",pat,ignore_case=True, + show_all=False).keys() a.sort() self.assertEqual(a,res) @@ -85,16 +103,15 @@ class Tests (unittest.TestCase): ns=root.__dict__ tests=[ ("a*", ["abbot","abel","ABEL","active","arna",]), - ("?b*.?o*",["abbot.koppel","abbot.loop","abel.koppel","abel.loop","ABEL.koppel","ABEL.loop",]), + ("?b*.?o*",["abbot.koppel","abbot.loop","abel.koppel","abel.loop", + "ABEL.koppel","ABEL.loop",]), ("_a*", ["_apan","_APAN"]), ("_*anka", ["__anka","__ANKA",]), ("_*a*", ["__anka","__ANKA","_apan","_APAN"]), ] for pat,res in tests: res.sort() - a=wildcard.list_namespace(ns,"all",pat,ignore_case=True,show_all=True).keys() + a=wildcard.list_namespace(ns,"all",pat,ignore_case=True, + show_all=True).keys() a.sort() self.assertEqual(a,res) - -if __name__ == '__main__': - unittest.main() \ No newline at end of file diff --git a/setupbase.py b/setupbase.py index 68f07cf..9542911 100644 --- a/setupbase.py +++ b/setupbase.py @@ -108,19 +108,9 @@ def find_packages(): add_package(packages, 'deathrow', tests=True) add_package(packages, 'extensions') add_package(packages, 'external') - add_package(packages, 'frontend', tests=True) - # Don't include the cocoa frontend for now as it is not stable - if sys.platform == 'darwin' and False: - add_package(packages, 'frontend.cocoa', tests=True, others=['plugin']) - add_package(packages, 'frontend.cocoa.examples') - add_package(packages, 'frontend.cocoa.examples.IPython1Sandbox') - add_package(packages, 'frontend.cocoa.examples.IPython1Sandbox.English.lproj') - add_package(packages, 'frontend.process') + add_package(packages, 'frontend') add_package(packages, 'frontend.qt') add_package(packages, 'frontend.qt.console') - add_package(packages, 'frontend.wx') - add_package(packages, 'gui') - add_package(packages, 'gui.wx') add_package(packages, 'kernel', config=False, tests=True, scripts=True) add_package(packages, 'kernel.core', config=False, tests=True) add_package(packages, 'lib', tests=True) diff --git a/test/manualtest_repr_tb.py b/test/manualtest_repr_tb.py deleted file mode 100644 index 93dff69..0000000 --- a/test/manualtest_repr_tb.py +++ /dev/null @@ -1,16 +0,0 @@ -"""This should be run directly from ipython, and it should NOT crash. - -It can't currently be run via runtests b/c exception handling changes there, -and this is precisely testing exception handling problems.""" - -ipmagic('xmode verbose') - -src = """ -class suck(object): - def __repr__(self): - raise ValueError("who needs repr anyway") - -suck() -""" - -__IPYTHON__.runlines(src) diff --git a/test/runtests.py b/test/runtests.py deleted file mode 100644 index 36160ab..0000000 --- a/test/runtests.py +++ /dev/null @@ -1,31 +0,0 @@ -""" Run ipython unit tests - -This should be launched from inside ipython by "%run runtests.py" -or through ipython command line "ipython runtests.py". - -""" - -from IPython.external.path import path -import pprint,os -import IPython.ipapi -ip = IPython.ipapi.get() - -def main(): - all = path('.').files('test_*py') - results = {} - res_exc = [None] - def exchook(self,*e): - res_exc[0] = [e] - ip.IP.set_custom_exc((Exception,), exchook) - startdir = os.getcwd() - for test in all: - print test - res_exc[0] = 'ok' - os.chdir(startdir) - ip.runlines(test.text()) - results[str(test)] = res_exc[0] - - os.chdir(startdir) - pprint.pprint(results) - -main() diff --git a/test/test_autocall.ipy b/test/test_autocall.ipy deleted file mode 100644 index 2f40785..0000000 --- a/test/test_autocall.ipy +++ /dev/null @@ -1,24 +0,0 @@ -def f1(a,b,c): - return a+b+c - - -def f2(a): - return a + a - - -;f2 a b c -assert _ == "a b ca b c" - -,f1 a b c -assert _ == 'abc' -print _ - -/f1 1,2,3 -assert _ == 6 - -/f2 4 -assert _ == 8 - -del f1 -del f2 - diff --git a/test/test_cd.ipy b/test/test_cd.ipy deleted file mode 100644 index eee6ace..0000000 --- a/test/test_cd.ipy +++ /dev/null @@ -1,18 +0,0 @@ -# assumes there is /tmp and /opt - -def curpath(): - cwd = os.path.splitdrive(os.getcwd())[1].replace('\\','/') - print cwd - return cwd - -import os -cd / -assert curpath() == '/' -%cd /tmp -assert curpath() == '/tmp' -pushd /opt -assert curpath() == '/opt' -popd -assert curpath() == '/tmp' - - diff --git a/test/test_completer.py b/test/test_completer.py deleted file mode 100644 index 0ba66c3..0000000 --- a/test/test_completer.py +++ /dev/null @@ -1,37 +0,0 @@ -""" -comp -""" - -# The prefilter always ends in a call to some self.handle_X method. We swap -# all of those out so that we can capture which one was called. - -import sys -sys.path.append('..') -import IPython -import IPython.ipapi - -IPython.Shell.start() - -ip = IPython.ipapi.get() - -completer = ip.IP.Completer - -print completer - -def do_test(text, line): - def get_endix(): - idx = len(line) - print "Call endidx =>",idx - return idx - def get_line_buffer(): - print "Lbuf =>",line - return line - completer.get_line_buffer = get_line_buffer - completer.get_endidx = get_endix - l = completer.all_completions(text) - return l - -l = do_test ('p', 'print p') -assert 'pow' in l -l = do_test ('p', 'import p') -assert 'pprint' in l \ No newline at end of file diff --git a/test/test_cpaste.ipy b/test/test_cpaste.ipy deleted file mode 100644 index 259e930..0000000 --- a/test/test_cpaste.ipy +++ /dev/null @@ -1,62 +0,0 @@ -"""Test cpaste magic""" - -tests = {'pass': ["> > > run()", - ">>> > run()", - "+++ run()", - "++ run()", - " >>> run()"], - - 'fail': ["+ + run()", - " ++ run()"]} - -from StringIO import StringIO -import sys - -stdin_save = sys.stdin - -# NOTE: no blank lines allowed in function definition -def testcase(code,should_fail=False): - """Execute code via 'cpaste' and ensure it was executed, unless - should_fail is set. - - """ - _ip.user_ns['code_ran'] = False - # - src = StringIO() - src.write('\n') - src.write(code) - src.write('\n--\n') - src.seek(0) - # - sys.stdin = src - - try: - cpaste - except: - if not should_fail: - raise AssertionError("Failure not expected : '%s'" % - code) - else: - assert code_ran - if should_fail: - raise AssertionError("Failure expected : '%s'" % code) - # - finally: - sys.stdin = stdin_save - # - -def run(): - """Marker function: sets a flag when executed. - - """ - _ip.user_ns['code_ran'] = True - return 'run' # return string so '+ run()' doesn't result in success - - -### Actual testing happens here - -for code in tests['pass']: - testcase(code) - -for code in tests['fail']: - testcase(code,should_fail=True) diff --git a/test/test_embed.py b/test/test_embed.py deleted file mode 100644 index ad88343..0000000 --- a/test/test_embed.py +++ /dev/null @@ -1,48 +0,0 @@ -""" An example of one way to embed IPython in your own application - -This basically means starting up IPython with some of your programs objects visible in the IPython -user namespace. - -""" - -import sys -sys.path.insert(1,'..') - -import IPython.ipapi - - - -def test_session(shellclass): - print "*****************\nLaunch shell for",shellclass - my_ns = dict(a=10) - ses = IPython.ipapi.make_session(my_ns, shellclass=shellclass) - - # Now get the ipapi instance, to be stored somewhere in your program for manipulation of the running - # IPython session. See http://ipython.scipy.org/moin/IpythonExtensionApi - - ip = ses.IP.getapi() - - # let's play with the ipapi a bit, creating a magic function for a soon-to-be-started IPython - def mymagic_f(self,s): - print "mymagic says",s - - ip.expose_magic("mymagic",mymagic_f) - - # And finally, start the IPython interaction! This will block until you say Exit. - - ses.mainloop() - - print "IPython session for shell ",shellclass," finished! namespace content:" - for k,v in my_ns.items(): - print k,':',str(v)[:80].rstrip() - -import IPython.Shell - -def do_test(arg_line): - test_session(IPython.Shell._select_shell(arg_line.split())) - -do_test('') -do_test('ipython -gthread') -do_test('ipython -q4thread') -do_test('ipython -pylab') -do_test('ipython -pylab -gthread') \ No newline at end of file diff --git a/test/test_ihist.ipy b/test/test_ihist.ipy deleted file mode 100644 index 6f9bce6..0000000 --- a/test/test_ihist.ipy +++ /dev/null @@ -1,2 +0,0 @@ -1+2 -assert _ == 3 diff --git a/test/test_ipapi.py b/test/test_ipapi.py deleted file mode 100644 index 30f51f4..0000000 --- a/test/test_ipapi.py +++ /dev/null @@ -1,54 +0,0 @@ -import sys -sys.path.append('..') - -import IPython.ipapi -IPython.ipapi.make_session() -ip = IPython.ipapi.get() - -def test_runlines(): - import textwrap - ip.runlines(['a = 10', 'a+=1']) - ip.runlines('assert a == 11\nassert 1') - - assert ip.user_ns['a'] == 11 - complex = textwrap.dedent("""\ - if 1: - print "hello" - if 1: - print "world" - - if 1: - print "foo" - if 1: - print "bar" - - if 1: - print "bar" - - """) - - - ip.runlines(complex) - - -def test_db(): - ip.db['__unittest_'] = 12 - assert ip.db['__unittest_'] == 12 - del ip.db['__unittest_'] - assert '__unittest_' not in ip.db - -def test_defalias(): - slot = [None] - # test callable alias - def cb(localip,s): - assert localip is ip - slot[0] = s - - ip.defalias('testalias', cb) - ip.runlines('testalias foo bar') - assert slot[0] == 'testalias foo bar' - - -test_runlines() -test_db() -test_defalias diff --git a/test/test_shouldfail.ipy b/test/test_shouldfail.ipy deleted file mode 100644 index 128f229..0000000 --- a/test/test_shouldfail.ipy +++ /dev/null @@ -1,3 +0,0 @@ -# this will fail w/ assertionerror -cd / -assert os.getcwd() == '/does/not/exist'