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