##// END OF EJS Templates
Fix almost all IPython.core tests for Python 3.
Thomas Kluyver -
Show More
@@ -344,8 +344,7 b' class Inspector:'
344 if init_ds is not None:
344 if init_ds is not None:
345 lines.append(head("Constructor Docstring:"))
345 lines.append(head("Constructor Docstring:"))
346 lines.append(indent(init_ds))
346 lines.append(indent(init_ds))
347 elif (type(obj) is types.InstanceType or isinstance(obj,object)) \
347 elif hasattr(obj,'__call__'):
348 and hasattr(obj,'__call__'):
349 call_ds = getdoc(obj.__call__)
348 call_ds = getdoc(obj.__call__)
350 if call_ds:
349 if call_ds:
351 lines.append(head("Calling Docstring:"))
350 lines.append(head("Calling Docstring:"))
@@ -12,6 +12,7 b' from IPython.core import autocall'
12 from IPython.testing import decorators as dec
12 from IPython.testing import decorators as dec
13 from IPython.testing import tools as tt
13 from IPython.testing import tools as tt
14 from IPython.testing.globalipapp import get_ipython
14 from IPython.testing.globalipapp import get_ipython
15 from IPython.utils import py3compat
15
16
16 #-----------------------------------------------------------------------------
17 #-----------------------------------------------------------------------------
17 # Globals
18 # Globals
@@ -77,9 +77,9 b' def test_history():'
77 # Cross testing: check that magic %save can get previous session.
77 # Cross testing: check that magic %save can get previous session.
78 testfilename = os.path.realpath(os.path.join(tmpdir, "test.py"))
78 testfilename = os.path.realpath(os.path.join(tmpdir, "test.py"))
79 ip.magic_save(testfilename + " ~1/1-3")
79 ip.magic_save(testfilename + " ~1/1-3")
80 testfile = open(testfilename, "r")
80 with py3compat.open(testfilename) as testfile:
81 nt.assert_equal(testfile.read().decode("utf-8"),
81 nt.assert_equal(testfile.read(),
82 "# coding: utf-8\n" + "\n".join(hist))
82 u"# coding: utf-8\n" + u"\n".join(hist))
83
83
84 # Duplicate line numbers - check that it doesn't crash, and
84 # Duplicate line numbers - check that it doesn't crash, and
85 # gets a new session
85 # gets a new session
@@ -15,6 +15,7 b' import nose.tools as nt'
15 # our own packages
15 # our own packages
16 from IPython.testing import decorators as dec
16 from IPython.testing import decorators as dec
17 from IPython.testing.globalipapp import get_ipython
17 from IPython.testing.globalipapp import get_ipython
18 from IPython.utils import py3compat
18
19
19 #-----------------------------------------------------------------------------
20 #-----------------------------------------------------------------------------
20 # Globals
21 # Globals
@@ -216,11 +216,6 b' def test_paste():'
216 original_clip = hooks.clipboard_get
216 original_clip = hooks.clipboard_get
217
217
218 try:
218 try:
219 # This try/except with an emtpy except clause is here only because
220 # try/yield/finally is invalid syntax in Python 2.4. This will be
221 # removed when we drop 2.4-compatibility, and the emtpy except below
222 # will be changed to a finally.
223
224 # Run tests with fake clipboard function
219 # Run tests with fake clipboard function
225 user_ns.pop('x', None)
220 user_ns.pop('x', None)
226 paste('x=1')
221 paste('x=1')
@@ -263,7 +258,6 b' def test_paste():'
263 yield nt.assert_equal(out, code+"\n## -- End pasted text --\n")
258 yield nt.assert_equal(out, code+"\n## -- End pasted text --\n")
264
259
265 finally:
260 finally:
266 # This should be in a finally clause, instead of the bare except above.
267 # Restore original hook
261 # Restore original hook
268 hooks.clipboard_get = original_clip
262 hooks.clipboard_get = original_clip
269
263
@@ -21,7 +21,7 b' from nose import SkipTest'
21
21
22 from IPython.testing import decorators as dec
22 from IPython.testing import decorators as dec
23 from IPython.testing import tools as tt
23 from IPython.testing import tools as tt
24 from IPython.utils.py3compat import doctest_refactor_print
24 from IPython.utils import py3compat
25
25
26 #-----------------------------------------------------------------------------
26 #-----------------------------------------------------------------------------
27 # Test functions begin
27 # Test functions begin
@@ -85,7 +85,7 b' def doctest_run_builtins():'
85 ....:
85 ....:
86 """
86 """
87
87
88 @doctest_refactor_print
88 @py3compat.doctest_refactor_print
89 def doctest_reset_del():
89 def doctest_reset_del():
90 """Test that resetting doesn't cause errors in __del__ methods.
90 """Test that resetting doesn't cause errors in __del__ methods.
91
91
@@ -168,7 +168,7 b' class TestMagicRunSimple(tt.TempFileMixin):'
168 " def __del__(self):\n"
168 " def __del__(self):\n"
169 " print 'object A deleted'\n"
169 " print 'object A deleted'\n"
170 "a = A()\n")
170 "a = A()\n")
171 self.mktmp(src)
171 self.mktmp(py3compat.doctest_refactor_print(src))
172 tt.ipexec_validate(self.fname, 'object A deleted')
172 tt.ipexec_validate(self.fname, 'object A deleted')
173
173
174 @dec.skip_known_failure
174 @dec.skip_known_failure
@@ -186,7 +186,7 b' class TestMagicRunSimple(tt.TempFileMixin):'
186 " ip.magic('run %s')\n"
186 " ip.magic('run %s')\n"
187 " except NameError, e:\n"
187 " except NameError, e:\n"
188 " print i;break\n" % empty.fname)
188 " print i;break\n" % empty.fname)
189 self.mktmp(src)
189 self.mktmp(py3compat.doctest_refactor_print(src))
190 _ip.magic('run %s' % self.fname)
190 _ip.magic('run %s' % self.fname)
191 _ip.run_cell('ip == get_ipython()')
191 _ip.run_cell('ip == get_ipython()')
192 tt.assert_equals(_ip.user_ns['i'], 5)
192 tt.assert_equals(_ip.user_ns['i'], 5)
@@ -200,11 +200,11 b' class TestMagicRunSimple(tt.TempFileMixin):'
200 "%%run '%s' C-third\n") % (tc, tc, tc)
200 "%%run '%s' C-third\n") % (tc, tc, tc)
201 self.mktmp(src, '.ipy')
201 self.mktmp(src, '.ipy')
202 out = """\
202 out = """\
203 ARGV 1-: [u'C-first']
203 ARGV 1-: [{u}'C-first']
204 ARGV 1-: [u'C-second']
204 ARGV 1-: [{u}'C-second']
205 tclass.py: deleting object: C-first
205 tclass.py: deleting object: C-first
206 ARGV 1-: [u'C-third']
206 ARGV 1-: [{u}'C-third']
207 tclass.py: deleting object: C-second
207 tclass.py: deleting object: C-second
208 tclass.py: deleting object: C-third
208 tclass.py: deleting object: C-third
209 """
209 """
210 tt.ipexec_validate(self.fname, out)
210 tt.ipexec_validate(self.fname, py3compat.u_format(out))
@@ -46,9 +46,11 b' class ParametricTestCase(unittest.TestCase):'
46 # For normal tests, we just call the base class and return that
46 # For normal tests, we just call the base class and return that
47 if isgenerator(testMethod):
47 if isgenerator(testMethod):
48 def adapter(next_test):
48 def adapter(next_test):
49 return unittest.FunctionTestCase(next_test,
49 ftc = unittest.FunctionTestCase(next_test,
50 self.setUp,
50 self.setUp,
51 self.tearDown)
51 self.tearDown)
52 self._nose_case = ftc # Nose 1.0 rejects the test without this
53 return ftc
52
54
53 return IterCallableSuite(testMethod(),adapter).run(result)
55 return IterCallableSuite(testMethod(),adapter).run(result)
54 else:
56 else:
@@ -48,6 +48,7 b' from IPython.config.loader import Config'
48 from IPython.utils.process import find_cmd, getoutputerror
48 from IPython.utils.process import find_cmd, getoutputerror
49 from IPython.utils.text import list_strings
49 from IPython.utils.text import list_strings
50 from IPython.utils.io import temp_pyfile
50 from IPython.utils.io import temp_pyfile
51 from IPython.utils.py3compat import PY3
51
52
52 from . import decorators as dec
53 from . import decorators as dec
53 from . import skipdoctest
54 from . import skipdoctest
@@ -209,7 +210,7 b' def ipexec(fname, options=None):'
209 _ip = get_ipython()
210 _ip = get_ipython()
210 test_dir = os.path.dirname(__file__)
211 test_dir = os.path.dirname(__file__)
211
212
212 ipython_cmd = find_cmd('ipython')
213 ipython_cmd = find_cmd('ipython3' if PY3 else 'ipython')
213 # Absolute path for filename
214 # Absolute path for filename
214 full_fname = os.path.join(test_dir, fname)
215 full_fname = os.path.join(test_dir, fname)
215 full_cmd = '%s %s %s' % (ipython_cmd, cmdargs, full_fname)
216 full_cmd = '%s %s %s' % (ipython_cmd, cmdargs, full_fname)
@@ -25,6 +25,7 b' from IPython.external import pexpect'
25 from .autoattr import auto_attr
25 from .autoattr import auto_attr
26 from ._process_common import getoutput
26 from ._process_common import getoutput
27 from IPython.utils import text
27 from IPython.utils import text
28 from IPython.utils import py3compat
28
29
29 #-----------------------------------------------------------------------------
30 #-----------------------------------------------------------------------------
30 # Function definitions
31 # Function definitions
@@ -33,8 +34,9 b' from IPython.utils import text'
33 def _find_cmd(cmd):
34 def _find_cmd(cmd):
34 """Find the full path to a command using which."""
35 """Find the full path to a command using which."""
35
36
36 return sp.Popen(['/usr/bin/env', 'which', cmd],
37 path = sp.Popen(['/usr/bin/env', 'which', cmd],
37 stdout=sp.PIPE).communicate()[0]
38 stdout=sp.PIPE).communicate()[0]
39 return py3compat.bytes_to_str(path)
38
40
39
41
40 class ProcessHandler(object):
42 class ProcessHandler(object):
@@ -67,7 +67,7 b' class PickleShareDB(collections.MutableMapping):'
67 return self.cache[fil][0]
67 return self.cache[fil][0]
68 try:
68 try:
69 # The cached item has expired, need to read
69 # The cached item has expired, need to read
70 obj = pickle.load(fil.open())
70 obj = pickle.load(fil.open("rb"))
71 except:
71 except:
72 raise KeyError(key)
72 raise KeyError(key)
73
73
@@ -80,7 +80,7 b' class PickleShareDB(collections.MutableMapping):'
80 parent = fil.parent
80 parent = fil.parent
81 if parent and not parent.isdir():
81 if parent and not parent.isdir():
82 parent.makedirs()
82 parent.makedirs()
83 pickled = pickle.dump(value,fil.open('w'))
83 pickled = pickle.dump(value,fil.open('wb'))
84 try:
84 try:
85 self.cache[fil] = (value,fil.mtime)
85 self.cache[fil] = (value,fil.mtime)
86 except OSError,e:
86 except OSError,e:
General Comments 0
You need to be logged in to leave comments. Login now