Skip to content

Commit

Permalink
Merge pull request ipython#5841 from takluyver/i2412
Browse files Browse the repository at this point in the history
Fix writing history with output to a file in Python 2
  • Loading branch information
minrk committed May 13, 2014
2 parents e972614 + f501203 commit c62821c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
3 changes: 2 additions & 1 deletion IPython/core/magics/history.py
Expand Up @@ -24,6 +24,7 @@
parse_argstring)
from IPython.testing.skipdoctest import skip_doctest
from IPython.utils import io
from IPython.utils.py3compat import cast_unicode_py2

#-----------------------------------------------------------------------------
# Magics class implementation
Expand Down Expand Up @@ -213,7 +214,7 @@ def _format_lineno(session, line):
inline = "\n... ".join(inline.splitlines()) + "\n..."
print(inline, file=outfile)
if get_output and output:
print(output, file=outfile)
print(cast_unicode_py2(output), file=outfile)

if close_at_end:
outfile.close()
Expand Down
10 changes: 10 additions & 0 deletions IPython/core/tests/test_magic.py
Expand Up @@ -236,6 +236,16 @@ def doctest_hist_op():
>>>
"""

def test_hist_pof():
ip = get_ipython()
ip.run_cell(u"1+2", store_history=True)
#raise Exception(ip.history_manager.session_number)
#raise Exception(list(ip.history_manager._get_range_session()))
with TemporaryDirectory() as td:
tf = os.path.join(td, 'hist.py')
ip.run_line_magic('history', '-pof %s' % tf)
assert os.path.isfile(tf)


@dec.skip_without('sqlite3')
def test_macro():
Expand Down

0 comments on commit c62821c

Please sign in to comment.