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