diff --git a/IPython/core/tests/test_magic.py b/IPython/core/tests/test_magic.py index 89f46df..16610c7 100644 --- a/IPython/core/tests/test_magic.py +++ b/IPython/core/tests/test_magic.py @@ -12,7 +12,7 @@ from __future__ import absolute_import import io import os import sys -from unittest import TestCase +from unittest import TestCase, skipIf try: from importlib import invalidate_caches # Required from Python 3.3 @@ -28,8 +28,6 @@ from IPython.core.magic import (Magics, magics_class, line_magic, register_line_magic, register_cell_magic, register_line_cell_magic) from IPython.core.magics import execution, script, code -from IPython.nbformat.v3.tests.nbexamples import nb0 -from IPython.nbformat import current from IPython.testing import decorators as dec from IPython.testing import tools as tt from IPython.utils import py3compat @@ -600,37 +598,46 @@ def test_extension(): finally: _ip.ipython_dir = orig_ipython_dir tmpdir.cleanup() - -def test_notebook_export_json(): - with TemporaryDirectory() as td: - outfile = os.path.join(td, "nb.ipynb") - _ip.ex(py3compat.u_format(u"u = {u}'héllo'")) - _ip.magic("notebook -e %s" % outfile) -def test_notebook_export_py(): - with TemporaryDirectory() as td: - outfile = os.path.join(td, "nb.py") - _ip.ex(py3compat.u_format(u"u = {u}'héllo'")) - _ip.magic("notebook -e %s" % outfile) -def test_notebook_reformat_py(): - with TemporaryDirectory() as td: - infile = os.path.join(td, "nb.ipynb") - with io.open(infile, 'w', encoding='utf-8') as f: - current.write(nb0, f, 'json') - - _ip.ex(py3compat.u_format(u"u = {u}'héllo'")) - _ip.magic("notebook -f py %s" % infile) +# The nose skip decorator doesn't work on classes, so this uses unittest's skipIf +@skipIf(dec.module_not_available('IPython.nbformat.current'), 'nbformat not importable') +class NotebookExportMagicTests(TestCase): + def test_notebook_export_json(self): + with TemporaryDirectory() as td: + outfile = os.path.join(td, "nb.ipynb") + _ip.ex(py3compat.u_format(u"u = {u}'héllo'")) + _ip.magic("notebook -e %s" % outfile) + + def test_notebook_export_py(self): + with TemporaryDirectory() as td: + outfile = os.path.join(td, "nb.py") + _ip.ex(py3compat.u_format(u"u = {u}'héllo'")) + _ip.magic("notebook -e %s" % outfile) + + def test_notebook_reformat_py(self): + from IPython.nbformat.v3.tests.nbexamples import nb0 + from IPython.nbformat import current + with TemporaryDirectory() as td: + infile = os.path.join(td, "nb.ipynb") + with io.open(infile, 'w', encoding='utf-8') as f: + current.write(nb0, f, 'json') + + _ip.ex(py3compat.u_format(u"u = {u}'héllo'")) + _ip.magic("notebook -f py %s" % infile) + + def test_notebook_reformat_json(self): + from IPython.nbformat.v3.tests.nbexamples import nb0 + from IPython.nbformat import current + with TemporaryDirectory() as td: + infile = os.path.join(td, "nb.py") + with io.open(infile, 'w', encoding='utf-8') as f: + current.write(nb0, f, 'py') + + _ip.ex(py3compat.u_format(u"u = {u}'héllo'")) + _ip.magic("notebook -f ipynb %s" % infile) + _ip.magic("notebook -f json %s" % infile) -def test_notebook_reformat_json(): - with TemporaryDirectory() as td: - infile = os.path.join(td, "nb.py") - with io.open(infile, 'w', encoding='utf-8') as f: - current.write(nb0, f, 'py') - - _ip.ex(py3compat.u_format(u"u = {u}'héllo'")) - _ip.magic("notebook -f ipynb %s" % infile) - _ip.magic("notebook -f json %s" % infile) def test_env(): env = _ip.magic("env") diff --git a/IPython/core/tests/test_run.py b/IPython/core/tests/test_run.py index 62c58b7..2816e36 100644 --- a/IPython/core/tests/test_run.py +++ b/IPython/core/tests/test_run.py @@ -371,7 +371,8 @@ tclass.py: deleting object: C-third with tt.AssertNotPrints('SystemExit'): _ip.magic('run -e %s' % self.fname) - + + @dec.skip_without('IPython.nbformat.current') # Requires jsonschema def test_run_nb(self): """Test %run notebook.ipynb""" from IPython.nbformat import current diff --git a/IPython/terminal/tests/test_help.py b/IPython/terminal/tests/test_help.py index 44cae7c..fd197f8 100644 --- a/IPython/terminal/tests/test_help.py +++ b/IPython/terminal/tests/test_help.py @@ -12,6 +12,7 @@ #----------------------------------------------------------------------------- import IPython.testing.tools as tt +from IPython.testing.decorators import skip_without #----------------------------------------------------------------------------- # Tests @@ -36,5 +37,6 @@ def test_locate_help(): def test_locate_profile_help(): tt.help_all_output_test("locate profile") +@skip_without('IPython.nbformat.current') # Requires jsonschema to be installed def test_trust_help(): tt.help_all_output_test("trust")