From 247753acdd0641205a3bed1b2f6efb0d20d9f6ca 2013-10-29 16:15:56 From: Thomas Kluyver Date: 2013-10-29 16:15:56 Subject: [PATCH] Fix tests for core --- diff --git a/IPython/core/completerlib.py b/IPython/core/completerlib.py index 22e14d7..bc0e3e4 100644 --- a/IPython/core/completerlib.py +++ b/IPython/core/completerlib.py @@ -269,7 +269,7 @@ def magic_run_completer(self, event): # should complete on all files, since after the first one other files may # be arguments to the input script. - if filter(magic_run_re.match, comps): + if any(magic_run_re.match(c) for c in comps): pys = [f.replace('\\','/') for f in lglob('*')] else: pys = [f.replace('\\','/') diff --git a/IPython/core/debugger.py b/IPython/core/debugger.py index 587c2c7..93f573f 100644 --- a/IPython/core/debugger.py +++ b/IPython/core/debugger.py @@ -146,7 +146,10 @@ class Tracer(object): # at least raise that limit to 80 chars, which should be enough for # most interactive uses. try: - from reprlib import aRepr + try: + from reprlib import aRepr # Py 3 + except ImportError: + from repr import aRepr # Py 2 aRepr.maxstring = 80 except: # This is only a user-facing convenience, so any error we encounter @@ -331,7 +334,10 @@ class Pdb(OldPdb): # vds: << def format_stack_entry(self, frame_lineno, lprefix=': ', context = 3): - import reprlib + try: + import reprlib # Py 3 + except ImportError: + import repr as reprlib # Py 2 ret = [] diff --git a/IPython/core/magics/namespace.py b/IPython/core/magics/namespace.py index b4863b2..a3b3be5 100644 --- a/IPython/core/magics/namespace.py +++ b/IPython/core/magics/namespace.py @@ -401,8 +401,6 @@ class NamespaceMagics(Magics): ndarray_type = ndarray.__name__ # Find all variable names and types so we can figure out column sizes - def get_vars(i): - return self.shell.user_ns[i] # some types are well known and can be shorter abbrevs = {'IPython.core.macro.Macro' : 'Macro'} @@ -410,7 +408,7 @@ class NamespaceMagics(Magics): tn = type(v).__name__ return abbrevs.get(tn,tn) - varlist = map(get_vars,varnames) + varlist = [self.shell.user_ns[n] for n in varnames] typelist = [] for vv in varlist: @@ -583,7 +581,7 @@ class NamespaceMagics(Magics): from numpy import ndarray # This must be done with items and not iteritems because # we're going to modify the dict in-place. - for x,val in user_ns.items(): + for x,val in list(user_ns.items()): if isinstance(val,ndarray): del user_ns[x] except ImportError: diff --git a/IPython/core/tests/test_completer.py b/IPython/core/tests/test_completer.py index 739c766..ea9e536 100644 --- a/IPython/core/tests/test_completer.py +++ b/IPython/core/tests/test_completer.py @@ -65,7 +65,7 @@ def check_line_split(splitter, test_specs): def test_line_split(): - """Basice line splitter test with default specs.""" + """Basic line splitter test with default specs.""" sp = completer.CompletionSplitter() # The format of the test specs is: part1, part2, expected answer. Parts 1 # and 2 are joined into the 'line' sent to the splitter, as if the cursor @@ -105,7 +105,7 @@ def test_unicode_completions(): # Some strings that trigger different types of completion. Check them both # in str and unicode forms s = ['ru', '%ru', 'cd /', 'floa', 'float(x)/'] - for t in s + map(unicode_type, s): + for t in s + list(map(unicode_type, s)): # We don't need to check exact completion values (they may change # depending on the state of the namespace, but at least no exceptions # should be thrown and the return value should be a pair of text, list @@ -159,7 +159,7 @@ def test_abspath_file_completions(): ip = get_ipython() with TemporaryDirectory() as tmpdir: prefix = os.path.join(tmpdir, 'foo') - suffixes = map(str, [1,2]) + suffixes = ['1', '2'] names = [prefix+s for s in suffixes] for n in names: open(n, 'w').close() @@ -182,7 +182,7 @@ def test_local_file_completions(): with TemporaryDirectory() as tmpdir: os.chdir(tmpdir) prefix = './foo' - suffixes = map(str, [1,2]) + suffixes = ['1', '2'] names = [prefix+s for s in suffixes] for n in names: open(n, 'w').close() @@ -206,7 +206,7 @@ def test_greedy_completions(): greedy_original = ip.Completer.greedy try: ip.Completer.greedy = False - ip.ex('a=range(5)') + ip.ex('a=list(range(5))') _,c = ip.complete('.',line='a[0].') nt.assert_false('a[0].real' in c, "Shouldn't have completed on a[0]: %s"%c) @@ -227,18 +227,18 @@ def test_omit__names(): cfg.IPCompleter.omit__names = 0 c.update_config(cfg) s,matches = c.complete('ip.') - nt.assert_true('ip.__str__' in matches) - nt.assert_true('ip._hidden_attr' in matches) + nt.assert_in('ip.__str__', matches) + nt.assert_in('ip._hidden_attr', matches) cfg.IPCompleter.omit__names = 1 c.update_config(cfg) s,matches = c.complete('ip.') - nt.assert_false('ip.__str__' in matches) - nt.assert_true('ip._hidden_attr' in matches) + nt.assert_not_in('ip.__str__', matches) + nt.assert_in('ip._hidden_attr', matches) cfg.IPCompleter.omit__names = 2 c.update_config(cfg) s,matches = c.complete('ip.') - nt.assert_false('ip.__str__' in matches) - nt.assert_false('ip._hidden_attr' in matches) + nt.assert_not_in('ip.__str__', matches) + nt.assert_not_in('ip._hidden_attr', matches) del ip._hidden_attr @@ -251,7 +251,7 @@ def test_limit_to__all__False_ok(): cfg.IPCompleter.limit_to__all__ = False c.update_config(cfg) s, matches = c.complete('d.') - nt.assert_true('d.x' in matches) + nt.assert_in('d.x', matches) def test_limit_to__all__True_ok(): @@ -264,8 +264,8 @@ def test_limit_to__all__True_ok(): cfg.IPCompleter.limit_to__all__ = True c.update_config(cfg) s, matches = c.complete('d.') - nt.assert_true('d.z' in matches) - nt.assert_false('d.x' in matches) + nt.assert_in('d.z', matches) + nt.assert_not_in('d.x', matches) def test_get__all__entries_ok(): diff --git a/IPython/core/tests/test_debugger.py b/IPython/core/tests/test_debugger.py index 2d36a22..dddcc27 100644 --- a/IPython/core/tests/test_debugger.py +++ b/IPython/core/tests/test_debugger.py @@ -58,7 +58,10 @@ class PdbTestInput(object): #----------------------------------------------------------------------------- def test_longer_repr(): - from reprlib import repr as trepr + try: + from reprlib import repr as trepr # Py 3 + except ImportError: + from repr import repr as trepr # Py 2 a = '1234567890'* 7 ar = "'1234567890123456789012345678901234567890123456789012345678901234567890'" diff --git a/IPython/core/tests/test_magic_terminal.py b/IPython/core/tests/test_magic_terminal.py index 464324d..9643ecf 100644 --- a/IPython/core/tests/test_magic_terminal.py +++ b/IPython/core/tests/test_magic_terminal.py @@ -9,12 +9,17 @@ from __future__ import absolute_import #----------------------------------------------------------------------------- import sys -from io import StringIO from unittest import TestCase import nose.tools as nt from IPython.testing import tools as tt +from IPython.utils.py3compat import PY3 + +if PY3: + from io import StringIO +else: + from StringIO import StringIO #----------------------------------------------------------------------------- # Globals