diff --git a/IPython/lib/irunner.py b/IPython/lib/irunner.py index c7954dd..2c7e7bd 100755 --- a/IPython/lib/irunner.py +++ b/IPython/lib/irunner.py @@ -38,6 +38,7 @@ import sys # Third-party modules: we carry a copy of pexpect to reduce the need for # external dependencies, but our import checks for a system version first. from IPython.external import pexpect +from IPython.utils import py3compat # Global usage strings, to avoid indentation issues when typing it below. USAGE = """ @@ -287,6 +288,7 @@ class InteractiveRunner(object): self.run_file(args[0],opts.interact) +_ipython_cmd = "ipython3" if py3compat.PY3 else "ipython" # Specific runners for particular programs class IPythonRunner(InteractiveRunner): @@ -302,7 +304,7 @@ class IPythonRunner(InteractiveRunner): prompts would break this. """ - def __init__(self,program = 'ipython',args=None,out=sys.stdout,echo=True): + def __init__(self,program = _ipython_cmd, args=None, out=sys.stdout, echo=True): """New runner, optionally passing the ipython command to use.""" args0 = ['--colors=NoColor', '--no-term-title', @@ -318,7 +320,7 @@ class IPythonRunner(InteractiveRunner): class PythonRunner(InteractiveRunner): """Interactive Python runner.""" - def __init__(self,program='python',args=None,out=sys.stdout,echo=True): + def __init__(self,program=sys.executable, args=None, out=sys.stdout, echo=True): """New runner, optionally passing the python command to use.""" prompts = [r'>>> ',r'\.\.\. '] diff --git a/IPython/lib/tests/test_irunner.py b/IPython/lib/tests/test_irunner.py index dcad7aa..b49bc86 100644 --- a/IPython/lib/tests/test_irunner.py +++ b/IPython/lib/tests/test_irunner.py @@ -14,6 +14,7 @@ import unittest # IPython imports from IPython.lib import irunner from IPython.testing.decorators import known_failure_py3 +from IPython.utils.py3compat import doctest_refactor_print # Testing code begins class RunnerTestCase(unittest.TestCase): @@ -57,11 +58,11 @@ class RunnerTestCase(unittest.TestCase): self.assert_(mismatch==0,'Number of mismatched lines: %s' % mismatch) - # irunner isn't working on Python 3 (due to pexpect) + # The SyntaxError appears differently in Python 3, for some reason. @known_failure_py3 def testIPython(self): """Test the IPython runner.""" - source = """ + source = doctest_refactor_print(""" print 'hello, this is python' # some more code x=1;y=2 @@ -76,13 +77,13 @@ cos pi cos(pi) for i in range(5): - print i, + print i print "that's all folks!" exit -""" - output = """\ +""") + output = doctest_refactor_print("""\ In [1]: print 'hello, this is python' hello, this is python @@ -119,24 +120,27 @@ Out[9]: -1.0 In [10]: for i in range(5): - ....: print i, + ....: print i ....: -0 1 2 3 4 +0 +1 +2 +3 +4 In [11]: print "that's all folks!" that's all folks! In [12]: exit -""" +""") runner = irunner.IPythonRunner(out=self.out) self._test_runner(runner,source,output) - @known_failure_py3 def testPython(self): """Test the Python runner.""" runner = irunner.PythonRunner(out=self.out) - source = """ + source = doctest_refactor_print(""" print 'hello, this is python' # some more code @@ -147,11 +151,11 @@ from math import * cos(pi) for i in range(5): - print i, + print i print "that's all folks!" - """ - output = """\ + """) + output = doctest_refactor_print("""\ >>> print 'hello, this is python' hello, this is python @@ -165,10 +169,14 @@ hello, this is python -1.0 >>> for i in range(5): -... print i, +... print i ... -0 1 2 3 4 +0 +1 +2 +3 +4 >>> print "that's all folks!" that's all folks! -""" +""") self._test_runner(runner,source,output) diff --git a/IPython/lib/tests/test_irunner_pylab_magic.py b/IPython/lib/tests/test_irunner_pylab_magic.py index 1d3ef7b..eb3f352 100644 --- a/IPython/lib/tests/test_irunner_pylab_magic.py +++ b/IPython/lib/tests/test_irunner_pylab_magic.py @@ -22,7 +22,6 @@ class RunnerTestCase(unittest.TestCase): self.out = StringIO.StringIO() #self.out = sys.stdout - @decorators.known_failure_py3 def _test_runner(self,runner,source,output): """Test that a given runner's input/output match.""" @@ -83,7 +82,6 @@ Out\[6\]: True runner = irunner.IPythonRunner(out=self.out) self._test_runner(runner,source,output) - @decorators.known_failure_py3 @decorators.skipif_not_matplotlib def test_pylab_import_all_disabled(self): "Verify that plot is not available when pylab_import_all = False"