Show More
@@ -12,7 +12,7 b' from __future__ import absolute_import' | |||||
12 | import io |
|
12 | import io | |
13 | import os |
|
13 | import os | |
14 | import sys |
|
14 | import sys | |
15 | from unittest import TestCase |
|
15 | from unittest import TestCase, skipIf | |
16 |
|
16 | |||
17 | try: |
|
17 | try: | |
18 | from importlib import invalidate_caches # Required from Python 3.3 |
|
18 | from importlib import invalidate_caches # Required from Python 3.3 | |
@@ -28,8 +28,6 b' from IPython.core.magic import (Magics, magics_class, line_magic,' | |||||
28 | register_line_magic, register_cell_magic, |
|
28 | register_line_magic, register_cell_magic, | |
29 | register_line_cell_magic) |
|
29 | register_line_cell_magic) | |
30 | from IPython.core.magics import execution, script, code |
|
30 | from IPython.core.magics import execution, script, code | |
31 | from IPython.nbformat.v3.tests.nbexamples import nb0 |
|
|||
32 | from IPython.nbformat import current |
|
|||
33 | from IPython.testing import decorators as dec |
|
31 | from IPython.testing import decorators as dec | |
34 | from IPython.testing import tools as tt |
|
32 | from IPython.testing import tools as tt | |
35 | from IPython.utils import py3compat |
|
33 | from IPython.utils import py3compat | |
@@ -600,37 +598,46 b' def test_extension():' | |||||
600 | finally: |
|
598 | finally: | |
601 | _ip.ipython_dir = orig_ipython_dir |
|
599 | _ip.ipython_dir = orig_ipython_dir | |
602 | tmpdir.cleanup() |
|
600 | tmpdir.cleanup() | |
603 |
|
||||
604 | def test_notebook_export_json(): |
|
|||
605 | with TemporaryDirectory() as td: |
|
|||
606 | outfile = os.path.join(td, "nb.ipynb") |
|
|||
607 | _ip.ex(py3compat.u_format(u"u = {u}'héllo'")) |
|
|||
608 | _ip.magic("notebook -e %s" % outfile) |
|
|||
609 |
|
601 | |||
610 | def test_notebook_export_py(): |
|
|||
611 | with TemporaryDirectory() as td: |
|
|||
612 | outfile = os.path.join(td, "nb.py") |
|
|||
613 | _ip.ex(py3compat.u_format(u"u = {u}'héllo'")) |
|
|||
614 | _ip.magic("notebook -e %s" % outfile) |
|
|||
615 |
|
602 | |||
616 | def test_notebook_reformat_py(): |
|
603 | # The nose skip decorator doesn't work on classes, so this uses unittest's skipIf | |
617 | with TemporaryDirectory() as td: |
|
604 | @skipIf(dec.module_not_available('IPython.nbformat.current'), 'nbformat not importable') | |
618 | infile = os.path.join(td, "nb.ipynb") |
|
605 | class NotebookExportMagicTests(TestCase): | |
619 | with io.open(infile, 'w', encoding='utf-8') as f: |
|
606 | def test_notebook_export_json(self): | |
620 | current.write(nb0, f, 'json') |
|
607 | with TemporaryDirectory() as td: | |
621 |
|
608 | outfile = os.path.join(td, "nb.ipynb") | ||
622 | _ip.ex(py3compat.u_format(u"u = {u}'héllo'")) |
|
609 | _ip.ex(py3compat.u_format(u"u = {u}'héllo'")) | |
623 |
_ip.magic("notebook - |
|
610 | _ip.magic("notebook -e %s" % outfile) | |
|
611 | ||||
|
612 | def test_notebook_export_py(self): | |||
|
613 | with TemporaryDirectory() as td: | |||
|
614 | outfile = os.path.join(td, "nb.py") | |||
|
615 | _ip.ex(py3compat.u_format(u"u = {u}'héllo'")) | |||
|
616 | _ip.magic("notebook -e %s" % outfile) | |||
|
617 | ||||
|
618 | def test_notebook_reformat_py(self): | |||
|
619 | from IPython.nbformat.v3.tests.nbexamples import nb0 | |||
|
620 | from IPython.nbformat import current | |||
|
621 | with TemporaryDirectory() as td: | |||
|
622 | infile = os.path.join(td, "nb.ipynb") | |||
|
623 | with io.open(infile, 'w', encoding='utf-8') as f: | |||
|
624 | current.write(nb0, f, 'json') | |||
|
625 | ||||
|
626 | _ip.ex(py3compat.u_format(u"u = {u}'héllo'")) | |||
|
627 | _ip.magic("notebook -f py %s" % infile) | |||
|
628 | ||||
|
629 | def test_notebook_reformat_json(self): | |||
|
630 | from IPython.nbformat.v3.tests.nbexamples import nb0 | |||
|
631 | from IPython.nbformat import current | |||
|
632 | with TemporaryDirectory() as td: | |||
|
633 | infile = os.path.join(td, "nb.py") | |||
|
634 | with io.open(infile, 'w', encoding='utf-8') as f: | |||
|
635 | current.write(nb0, f, 'py') | |||
|
636 | ||||
|
637 | _ip.ex(py3compat.u_format(u"u = {u}'héllo'")) | |||
|
638 | _ip.magic("notebook -f ipynb %s" % infile) | |||
|
639 | _ip.magic("notebook -f json %s" % infile) | |||
624 |
|
640 | |||
625 | def test_notebook_reformat_json(): |
|
|||
626 | with TemporaryDirectory() as td: |
|
|||
627 | infile = os.path.join(td, "nb.py") |
|
|||
628 | with io.open(infile, 'w', encoding='utf-8') as f: |
|
|||
629 | current.write(nb0, f, 'py') |
|
|||
630 |
|
||||
631 | _ip.ex(py3compat.u_format(u"u = {u}'héllo'")) |
|
|||
632 | _ip.magic("notebook -f ipynb %s" % infile) |
|
|||
633 | _ip.magic("notebook -f json %s" % infile) |
|
|||
634 |
|
641 | |||
635 | def test_env(): |
|
642 | def test_env(): | |
636 | env = _ip.magic("env") |
|
643 | env = _ip.magic("env") |
@@ -371,7 +371,8 b' tclass.py: deleting object: C-third' | |||||
371 |
|
371 | |||
372 | with tt.AssertNotPrints('SystemExit'): |
|
372 | with tt.AssertNotPrints('SystemExit'): | |
373 | _ip.magic('run -e %s' % self.fname) |
|
373 | _ip.magic('run -e %s' % self.fname) | |
374 |
|
374 | |||
|
375 | @dec.skip_without('IPython.nbformat.current') # Requires jsonschema | |||
375 | def test_run_nb(self): |
|
376 | def test_run_nb(self): | |
376 | """Test %run notebook.ipynb""" |
|
377 | """Test %run notebook.ipynb""" | |
377 | from IPython.nbformat import current |
|
378 | from IPython.nbformat import current |
@@ -12,6 +12,7 b'' | |||||
12 | #----------------------------------------------------------------------------- |
|
12 | #----------------------------------------------------------------------------- | |
13 |
|
13 | |||
14 | import IPython.testing.tools as tt |
|
14 | import IPython.testing.tools as tt | |
|
15 | from IPython.testing.decorators import skip_without | |||
15 |
|
16 | |||
16 | #----------------------------------------------------------------------------- |
|
17 | #----------------------------------------------------------------------------- | |
17 | # Tests |
|
18 | # Tests | |
@@ -36,5 +37,6 b' def test_locate_help():' | |||||
36 | def test_locate_profile_help(): |
|
37 | def test_locate_profile_help(): | |
37 | tt.help_all_output_test("locate profile") |
|
38 | tt.help_all_output_test("locate profile") | |
38 |
|
39 | |||
|
40 | @skip_without('IPython.nbformat.current') # Requires jsonschema to be installed | |||
39 | def test_trust_help(): |
|
41 | def test_trust_help(): | |
40 | tt.help_all_output_test("trust") |
|
42 | tt.help_all_output_test("trust") |
General Comments 0
You need to be logged in to leave comments.
Login now