##// END OF EJS Templates
Update irunner to work in Python 3.
Thomas Kluyver -
Show More
@@ -38,6 +38,7 b' import sys'
38 38 # Third-party modules: we carry a copy of pexpect to reduce the need for
39 39 # external dependencies, but our import checks for a system version first.
40 40 from IPython.external import pexpect
41 from IPython.utils import py3compat
41 42
42 43 # Global usage strings, to avoid indentation issues when typing it below.
43 44 USAGE = """
@@ -287,6 +288,7 b' class InteractiveRunner(object):'
287 288
288 289 self.run_file(args[0],opts.interact)
289 290
291 _ipython_cmd = "ipython3" if py3compat.PY3 else "ipython"
290 292
291 293 # Specific runners for particular programs
292 294 class IPythonRunner(InteractiveRunner):
@@ -302,7 +304,7 b' class IPythonRunner(InteractiveRunner):'
302 304 prompts would break this.
303 305 """
304 306
305 def __init__(self,program = 'ipython',args=None,out=sys.stdout,echo=True):
307 def __init__(self,program = _ipython_cmd, args=None, out=sys.stdout, echo=True):
306 308 """New runner, optionally passing the ipython command to use."""
307 309 args0 = ['--colors=NoColor',
308 310 '--no-term-title',
@@ -318,7 +320,7 b' class IPythonRunner(InteractiveRunner):'
318 320 class PythonRunner(InteractiveRunner):
319 321 """Interactive Python runner."""
320 322
321 def __init__(self,program='python',args=None,out=sys.stdout,echo=True):
323 def __init__(self,program=sys.executable, args=None, out=sys.stdout, echo=True):
322 324 """New runner, optionally passing the python command to use."""
323 325
324 326 prompts = [r'>>> ',r'\.\.\. ']
@@ -14,6 +14,7 b' import unittest'
14 14 # IPython imports
15 15 from IPython.lib import irunner
16 16 from IPython.testing.decorators import known_failure_py3
17 from IPython.utils.py3compat import doctest_refactor_print
17 18
18 19 # Testing code begins
19 20 class RunnerTestCase(unittest.TestCase):
@@ -57,11 +58,11 b' class RunnerTestCase(unittest.TestCase):'
57 58 self.assert_(mismatch==0,'Number of mismatched lines: %s' %
58 59 mismatch)
59 60
60 # irunner isn't working on Python 3 (due to pexpect)
61 # The SyntaxError appears differently in Python 3, for some reason.
61 62 @known_failure_py3
62 63 def testIPython(self):
63 64 """Test the IPython runner."""
64 source = """
65 source = doctest_refactor_print("""
65 66 print 'hello, this is python'
66 67 # some more code
67 68 x=1;y=2
@@ -76,13 +77,13 b' cos pi'
76 77 cos(pi)
77 78
78 79 for i in range(5):
79 print i,
80 print i
80 81
81 82 print "that's all folks!"
82 83
83 84 exit
84 """
85 output = """\
85 """)
86 output = doctest_refactor_print("""\
86 87 In [1]: print 'hello, this is python'
87 88 hello, this is python
88 89
@@ -119,24 +120,27 b' Out[9]: -1.0'
119 120
120 121
121 122 In [10]: for i in range(5):
122 ....: print i,
123 ....: print i
123 124 ....:
124 0 1 2 3 4
125 0
126 1
127 2
128 3
129 4
125 130
126 131 In [11]: print "that's all folks!"
127 132 that's all folks!
128 133
129 134
130 135 In [12]: exit
131 """
136 """)
132 137 runner = irunner.IPythonRunner(out=self.out)
133 138 self._test_runner(runner,source,output)
134 139
135 @known_failure_py3
136 140 def testPython(self):
137 141 """Test the Python runner."""
138 142 runner = irunner.PythonRunner(out=self.out)
139 source = """
143 source = doctest_refactor_print("""
140 144 print 'hello, this is python'
141 145
142 146 # some more code
@@ -147,11 +151,11 b' from math import *'
147 151 cos(pi)
148 152
149 153 for i in range(5):
150 print i,
154 print i
151 155
152 156 print "that's all folks!"
153 """
154 output = """\
157 """)
158 output = doctest_refactor_print("""\
155 159 >>> print 'hello, this is python'
156 160 hello, this is python
157 161
@@ -165,10 +169,14 b' hello, this is python'
165 169 -1.0
166 170
167 171 >>> for i in range(5):
168 ... print i,
172 ... print i
169 173 ...
170 0 1 2 3 4
174 0
175 1
176 2
177 3
178 4
171 179 >>> print "that's all folks!"
172 180 that's all folks!
173 """
181 """)
174 182 self._test_runner(runner,source,output)
@@ -22,7 +22,6 b' class RunnerTestCase(unittest.TestCase):'
22 22 self.out = StringIO.StringIO()
23 23 #self.out = sys.stdout
24 24
25 @decorators.known_failure_py3
26 25 def _test_runner(self,runner,source,output):
27 26 """Test that a given runner's input/output match."""
28 27
@@ -83,7 +82,6 b' Out\\[6\\]: True'
83 82 runner = irunner.IPythonRunner(out=self.out)
84 83 self._test_runner(runner,source,output)
85 84
86 @decorators.known_failure_py3
87 85 @decorators.skipif_not_matplotlib
88 86 def test_pylab_import_all_disabled(self):
89 87 "Verify that plot is not available when pylab_import_all = False"
General Comments 0
You need to be logged in to leave comments. Login now