Show More
@@ -20,6 +20,7 b' import __future__' | |||||
20 | import bdb |
|
20 | import bdb | |
21 | import inspect |
|
21 | import inspect | |
22 | import imp |
|
22 | import imp | |
|
23 | import io | |||
23 | import os |
|
24 | import os | |
24 | import sys |
|
25 | import sys | |
25 | import shutil |
|
26 | import shutil | |
@@ -3682,7 +3683,7 b' Defaulting color scheme to \'NoColor\'"""' | |||||
3682 | cells.append(current.new_code_cell(prompt_number=prompt_number, input=input)) |
|
3683 | cells.append(current.new_code_cell(prompt_number=prompt_number, input=input)) | |
3683 | worksheet = current.new_worksheet(cells=cells) |
|
3684 | worksheet = current.new_worksheet(cells=cells) | |
3684 | nb = current.new_notebook(name=name,worksheets=[worksheet]) |
|
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 | current.write(nb, f, format); |
|
3687 | current.write(nb, f, format); | |
3687 | elif args.format is not None: |
|
3688 | elif args.format is not None: | |
3688 | old_fname, old_name, old_format = current.parse_filename(args.filename) |
|
3689 | old_fname, old_name, old_format = current.parse_filename(args.filename) | |
@@ -3696,13 +3697,9 b' Defaulting color scheme to \'NoColor\'"""' | |||||
3696 | new_fname = old_name + u'.py' |
|
3697 | new_fname = old_name + u'.py' | |
3697 | else: |
|
3698 | else: | |
3698 | raise ValueError('Invalid notebook format: %s' % new_format) |
|
3699 | raise ValueError('Invalid notebook format: %s' % new_format) | |
3699 | with open(old_fname, 'r') as f: |
|
3700 | with io.open(old_fname, 'r') as f: | |
3700 |
|
|
3701 | nb = current.read(f, old_format) | |
3701 | try: |
|
3702 | with io.open(new_fname, 'w') as f: | |
3702 | nb = current.reads(s, old_format) |
|
|||
3703 | except: |
|
|||
3704 | nb = current.reads(s, u'xml') |
|
|||
3705 | with open(new_fname, 'w') as f: |
|
|||
3706 | current.write(nb, f, new_format) |
|
3703 | current.write(nb, f, new_format) | |
3707 |
|
3704 | |||
3708 | def magic_config(self, s): |
|
3705 | def magic_config(self, s): |
@@ -1,3 +1,4 b'' | |||||
|
1 | # -*- coding: utf-8 -*- | |||
1 | """Tests for various magic functions. |
|
2 | """Tests for various magic functions. | |
2 |
|
3 | |||
3 | Needs to be run by nose (to make ipython session available). |
|
4 | Needs to be run by nose (to make ipython session available). | |
@@ -8,10 +9,13 b' from __future__ import absolute_import' | |||||
8 | # Imports |
|
9 | # Imports | |
9 | #----------------------------------------------------------------------------- |
|
10 | #----------------------------------------------------------------------------- | |
10 |
|
11 | |||
|
12 | import io | |||
11 | import os |
|
13 | import os | |
12 |
|
14 | |||
13 | import nose.tools as nt |
|
15 | import nose.tools as nt | |
14 |
|
16 | |||
|
17 | from IPython.nbformat.v3.tests.nbexamples import nb0 | |||
|
18 | from IPython.nbformat import current | |||
15 | from IPython.testing import decorators as dec |
|
19 | from IPython.testing import decorators as dec | |
16 | from IPython.testing import tools as tt |
|
20 | from IPython.testing import tools as tt | |
17 | from IPython.utils import py3compat |
|
21 | from IPython.utils import py3compat | |
@@ -21,6 +25,7 b' from IPython.utils.tempdir import TemporaryDirectory' | |||||
21 | # Test functions begin |
|
25 | # Test functions begin | |
22 | #----------------------------------------------------------------------------- |
|
26 | #----------------------------------------------------------------------------- | |
23 |
|
27 | |||
|
28 | ||||
24 | def test_rehashx(): |
|
29 | def test_rehashx(): | |
25 | # clear up everything |
|
30 | # clear up everything | |
26 | _ip = get_ipython() |
|
31 | _ip = get_ipython() | |
@@ -412,3 +417,34 b' def test_extension():' | |||||
412 | finally: |
|
417 | finally: | |
413 | _ip.ipython_dir = orig_ipython_dir |
|
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