Show More
@@ -20,6 +20,7 import __future__ | |||
|
20 | 20 | import bdb |
|
21 | 21 | import inspect |
|
22 | 22 | import imp |
|
23 | import io | |
|
23 | 24 | import os |
|
24 | 25 | import sys |
|
25 | 26 | import shutil |
@@ -3682,7 +3683,7 Defaulting color scheme to 'NoColor'""" | |||
|
3682 | 3683 | cells.append(current.new_code_cell(prompt_number=prompt_number, input=input)) |
|
3683 | 3684 | worksheet = current.new_worksheet(cells=cells) |
|
3684 | 3685 | nb = current.new_notebook(name=name,worksheets=[worksheet]) |
|
3685 | with open(fname, 'w') as f: | |
|
3686 | with io.open(fname, 'w') as f: | |
|
3686 | 3687 | current.write(nb, f, format); |
|
3687 | 3688 | elif args.format is not None: |
|
3688 | 3689 | old_fname, old_name, old_format = current.parse_filename(args.filename) |
@@ -3696,13 +3697,9 Defaulting color scheme to 'NoColor'""" | |||
|
3696 | 3697 | new_fname = old_name + u'.py' |
|
3697 | 3698 | else: |
|
3698 | 3699 | raise ValueError('Invalid notebook format: %s' % new_format) |
|
3699 | with open(old_fname, 'r') as f: | |
|
3700 |
|
|
|
3701 | try: | |
|
3702 | nb = current.reads(s, old_format) | |
|
3703 | except: | |
|
3704 | nb = current.reads(s, u'xml') | |
|
3705 | with open(new_fname, 'w') as f: | |
|
3700 | with io.open(old_fname, 'r') as f: | |
|
3701 | nb = current.read(f, old_format) | |
|
3702 | with io.open(new_fname, 'w') as f: | |
|
3706 | 3703 | current.write(nb, f, new_format) |
|
3707 | 3704 | |
|
3708 | 3705 | def magic_config(self, s): |
@@ -1,3 +1,4 | |||
|
1 | # -*- coding: utf-8 -*- | |
|
1 | 2 | """Tests for various magic functions. |
|
2 | 3 | |
|
3 | 4 | Needs to be run by nose (to make ipython session available). |
@@ -8,10 +9,13 from __future__ import absolute_import | |||
|
8 | 9 | # Imports |
|
9 | 10 | #----------------------------------------------------------------------------- |
|
10 | 11 | |
|
12 | import io | |
|
11 | 13 | import os |
|
12 | 14 | |
|
13 | 15 | import nose.tools as nt |
|
14 | 16 | |
|
17 | from IPython.nbformat.v3.tests.nbexamples import nb0 | |
|
18 | from IPython.nbformat import current | |
|
15 | 19 | from IPython.testing import decorators as dec |
|
16 | 20 | from IPython.testing import tools as tt |
|
17 | 21 | from IPython.utils import py3compat |
@@ -21,6 +25,7 from IPython.utils.tempdir import TemporaryDirectory | |||
|
21 | 25 | # Test functions begin |
|
22 | 26 | #----------------------------------------------------------------------------- |
|
23 | 27 | |
|
28 | ||
|
24 | 29 | def test_rehashx(): |
|
25 | 30 | # clear up everything |
|
26 | 31 | _ip = get_ipython() |
@@ -412,3 +417,34 def test_extension(): | |||
|
412 | 417 | finally: |
|
413 | 418 | _ip.ipython_dir = orig_ipython_dir |
|
414 | 419 | |
|
420 | def test_notebook_export_json(): | |
|
421 | with TemporaryDirectory() as td: | |
|
422 | outfile = os.path.join(td, "nb.ipynb") | |
|
423 | _ip.ex(py3compat.u_format("u = {u}'héllo'")) | |
|
424 | _ip.magic("notebook -e %s" % outfile) | |
|
425 | ||
|
426 | def test_notebook_export_py(): | |
|
427 | with TemporaryDirectory() as td: | |
|
428 | outfile = os.path.join(td, "nb.py") | |
|
429 | _ip.ex(py3compat.u_format("u = {u}'héllo'")) | |
|
430 | _ip.magic("notebook -e %s" % outfile) | |
|
431 | ||
|
432 | def test_notebook_reformat_py(): | |
|
433 | with TemporaryDirectory() as td: | |
|
434 | infile = os.path.join(td, "nb.ipynb") | |
|
435 | with io.open(infile, 'w') as f: | |
|
436 | current.write(nb0, f, 'json') | |
|
437 | ||
|
438 | _ip.ex(py3compat.u_format("u = {u}'héllo'")) | |
|
439 | _ip.magic("notebook -f py %s" % infile) | |
|
440 | ||
|
441 | def test_notebook_reformat_json(): | |
|
442 | with TemporaryDirectory() as td: | |
|
443 | infile = os.path.join(td, "nb.py") | |
|
444 | with io.open(infile, 'w') as f: | |
|
445 | current.write(nb0, f, 'py') | |
|
446 | ||
|
447 | _ip.ex(py3compat.u_format("u = {u}'héllo'")) | |
|
448 | _ip.magic("notebook -f ipynb %s" % infile) | |
|
449 | _ip.magic("notebook -f json %s" % infile) | |
|
450 |
General Comments 0
You need to be logged in to leave comments.
Login now