diff --git a/IPython/utils/frame.py b/IPython/utils/frame.py index 9a077fe..9ac37db 100644 --- a/IPython/utils/frame.py +++ b/IPython/utils/frame.py @@ -15,11 +15,13 @@ Utilities for working with stack frames. #----------------------------------------------------------------------------- import sys +from IPython.utils import py3compat #----------------------------------------------------------------------------- # Code #----------------------------------------------------------------------------- +@py3compat.doctest_refactor_print def extract_vars(*names,**kw): """Extract a set of variables by name from another frame. diff --git a/IPython/utils/ipstruct.py b/IPython/utils/ipstruct.py index fd6e159..3700146 100644 --- a/IPython/utils/ipstruct.py +++ b/IPython/utils/ipstruct.py @@ -137,7 +137,7 @@ class Struct(dict): >>> s.a 10 >>> type(s.get) - + <... 'builtin_function_or_method'> >>> try: ... s.b ... except AttributeError: diff --git a/IPython/utils/sysinfo.py b/IPython/utils/sysinfo.py index 7aa7077..a49c735 100644 --- a/IPython/utils/sysinfo.py +++ b/IPython/utils/sysinfo.py @@ -23,6 +23,7 @@ import subprocess from ConfigParser import ConfigParser from IPython.core import release +from IPython.utils import py3compat #----------------------------------------------------------------------------- # Globals @@ -113,6 +114,7 @@ def pkg_info(pkg_path): ) +@py3compat.doctest_refactor_print def sys_info(): """Return useful information about IPython and the system, as a string. diff --git a/IPython/utils/tests/test_io.py b/IPython/utils/tests/test_io.py index 64764a4..0a01bce 100644 --- a/IPython/utils/tests/test_io.py +++ b/IPython/utils/tests/test_io.py @@ -21,6 +21,7 @@ import nose.tools as nt from IPython.testing import decorators as dec from IPython.utils.io import Tee +from IPython.utils.py3compat import doctest_refactor_print #----------------------------------------------------------------------------- # Tests @@ -32,8 +33,8 @@ def test_tee_simple(): chan = StringIO() text = 'Hello' tee = Tee(chan, channel='stdout') - print >> chan, text, - nt.assert_equal(chan.getvalue(), text) + print >> chan, text + nt.assert_equal(chan.getvalue(), text+"\n") class TeeTestCase(dec.ParametricTestCase): @@ -64,8 +65,11 @@ class TeeTestCase(dec.ParametricTestCase): def test_io_init(): """Test that io.stdin/out/err exist at startup""" for name in ('stdin', 'stdout', 'stderr'): - p = Popen([sys.executable, '-c', "from IPython.utils import io;print io.%s.__class__"%name], + cmd = doctest_refactor_print("from IPython.utils import io;print io.%s.__class__"%name) + p = Popen([sys.executable, '-c', cmd], stdout=PIPE) p.wait() - classname = p.stdout.read().strip() - nt.assert_equals(classname, 'IPython.utils.io.IOStream') + classname = p.stdout.read().strip().decode('ascii') + # __class__ is a reference to the class object in Python 3, so we can't + # just test for string equality. + assert 'IPython.utils.io.IOStream' in classname, classname diff --git a/IPython/utils/tests/test_path.py b/IPython/utils/tests/test_path.py index c8acc8b..bcf23b6 100644 --- a/IPython/utils/tests/test_path.py +++ b/IPython/utils/tests/test_path.py @@ -18,7 +18,7 @@ import os import shutil import sys import tempfile -import StringIO +from io import StringIO from os.path import join, abspath, split @@ -405,7 +405,7 @@ def test_not_writable_ipdir(): os.mkdir(ipdir) os.chmod(ipdir, 600) stderr = io.stderr - pipe = StringIO.StringIO() + pipe = StringIO() io.stderr = pipe ipdir = path.get_ipython_dir() io.stderr.flush() diff --git a/IPython/utils/tests/test_text.py b/IPython/utils/tests/test_text.py index c4c0629..ba7f160 100644 --- a/IPython/utils/tests/test_text.py +++ b/IPython/utils/tests/test_text.py @@ -47,7 +47,7 @@ def test_columnize_long(): def test_eval_formatter(): f = text.EvalFormatter() ns = dict(n=12, pi=math.pi, stuff='hello there', os=os) - s = f.format("{n} {n/4} {stuff.split()[0]}", **ns) + s = f.format("{n} {n//4} {stuff.split()[0]}", **ns) nt.assert_equals(s, "12 3 hello") s = f.format(' '.join(['{n//%i}'%i for i in range(1,8)]), **ns) nt.assert_equals(s, "12 6 4 3 2 2 1") diff --git a/IPython/utils/tests/test_traitlets.py b/IPython/utils/tests/test_traitlets.py index d6e7d2f..e1e296e 100644 --- a/IPython/utils/tests/test_traitlets.py +++ b/IPython/utils/tests/test_traitlets.py @@ -30,7 +30,7 @@ from IPython.utils.traitlets import ( Undefined, Type, This, Instance, TCPAddress, List, Tuple, ObjectName, DottedObjectName ) - +from IPython.utils import py3compat #----------------------------------------------------------------------------- # Helper classes for testing @@ -622,7 +622,10 @@ class TraitTestBase(TestCase): def test_bad_values(self): if hasattr(self, '_bad_values'): for value in self._bad_values: - self.assertRaises(TraitError, self.assign, value) + try: + self.assertRaises(TraitError, self.assign, value) + except AssertionError: + assert False, value def test_default_value(self): if hasattr(self, '_default_value'): @@ -651,9 +654,11 @@ class TestInt(TraitTestBase): obj = IntTrait() _default_value = 99 _good_values = [10, -10] - _bad_values = ['ten', u'ten', [10], {'ten': 10},(10,), None, 1j, 10L, - -10L, 10.1, -10.1, '10L', '-10L', '10.1', '-10.1', u'10L', + _bad_values = ['ten', u'ten', [10], {'ten': 10},(10,), None, 1j, + 10.1, -10.1, '10L', '-10L', '10.1', '-10.1', u'10L', u'-10L', u'10.1', u'-10.1', '10', '-10', u'10', u'-10'] + if not py3compat.PY3: + _bad_values.extend([10L, -10L]) class LongTrait(HasTraits): @@ -682,9 +687,11 @@ class TestFloat(TraitTestBase): _default_value = 99.0 _good_values = [10, -10, 10.1, -10.1] - _bad_values = [10L, -10L, 'ten', u'ten', [10], {'ten': 10},(10,), None, + _bad_values = ['ten', u'ten', [10], {'ten': 10},(10,), None, 1j, '10', '-10', '10L', '-10L', '10.1', '-10.1', u'10', u'-10', u'10L', u'-10L', u'10.1', u'-10.1'] + if not py3compat.PY3: + _bad_values.extend([10L, -10L]) class ComplexTrait(HasTraits): @@ -698,7 +705,9 @@ class TestComplex(TraitTestBase): _default_value = 99.0-99.0j _good_values = [10, -10, 10.1, -10.1, 10j, 10+10j, 10-10j, 10.1j, 10.1+10.1j, 10.1-10.1j] - _bad_values = [10L, -10L, u'10L', u'-10L', 'ten', [10], {'ten': 10},(10,), None] + _bad_values = [u'10L', u'-10L', 'ten', [10], {'ten': 10},(10,), None] + if not py3compat.PY3: + _bad_values.extend([10L, -10L]) class BytesTrait(HasTraits): @@ -835,12 +844,12 @@ class TestLooseTupleTrait(TraitTestBase): class MultiTupleTrait(HasTraits): - value = Tuple(Int, Bytes, default_value=[99,'bottles']) + value = Tuple(Int, Bytes, default_value=[99,b'bottles']) class TestMultiTuple(TraitTestBase): obj = MultiTupleTrait() - _default_value = (99,'bottles') - _good_values = [(1,'a'), (2,'b')] - _bad_values = ((),10, 'a', (1,'a',3), ('a',1)) + _default_value = (99,b'bottles') + _good_values = [(1,b'a'), (2,b'b')] + _bad_values = ((),10, b'a', (1,b'a',3), (b'a',1), (1, u'a'))