Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c4afd4e

Browse files
committed
Various fixes to tests in IPython.utils.
1 parent 055cc6c commit c4afd4e

7 files changed

Lines changed: 36 additions & 19 deletions

File tree

IPython/utils/frame.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@
1515
#-----------------------------------------------------------------------------
1616

1717
import sys
18+
from IPython.utils import py3compat
1819

1920
#-----------------------------------------------------------------------------
2021
# Code
2122
#-----------------------------------------------------------------------------
2223

24+
@py3compat.doctest_refactor_print
2325
def extract_vars(*names,**kw):
2426
"""Extract a set of variables by name from another frame.
2527

IPython/utils/ipstruct.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ def __getattr__(self, key):
137137
>>> s.a
138138
10
139139
>>> type(s.get)
140-
<type 'builtin_function_or_method'>
140+
<... 'builtin_function_or_method'>
141141
>>> try:
142142
... s.b
143143
... except AttributeError:

IPython/utils/sysinfo.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from ConfigParser import ConfigParser
2424

2525
from IPython.core import release
26+
from IPython.utils import py3compat
2627

2728
#-----------------------------------------------------------------------------
2829
# Globals
@@ -113,6 +114,7 @@ def pkg_info(pkg_path):
113114
)
114115

115116

117+
@py3compat.doctest_refactor_print
116118
def sys_info():
117119
"""Return useful information about IPython and the system, as a string.
118120

IPython/utils/tests/test_io.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
from IPython.testing import decorators as dec
2323
from IPython.utils.io import Tee
24+
from IPython.utils.py3compat import doctest_refactor_print
2425

2526
#-----------------------------------------------------------------------------
2627
# Tests
@@ -32,8 +33,8 @@ def test_tee_simple():
3233
chan = StringIO()
3334
text = 'Hello'
3435
tee = Tee(chan, channel='stdout')
35-
print >> chan, text,
36-
nt.assert_equal(chan.getvalue(), text)
36+
print >> chan, text
37+
nt.assert_equal(chan.getvalue(), text+"\n")
3738

3839

3940
class TeeTestCase(dec.ParametricTestCase):
@@ -64,8 +65,11 @@ def test(self):
6465
def test_io_init():
6566
"""Test that io.stdin/out/err exist at startup"""
6667
for name in ('stdin', 'stdout', 'stderr'):
67-
p = Popen([sys.executable, '-c', "from IPython.utils import io;print io.%s.__class__"%name],
68+
cmd = doctest_refactor_print("from IPython.utils import io;print io.%s.__class__"%name)
69+
p = Popen([sys.executable, '-c', cmd],
6870
stdout=PIPE)
6971
p.wait()
70-
classname = p.stdout.read().strip()
71-
nt.assert_equals(classname, 'IPython.utils.io.IOStream')
72+
classname = p.stdout.read().strip().decode('ascii')
73+
# __class__ is a reference to the class object in Python 3, so we can't
74+
# just test for string equality.
75+
assert 'IPython.utils.io.IOStream' in classname, classname

IPython/utils/tests/test_path.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import shutil
1919
import sys
2020
import tempfile
21-
import StringIO
21+
from io import StringIO
2222

2323
from os.path import join, abspath, split
2424

@@ -405,7 +405,7 @@ def test_not_writable_ipdir():
405405
os.mkdir(ipdir)
406406
os.chmod(ipdir, 600)
407407
stderr = io.stderr
408-
pipe = StringIO.StringIO()
408+
pipe = StringIO()
409409
io.stderr = pipe
410410
ipdir = path.get_ipython_dir()
411411
io.stderr.flush()

IPython/utils/tests/test_text.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def test_columnize_long():
4747
def test_eval_formatter():
4848
f = text.EvalFormatter()
4949
ns = dict(n=12, pi=math.pi, stuff='hello there', os=os)
50-
s = f.format("{n} {n/4} {stuff.split()[0]}", **ns)
50+
s = f.format("{n} {n//4} {stuff.split()[0]}", **ns)
5151
nt.assert_equals(s, "12 3 hello")
5252
s = f.format(' '.join(['{n//%i}'%i for i in range(1,8)]), **ns)
5353
nt.assert_equals(s, "12 6 4 3 2 2 1")

IPython/utils/tests/test_traitlets.py

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
Undefined, Type, This, Instance, TCPAddress, List, Tuple,
3131
ObjectName, DottedObjectName
3232
)
33-
33+
from IPython.utils import py3compat
3434

3535
#-----------------------------------------------------------------------------
3636
# Helper classes for testing
@@ -622,7 +622,10 @@ def test_good_values(self):
622622
def test_bad_values(self):
623623
if hasattr(self, '_bad_values'):
624624
for value in self._bad_values:
625-
self.assertRaises(TraitError, self.assign, value)
625+
try:
626+
self.assertRaises(TraitError, self.assign, value)
627+
except AssertionError:
628+
assert False, value
626629

627630
def test_default_value(self):
628631
if hasattr(self, '_default_value'):
@@ -651,9 +654,11 @@ class TestInt(TraitTestBase):
651654
obj = IntTrait()
652655
_default_value = 99
653656
_good_values = [10, -10]
654-
_bad_values = ['ten', u'ten', [10], {'ten': 10},(10,), None, 1j, 10L,
655-
-10L, 10.1, -10.1, '10L', '-10L', '10.1', '-10.1', u'10L',
657+
_bad_values = ['ten', u'ten', [10], {'ten': 10},(10,), None, 1j,
658+
10.1, -10.1, '10L', '-10L', '10.1', '-10.1', u'10L',
656659
u'-10L', u'10.1', u'-10.1', '10', '-10', u'10', u'-10']
660+
if not py3compat.PY3:
661+
_bad_values.extend([10L, -10L])
657662

658663

659664
class LongTrait(HasTraits):
@@ -682,9 +687,11 @@ class TestFloat(TraitTestBase):
682687

683688
_default_value = 99.0
684689
_good_values = [10, -10, 10.1, -10.1]
685-
_bad_values = [10L, -10L, 'ten', u'ten', [10], {'ten': 10},(10,), None,
690+
_bad_values = ['ten', u'ten', [10], {'ten': 10},(10,), None,
686691
1j, '10', '-10', '10L', '-10L', '10.1', '-10.1', u'10',
687692
u'-10', u'10L', u'-10L', u'10.1', u'-10.1']
693+
if not py3compat.PY3:
694+
_bad_values.extend([10L, -10L])
688695

689696

690697
class ComplexTrait(HasTraits):
@@ -698,7 +705,9 @@ class TestComplex(TraitTestBase):
698705
_default_value = 99.0-99.0j
699706
_good_values = [10, -10, 10.1, -10.1, 10j, 10+10j, 10-10j,
700707
10.1j, 10.1+10.1j, 10.1-10.1j]
701-
_bad_values = [10L, -10L, u'10L', u'-10L', 'ten', [10], {'ten': 10},(10,), None]
708+
_bad_values = [u'10L', u'-10L', 'ten', [10], {'ten': 10},(10,), None]
709+
if not py3compat.PY3:
710+
_bad_values.extend([10L, -10L])
702711

703712

704713
class BytesTrait(HasTraits):
@@ -835,12 +844,12 @@ def test_invalid_args(self):
835844

836845
class MultiTupleTrait(HasTraits):
837846

838-
value = Tuple(Int, Bytes, default_value=[99,'bottles'])
847+
value = Tuple(Int, Bytes, default_value=[99,b'bottles'])
839848

840849
class TestMultiTuple(TraitTestBase):
841850

842851
obj = MultiTupleTrait()
843852

844-
_default_value = (99,'bottles')
845-
_good_values = [(1,'a'), (2,'b')]
846-
_bad_values = ((),10, 'a', (1,'a',3), ('a',1))
853+
_default_value = (99,b'bottles')
854+
_good_values = [(1,b'a'), (2,b'b')]
855+
_bad_values = ((),10, b'a', (1,b'a',3), (b'a',1), (1, u'a'))

0 commit comments

Comments
 (0)