##// END OF EJS Templates
Various fixes to tests in IPython.utils.
Thomas Kluyver -
Show More
@@ -15,11 +15,13 b' Utilities for working with stack frames.'
15 15 #-----------------------------------------------------------------------------
16 16
17 17 import sys
18 from IPython.utils import py3compat
18 19
19 20 #-----------------------------------------------------------------------------
20 21 # Code
21 22 #-----------------------------------------------------------------------------
22 23
24 @py3compat.doctest_refactor_print
23 25 def extract_vars(*names,**kw):
24 26 """Extract a set of variables by name from another frame.
25 27
@@ -137,7 +137,7 b' class Struct(dict):'
137 137 >>> s.a
138 138 10
139 139 >>> type(s.get)
140 <type 'builtin_function_or_method'>
140 <... 'builtin_function_or_method'>
141 141 >>> try:
142 142 ... s.b
143 143 ... except AttributeError:
@@ -23,6 +23,7 b' import subprocess'
23 23 from ConfigParser import ConfigParser
24 24
25 25 from IPython.core import release
26 from IPython.utils import py3compat
26 27
27 28 #-----------------------------------------------------------------------------
28 29 # Globals
@@ -113,6 +114,7 b' def pkg_info(pkg_path):'
113 114 )
114 115
115 116
117 @py3compat.doctest_refactor_print
116 118 def sys_info():
117 119 """Return useful information about IPython and the system, as a string.
118 120
@@ -21,6 +21,7 b' import nose.tools as nt'
21 21
22 22 from IPython.testing import decorators as dec
23 23 from IPython.utils.io import Tee
24 from IPython.utils.py3compat import doctest_refactor_print
24 25
25 26 #-----------------------------------------------------------------------------
26 27 # Tests
@@ -32,8 +33,8 b' def test_tee_simple():'
32 33 chan = StringIO()
33 34 text = 'Hello'
34 35 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")
37 38
38 39
39 40 class TeeTestCase(dec.ParametricTestCase):
@@ -64,8 +65,11 b' class TeeTestCase(dec.ParametricTestCase):'
64 65 def test_io_init():
65 66 """Test that io.stdin/out/err exist at startup"""
66 67 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],
68 70 stdout=PIPE)
69 71 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
@@ -18,7 +18,7 b' import os'
18 18 import shutil
19 19 import sys
20 20 import tempfile
21 import StringIO
21 from io import StringIO
22 22
23 23 from os.path import join, abspath, split
24 24
@@ -405,7 +405,7 b' def test_not_writable_ipdir():'
405 405 os.mkdir(ipdir)
406 406 os.chmod(ipdir, 600)
407 407 stderr = io.stderr
408 pipe = StringIO.StringIO()
408 pipe = StringIO()
409 409 io.stderr = pipe
410 410 ipdir = path.get_ipython_dir()
411 411 io.stderr.flush()
@@ -47,7 +47,7 b' def test_columnize_long():'
47 47 def test_eval_formatter():
48 48 f = text.EvalFormatter()
49 49 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)
51 51 nt.assert_equals(s, "12 3 hello")
52 52 s = f.format(' '.join(['{n//%i}'%i for i in range(1,8)]), **ns)
53 53 nt.assert_equals(s, "12 6 4 3 2 2 1")
@@ -30,7 +30,7 b' from IPython.utils.traitlets import ('
30 30 Undefined, Type, This, Instance, TCPAddress, List, Tuple,
31 31 ObjectName, DottedObjectName
32 32 )
33
33 from IPython.utils import py3compat
34 34
35 35 #-----------------------------------------------------------------------------
36 36 # Helper classes for testing
@@ -622,7 +622,10 b' class TraitTestBase(TestCase):'
622 622 def test_bad_values(self):
623 623 if hasattr(self, '_bad_values'):
624 624 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
626 629
627 630 def test_default_value(self):
628 631 if hasattr(self, '_default_value'):
@@ -651,9 +654,11 b' class TestInt(TraitTestBase):'
651 654 obj = IntTrait()
652 655 _default_value = 99
653 656 _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',
656 659 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])
657 662
658 663
659 664 class LongTrait(HasTraits):
@@ -682,9 +687,11 b' class TestFloat(TraitTestBase):'
682 687
683 688 _default_value = 99.0
684 689 _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,
686 691 1j, '10', '-10', '10L', '-10L', '10.1', '-10.1', u'10',
687 692 u'-10', u'10L', u'-10L', u'10.1', u'-10.1']
693 if not py3compat.PY3:
694 _bad_values.extend([10L, -10L])
688 695
689 696
690 697 class ComplexTrait(HasTraits):
@@ -698,7 +705,9 b' class TestComplex(TraitTestBase):'
698 705 _default_value = 99.0-99.0j
699 706 _good_values = [10, -10, 10.1, -10.1, 10j, 10+10j, 10-10j,
700 707 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])
702 711
703 712
704 713 class BytesTrait(HasTraits):
@@ -835,12 +844,12 b' class TestLooseTupleTrait(TraitTestBase):'
835 844
836 845 class MultiTupleTrait(HasTraits):
837 846
838 value = Tuple(Int, Bytes, default_value=[99,'bottles'])
847 value = Tuple(Int, Bytes, default_value=[99,b'bottles'])
839 848
840 849 class TestMultiTuple(TraitTestBase):
841 850
842 851 obj = MultiTupleTrait()
843 852
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'))
General Comments 0
You need to be logged in to leave comments. Login now