diff --git a/IPython/core/tests/test_autocall.py b/IPython/core/tests/test_autocall.py index 8db5b49..65123ab 100644 --- a/IPython/core/tests/test_autocall.py +++ b/IPython/core/tests/test_autocall.py @@ -5,7 +5,9 @@ directory, which we are removing. For now putting this here ensures at least we do run the test, though ultimately this functionality should all be tested with better-isolated tests that don't rely on the global instance in iptest. """ +from IPython.utils import py3compat +@py3compat.doctest_refactor_print def doctest_autocall(): """ In [1]: def f1(a,b,c): diff --git a/IPython/core/tests/test_handlers.py b/IPython/core/tests/test_handlers.py index 173b6fe..7696620 100644 --- a/IPython/core/tests/test_handlers.py +++ b/IPython/core/tests/test_handlers.py @@ -59,11 +59,12 @@ def test_handlers(): # These are useful for checking a particular recursive alias issue ip.alias_manager.alias_table['top'] = (0, 'd:/cygwin/top') ip.alias_manager.alias_table['d'] = (0, 'true') - run([("an_alias", 'get_ipython().system(u"true ")'), # alias + run([(i,py3compat.u_format(o)) for i,o in \ + [("an_alias", 'get_ipython().system({u}"true ")'), # alias # Below: recursive aliases should expand whitespace-surrounded # chars, *not* initial chars which happen to be aliases: - ("top", 'get_ipython().system(u"d:/cygwin/top ")'), - ]) + ("top", 'get_ipython().system({u}"d:/cygwin/top ")'), + ]]) ip.system = old_system_cmd call_idx = CallableIndexable() @@ -72,16 +73,17 @@ def test_handlers(): # For many of the below, we're also checking that leading whitespace # turns off the esc char, which it should unless there is a continuation # line. - run([('"no change"', '"no change"'), # normal - ("!true", 'get_ipython().system(u"true")'), # shell_escapes - ("!! true", 'get_ipython().magic(u"sx true")'), # shell_escapes + magic - ("!!true", 'get_ipython().magic(u"sx true")'), # shell_escapes + magic - ("%lsmagic", 'get_ipython().magic(u"lsmagic ")'), # magic - ("lsmagic", 'get_ipython().magic(u"lsmagic ")'), # magic + run([(i,py3compat.u_format(o)) for i,o in \ + [('"no change"', '"no change"'), # normal + ("!true", 'get_ipython().system({u}"true")'), # shell_escapes + ("!! true", 'get_ipython().magic({u}"sx true")'), # shell_escapes + magic + ("!!true", 'get_ipython().magic({u}"sx true")'), # shell_escapes + magic + ("%lsmagic", 'get_ipython().magic({u}"lsmagic ")'), # magic + ("lsmagic", 'get_ipython().magic({u}"lsmagic ")'), # magic #("a = b # PYTHON-MODE", '_i'), # emacs -- avoids _in cache # post-esc-char whitespace goes inside - ("! true", 'get_ipython().system(u" true")'), + ("! true", 'get_ipython().system({u}" true")'), # handle_help @@ -90,7 +92,7 @@ def test_handlers(): # lets us check the key paths through the handler. ("x=1 # what?", "x=1 # what?"), # no help if valid python - ]) + ]]) # multi_line_specials ip.prefilter_manager.multi_line_specials = False @@ -103,12 +105,12 @@ def test_handlers(): ip.prefilter_manager.multi_line_specials = True # initial indents must be preserved. - run([ - ('if 1:\n !true', 'if 1:\n get_ipython().system(u"true")'), - ('if 2:\n lsmagic', 'if 2:\n get_ipython().magic(u"lsmagic ")'), - ('if 1:\n an_alias', 'if 1:\n get_ipython().system(u"true ")'), + run([(i,py3compat.u_format(o)) for i,o in \ + [('if 1:\n !true', 'if 1:\n get_ipython().system({u}"true")'), + ('if 2:\n lsmagic', 'if 2:\n get_ipython().magic({u}"lsmagic ")'), + ('if 1:\n an_alias', 'if 1:\n get_ipython().system({u}"true ")'), # Weird one - ('if 1:\n !!true', 'if 1:\n get_ipython().magic(u"sx true")'), + ('if 1:\n !!true', 'if 1:\n get_ipython().magic({u}"sx true")'), # Even with m_l_s on, autocall is off even with special chars ('if 1:\n /fun 1 2', 'if 1:\n /fun 1 2'), @@ -116,7 +118,7 @@ def test_handlers(): ('if 1:\n ,fun 1 2', 'if 1:\n ,fun 1 2'), ('if 1:\n ?fun 1 2', 'if 1:\n ?fun 1 2'), # What about !! - ]) + ]]) # Objects which are instances of IPyAutocall are *always* autocalled autocallable = Autocallable() diff --git a/IPython/core/tests/test_inputsplitter.py b/IPython/core/tests/test_inputsplitter.py index 07e98a0..bf1d79c 100644 --- a/IPython/core/tests/test_inputsplitter.py +++ b/IPython/core/tests/test_inputsplitter.py @@ -26,6 +26,7 @@ import nose.tools as nt # Our own from IPython.core import inputsplitter as isp from IPython.testing import tools as tt +from IPython.utils import py3compat #----------------------------------------------------------------------------- # Semi-complete examples (also used as tests) @@ -403,18 +404,20 @@ def transform_checker(tests, func): syntax = \ dict(assign_system = - [('a =! ls', 'a = get_ipython().getoutput(u"ls")'), - ('b = !ls', 'b = get_ipython().getoutput(u"ls")'), + [(i,py3compat.u_format(o)) for i,o in \ + [('a =! ls', 'a = get_ipython().getoutput({u}"ls")'), + ('b = !ls', 'b = get_ipython().getoutput({u}"ls")'), ('x=1', 'x=1'), # normal input is unmodified (' ',' '), # blank lines are kept intact - ], + ]], assign_magic = - [('a =% who', 'a = get_ipython().magic(u"who")'), - ('b = %who', 'b = get_ipython().magic(u"who")'), + [(i,py3compat.u_format(o)) for i,o in \ + [('a =% who', 'a = get_ipython().magic({u}"who")'), + ('b = %who', 'b = get_ipython().magic({u}"who")'), ('x=1', 'x=1'), # normal input is unmodified (' ',' '), # blank lines are kept intact - ], + ]], classic_prompt = [('>>> x=1', 'x=1'), @@ -438,41 +441,45 @@ syntax = \ # System calls escaped_shell = - [ ('!ls', 'get_ipython().system(u"ls")'), + [(i,py3compat.u_format(o)) for i,o in \ + [ ('!ls', 'get_ipython().system({u}"ls")'), # Double-escape shell, this means to capture the output of the # subprocess and return it - ('!!ls', 'get_ipython().getoutput(u"ls")'), - ], + ('!!ls', 'get_ipython().getoutput({u}"ls")'), + ]], # Help/object info escaped_help = + [(i,py3compat.u_format(o)) for i,o in \ [ ('?', 'get_ipython().show_usage()'), - ('?x1', 'get_ipython().magic(u"pinfo x1")'), - ('??x2', 'get_ipython().magic(u"pinfo2 x2")'), - ('?a.*s', 'get_ipython().magic(u"psearch a.*s")'), - ('?%hist', 'get_ipython().magic(u"pinfo %hist")'), - ('?abc = qwe', 'get_ipython().magic(u"pinfo abc")'), - ], + ('?x1', 'get_ipython().magic({u}"pinfo x1")'), + ('??x2', 'get_ipython().magic({u}"pinfo2 x2")'), + ('?a.*s', 'get_ipython().magic({u}"psearch a.*s")'), + ('?%hist', 'get_ipython().magic({u}"pinfo %hist")'), + ('?abc = qwe', 'get_ipython().magic({u}"pinfo abc")'), + ]], end_help = - [ ('x3?', 'get_ipython().magic(u"pinfo x3")'), - ('x4??', 'get_ipython().magic(u"pinfo2 x4")'), - ('%hist?', 'get_ipython().magic(u"pinfo %hist")'), - ('f*?', 'get_ipython().magic(u"psearch f*")'), - ('ax.*aspe*?', 'get_ipython().magic(u"psearch ax.*aspe*")'), - ('a = abc?', 'get_ipython().magic(u"pinfo abc", next_input=u"a = abc")'), - ('a = abc.qe??', 'get_ipython().magic(u"pinfo2 abc.qe", next_input=u"a = abc.qe")'), - ('a = *.items?', 'get_ipython().magic(u"psearch *.items", next_input=u"a = *.items")'), - ('plot(a?', 'get_ipython().magic(u"pinfo a", next_input=u"plot(a")'), + [(i,py3compat.u_format(o)) for i,o in \ + [ ('x3?', 'get_ipython().magic({u}"pinfo x3")'), + ('x4??', 'get_ipython().magic({u}"pinfo2 x4")'), + ('%hist?', 'get_ipython().magic({u}"pinfo %hist")'), + ('f*?', 'get_ipython().magic({u}"psearch f*")'), + ('ax.*aspe*?', 'get_ipython().magic({u}"psearch ax.*aspe*")'), + ('a = abc?', 'get_ipython().magic({u}"pinfo abc", next_input={u}"a = abc")'), + ('a = abc.qe??', 'get_ipython().magic({u}"pinfo2 abc.qe", next_input={u}"a = abc.qe")'), + ('a = *.items?', 'get_ipython().magic({u}"psearch *.items", next_input={u}"a = *.items")'), + ('plot(a?', 'get_ipython().magic({u}"pinfo a", next_input={u}"plot(a")'), ('a*2 #comment?', 'a*2 #comment?'), - ], + ]], # Explicit magic calls escaped_magic = - [ ('%cd', 'get_ipython().magic(u"cd")'), - ('%cd /home', 'get_ipython().magic(u"cd /home")'), - (' %magic', ' get_ipython().magic(u"magic")'), - ], + [(i,py3compat.u_format(o)) for i,o in \ + [ ('%cd', 'get_ipython().magic({u}"cd")'), + ('%cd /home', 'get_ipython().magic({u}"cd /home")'), + (' %magic', ' get_ipython().magic({u}"magic")'), + ]], # Quoting with separate arguments escaped_quote = @@ -500,12 +507,13 @@ syntax = \ # Check that we transform prompts before other transforms mixed = - [ ('In [1]: %lsmagic', 'get_ipython().magic(u"lsmagic")'), - ('>>> %lsmagic', 'get_ipython().magic(u"lsmagic")'), - ('In [2]: !ls', 'get_ipython().system(u"ls")'), - ('In [3]: abs?', 'get_ipython().magic(u"pinfo abs")'), - ('In [4]: b = %who', 'b = get_ipython().magic(u"who")'), - ], + [(i,py3compat.u_format(o)) for i,o in \ + [ ('In [1]: %lsmagic', 'get_ipython().magic({u}"lsmagic")'), + ('>>> %lsmagic', 'get_ipython().magic({u}"lsmagic")'), + ('In [2]: !ls', 'get_ipython().system({u}"ls")'), + ('In [3]: abs?', 'get_ipython().magic({u}"pinfo abs")'), + ('In [4]: b = %who', 'b = get_ipython().magic({u}"who")'), + ]], ) # multiline syntax examples. Each of these should be a list of lists, with diff --git a/IPython/core/tests/test_iplib.py b/IPython/core/tests/test_iplib.py index dba13a5..5e6d5d6 100644 --- a/IPython/core/tests/test_iplib.py +++ b/IPython/core/tests/test_iplib.py @@ -147,7 +147,7 @@ ZeroDivisionError Traceback (most recent call last) ZeroDivisionError: ... """ - +@py3compat.u_format def doctest_tb_sysexit(): """ In [17]: %xmode plain @@ -155,11 +155,11 @@ Exception reporting mode: Plain In [18]: %run simpleerr.py exit An exception has occurred, use %tb to see the full traceback. -SystemExit: (1, u'Mode = exit') +SystemExit: (1, {u}'Mode = exit') In [19]: %run simpleerr.py exit 2 An exception has occurred, use %tb to see the full traceback. -SystemExit: (2, u'Mode = exit') +SystemExit: (2, {u}'Mode = exit') In [20]: %tb Traceback (most recent call last): @@ -169,7 +169,7 @@ Traceback (most recent call last): sysexit(stat, mode) File ... line 11, in sysexit raise SystemExit(stat, 'Mode = %s' % mode) -SystemExit: (2, u'Mode = exit') +SystemExit: (2, {u}'Mode = exit') In [21]: %xmode context Exception reporting mode: Context @@ -197,7 +197,7 @@ SystemExit Traceback (most recent call last) 12 13 def bar(mode): -SystemExit: (2, u'Mode = exit') +SystemExit: (2, {u}'Mode = exit') In [23]: %xmode verbose Exception reporting mode: Verbose @@ -211,29 +211,29 @@ SystemExit Traceback (most recent call last) 31 ---> 32 bar(mode) global bar = - global mode = u'exit' + global mode = {u}'exit' -... in bar(mode=u'exit') +... in bar(mode={u}'exit') 20 except: 21 stat = 1 ---> 22 sysexit(stat, mode) global sysexit = stat = 2 - mode = u'exit' + mode = {u}'exit' 23 else: 24 raise ValueError('Unknown mode') -... in sysexit(stat=2, mode=u'exit') +... in sysexit(stat=2, mode={u}'exit') 9 10 def sysexit(stat, mode): ---> 11 raise SystemExit(stat, 'Mode = %s' % mode) global SystemExit = undefined stat = 2 - mode = u'exit' + mode = {u}'exit' 12 13 def bar(mode): -SystemExit: (2, u'Mode = exit') +SystemExit: (2, {u}'Mode = exit') """ diff --git a/IPython/core/tests/test_magic.py b/IPython/core/tests/test_magic.py index 5b9f6b6..504e509 100644 --- a/IPython/core/tests/test_magic.py +++ b/IPython/core/tests/test_magic.py @@ -19,6 +19,7 @@ import nose.tools as nt from IPython.utils.path import get_long_path_name from IPython.testing import decorators as dec from IPython.testing import tools as tt +from IPython.utils import py3compat #----------------------------------------------------------------------------- # Test functions begin @@ -88,20 +89,20 @@ def doctest_hist_r(): def doctest_hist_op(): """Test %hist -op - In [1]: class b: - ...: pass + In [1]: class b(float): + ...: pass ...: - In [2]: class s(b): - ...: def __str__(self): - ...: return 's' + In [2]: class s(object): + ...: def __str__(self): + ...: return 's' ...: In [3]: In [4]: class r(b): - ...: def __repr__(self): - ...: return 'r' + ...: def __repr__(self): + ...: return 'r' ...: In [5]: class sr(s,r): pass @@ -117,11 +118,11 @@ def doctest_hist_op(): In [10]: ssrr=sr() - In [11]: bb - Out[11]: <...b instance at ...> + In [11]: 4.5 + Out[11]: 4.5 - In [12]: ss - Out[12]: <...s instance at ...> + In [12]: str(ss) + Out[12]: 's' In [13]: @@ -144,10 +145,10 @@ def doctest_hist_op(): >>> ss=s() >>> rr=r() >>> ssrr=sr() - >>> bb - <...b instance at ...> - >>> ss - <...s instance at ...> + >>> 4.5 + 4.5 + >>> str(ss) + 's' >>> """ @@ -167,10 +168,12 @@ def test_macro_run(): """Test that we can run a multi-line macro successfully.""" ip = get_ipython() ip.history_manager.reset() - cmds = ["a=10", "a+=1", "print a", "%macro test 2-3"] + cmds = ["a=10", "a+=1", py3compat.doctest_refactor_print("print a"), + "%macro test 2-3"] for cmd in cmds: ip.run_cell(cmd) - nt.assert_equal(ip.user_ns["test"].value, "a+=1\nprint a\n") + nt.assert_equal(ip.user_ns["test"].value, + py3compat.doctest_refactor_print("a+=1\nprint a\n")) original_stdout = sys.stdout new_stdout = StringIO() sys.stdout = new_stdout @@ -269,6 +272,7 @@ def test_time(): _ip.magic('time None') +@py3compat.doctest_refactor_print def doctest_time(): """ In [10]: %time None @@ -442,21 +446,22 @@ def doctest_who(): Out[7]: ['alpha', 'beta'] """ +@py3compat.u_format def doctest_precision(): """doctest for %precision In [1]: f = get_ipython().shell.display_formatter.formatters['text/plain'] In [2]: %precision 5 - Out[2]: u'%.5f' + Out[2]: {u}'%.5f' In [3]: f.float_format - Out[3]: u'%.5f' + Out[3]: {u}'%.5f' In [4]: %precision %e - Out[4]: u'%e' + Out[4]: {u}'%e' In [5]: f(3.1415927) - Out[5]: u'3.141593e+00' + Out[5]: {u}'3.141593e+00' """ diff --git a/IPython/core/tests/test_run.py b/IPython/core/tests/test_run.py index 3077bc4..7cbbb54 100644 --- a/IPython/core/tests/test_run.py +++ b/IPython/core/tests/test_run.py @@ -21,6 +21,7 @@ from nose import SkipTest from IPython.testing import decorators as dec from IPython.testing import tools as tt +from IPython.utils.py3compat import doctest_refactor_print #----------------------------------------------------------------------------- # Test functions begin @@ -57,7 +58,7 @@ def doctest_run_builtins(): In [3]: f = open(fname,'w') - In [4]: f.write('pass\n') + In [4]: dummy= f.write('pass\n') In [5]: f.flush() @@ -84,6 +85,7 @@ def doctest_run_builtins(): ....: """ +@doctest_refactor_print def doctest_reset_del(): """Test that resetting doesn't cause errors in __del__ methods.