Show More
@@ -15,11 +15,13 b' Utilities for working with stack frames.' | |||||
15 | #----------------------------------------------------------------------------- |
|
15 | #----------------------------------------------------------------------------- | |
16 |
|
16 | |||
17 | import sys |
|
17 | import sys | |
|
18 | from IPython.utils import py3compat | |||
18 |
|
19 | |||
19 | #----------------------------------------------------------------------------- |
|
20 | #----------------------------------------------------------------------------- | |
20 | # Code |
|
21 | # Code | |
21 | #----------------------------------------------------------------------------- |
|
22 | #----------------------------------------------------------------------------- | |
22 |
|
23 | |||
|
24 | @py3compat.doctest_refactor_print | |||
23 | def extract_vars(*names,**kw): |
|
25 | def extract_vars(*names,**kw): | |
24 | """Extract a set of variables by name from another frame. |
|
26 | """Extract a set of variables by name from another frame. | |
25 |
|
27 |
@@ -137,7 +137,7 b' class Struct(dict):' | |||||
137 | >>> s.a |
|
137 | >>> s.a | |
138 | 10 |
|
138 | 10 | |
139 | >>> type(s.get) |
|
139 | >>> type(s.get) | |
140 |
< |
|
140 | <... 'builtin_function_or_method'> | |
141 | >>> try: |
|
141 | >>> try: | |
142 | ... s.b |
|
142 | ... s.b | |
143 | ... except AttributeError: |
|
143 | ... except AttributeError: |
@@ -23,6 +23,7 b' import subprocess' | |||||
23 | from ConfigParser import ConfigParser |
|
23 | from ConfigParser import ConfigParser | |
24 |
|
24 | |||
25 | from IPython.core import release |
|
25 | from IPython.core import release | |
|
26 | from IPython.utils import py3compat | |||
26 |
|
27 | |||
27 | #----------------------------------------------------------------------------- |
|
28 | #----------------------------------------------------------------------------- | |
28 | # Globals |
|
29 | # Globals | |
@@ -113,6 +114,7 b' def pkg_info(pkg_path):' | |||||
113 | ) |
|
114 | ) | |
114 |
|
115 | |||
115 |
|
116 | |||
|
117 | @py3compat.doctest_refactor_print | |||
116 | def sys_info(): |
|
118 | def sys_info(): | |
117 | """Return useful information about IPython and the system, as a string. |
|
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 | from IPython.testing import decorators as dec |
|
22 | from IPython.testing import decorators as dec | |
23 | from IPython.utils.io import Tee |
|
23 | from IPython.utils.io import Tee | |
|
24 | from IPython.utils.py3compat import doctest_refactor_print | |||
24 |
|
25 | |||
25 | #----------------------------------------------------------------------------- |
|
26 | #----------------------------------------------------------------------------- | |
26 | # Tests |
|
27 | # Tests | |
@@ -32,8 +33,8 b' def test_tee_simple():' | |||||
32 | chan = StringIO() |
|
33 | chan = StringIO() | |
33 | text = 'Hello' |
|
34 | text = 'Hello' | |
34 | tee = Tee(chan, channel='stdout') |
|
35 | tee = Tee(chan, channel='stdout') | |
35 |
print >> chan, text |
|
36 | print >> chan, text | |
36 | nt.assert_equal(chan.getvalue(), text) |
|
37 | nt.assert_equal(chan.getvalue(), text+"\n") | |
37 |
|
38 | |||
38 |
|
39 | |||
39 | class TeeTestCase(dec.ParametricTestCase): |
|
40 | class TeeTestCase(dec.ParametricTestCase): | |
@@ -64,8 +65,11 b' class TeeTestCase(dec.ParametricTestCase):' | |||||
64 | def test_io_init(): |
|
65 | def test_io_init(): | |
65 | """Test that io.stdin/out/err exist at startup""" |
|
66 | """Test that io.stdin/out/err exist at startup""" | |
66 | for name in ('stdin', 'stdout', 'stderr'): |
|
67 | for name in ('stdin', 'stdout', 'stderr'): | |
67 |
|
|
68 | cmd = doctest_refactor_print("from IPython.utils import io;print io.%s.__class__"%name) | |
|
69 | p = Popen([sys.executable, '-c', cmd], | |||
68 | stdout=PIPE) |
|
70 | stdout=PIPE) | |
69 | p.wait() |
|
71 | p.wait() | |
70 | classname = p.stdout.read().strip() |
|
72 | classname = p.stdout.read().strip().decode('ascii') | |
71 | nt.assert_equals(classname, 'IPython.utils.io.IOStream') |
|
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 | import shutil |
|
18 | import shutil | |
19 | import sys |
|
19 | import sys | |
20 | import tempfile |
|
20 | import tempfile | |
21 | import StringIO |
|
21 | from io import StringIO | |
22 |
|
22 | |||
23 | from os.path import join, abspath, split |
|
23 | from os.path import join, abspath, split | |
24 |
|
24 | |||
@@ -405,7 +405,7 b' def test_not_writable_ipdir():' | |||||
405 | os.mkdir(ipdir) |
|
405 | os.mkdir(ipdir) | |
406 | os.chmod(ipdir, 600) |
|
406 | os.chmod(ipdir, 600) | |
407 | stderr = io.stderr |
|
407 | stderr = io.stderr | |
408 |
pipe = StringIO |
|
408 | pipe = StringIO() | |
409 | io.stderr = pipe |
|
409 | io.stderr = pipe | |
410 | ipdir = path.get_ipython_dir() |
|
410 | ipdir = path.get_ipython_dir() | |
411 | io.stderr.flush() |
|
411 | io.stderr.flush() |
@@ -47,7 +47,7 b' def test_columnize_long():' | |||||
47 | def test_eval_formatter(): |
|
47 | def test_eval_formatter(): | |
48 | f = text.EvalFormatter() |
|
48 | f = text.EvalFormatter() | |
49 | ns = dict(n=12, pi=math.pi, stuff='hello there', os=os) |
|
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 | nt.assert_equals(s, "12 3 hello") |
|
51 | nt.assert_equals(s, "12 3 hello") | |
52 | s = f.format(' '.join(['{n//%i}'%i for i in range(1,8)]), **ns) |
|
52 | s = f.format(' '.join(['{n//%i}'%i for i in range(1,8)]), **ns) | |
53 | nt.assert_equals(s, "12 6 4 3 2 2 1") |
|
53 | nt.assert_equals(s, "12 6 4 3 2 2 1") |
@@ -30,7 +30,7 b' from IPython.utils.traitlets import (' | |||||
30 | Undefined, Type, This, Instance, TCPAddress, List, Tuple, |
|
30 | Undefined, Type, This, Instance, TCPAddress, List, Tuple, | |
31 | ObjectName, DottedObjectName |
|
31 | ObjectName, DottedObjectName | |
32 | ) |
|
32 | ) | |
33 |
|
33 | from IPython.utils import py3compat | ||
34 |
|
34 | |||
35 | #----------------------------------------------------------------------------- |
|
35 | #----------------------------------------------------------------------------- | |
36 | # Helper classes for testing |
|
36 | # Helper classes for testing | |
@@ -622,7 +622,10 b' class TraitTestBase(TestCase):' | |||||
622 | def test_bad_values(self): |
|
622 | def test_bad_values(self): | |
623 | if hasattr(self, '_bad_values'): |
|
623 | if hasattr(self, '_bad_values'): | |
624 | for value in self._bad_values: |
|
624 | for value in self._bad_values: | |
|
625 | try: | |||
625 | self.assertRaises(TraitError, self.assign, value) |
|
626 | self.assertRaises(TraitError, self.assign, value) | |
|
627 | except AssertionError: | |||
|
628 | assert False, value | |||
626 |
|
629 | |||
627 | def test_default_value(self): |
|
630 | def test_default_value(self): | |
628 | if hasattr(self, '_default_value'): |
|
631 | if hasattr(self, '_default_value'): | |
@@ -651,9 +654,11 b' class TestInt(TraitTestBase):' | |||||
651 | obj = IntTrait() |
|
654 | obj = IntTrait() | |
652 | _default_value = 99 |
|
655 | _default_value = 99 | |
653 | _good_values = [10, -10] |
|
656 | _good_values = [10, -10] | |
654 |
_bad_values = ['ten', u'ten', [10], {'ten': 10},(10,), None, 1j, |
|
657 | _bad_values = ['ten', u'ten', [10], {'ten': 10},(10,), None, 1j, | |
655 |
|
|
658 | 10.1, -10.1, '10L', '-10L', '10.1', '-10.1', u'10L', | |
656 | u'-10L', u'10.1', u'-10.1', '10', '-10', u'10', u'-10'] |
|
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 | class LongTrait(HasTraits): |
|
664 | class LongTrait(HasTraits): | |
@@ -682,9 +687,11 b' class TestFloat(TraitTestBase):' | |||||
682 |
|
687 | |||
683 | _default_value = 99.0 |
|
688 | _default_value = 99.0 | |
684 | _good_values = [10, -10, 10.1, -10.1] |
|
689 | _good_values = [10, -10, 10.1, -10.1] | |
685 |
_bad_values = [ |
|
690 | _bad_values = ['ten', u'ten', [10], {'ten': 10},(10,), None, | |
686 | 1j, '10', '-10', '10L', '-10L', '10.1', '-10.1', u'10', |
|
691 | 1j, '10', '-10', '10L', '-10L', '10.1', '-10.1', u'10', | |
687 | u'-10', u'10L', u'-10L', u'10.1', u'-10.1'] |
|
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 | class ComplexTrait(HasTraits): |
|
697 | class ComplexTrait(HasTraits): | |
@@ -698,7 +705,9 b' class TestComplex(TraitTestBase):' | |||||
698 | _default_value = 99.0-99.0j |
|
705 | _default_value = 99.0-99.0j | |
699 | _good_values = [10, -10, 10.1, -10.1, 10j, 10+10j, 10-10j, |
|
706 | _good_values = [10, -10, 10.1, -10.1, 10j, 10+10j, 10-10j, | |
700 | 10.1j, 10.1+10.1j, 10.1-10.1j] |
|
707 | 10.1j, 10.1+10.1j, 10.1-10.1j] | |
701 |
_bad_values = [ |
|
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 | class BytesTrait(HasTraits): |
|
713 | class BytesTrait(HasTraits): | |
@@ -835,12 +844,12 b' class TestLooseTupleTrait(TraitTestBase):' | |||||
835 |
|
844 | |||
836 | class MultiTupleTrait(HasTraits): |
|
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 | class TestMultiTuple(TraitTestBase): |
|
849 | class TestMultiTuple(TraitTestBase): | |
841 |
|
850 | |||
842 | obj = MultiTupleTrait() |
|
851 | obj = MultiTupleTrait() | |
843 |
|
852 | |||
844 | _default_value = (99,'bottles') |
|
853 | _default_value = (99,b'bottles') | |
845 | _good_values = [(1,'a'), (2,'b')] |
|
854 | _good_values = [(1,b'a'), (2,b'b')] | |
846 | _bad_values = ((),10, 'a', (1,'a',3), ('a',1)) |
|
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