Skip to content

Commit

Permalink
Merge pull request #758 from mpacer/find_the_hidden_nose
Browse files Browse the repository at this point in the history
Removing more nose remnants via dependencies.
  • Loading branch information
takluyver authored Feb 9, 2018
2 parents 06b5452 + fcb6455 commit 626c82a
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 36 deletions.
6 changes: 3 additions & 3 deletions nbconvert/exporters/tests/test_asciidoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
import re

from traitlets.config import Config
from ipython_genutils.testing import decorators as dec

from .base import ExportersTestsBase
from ..asciidoc import ASCIIDocExporter
from ...utils.io import onlyif_cmds_exist

#-----------------------------------------------------------------------------
# Class
Expand All @@ -38,7 +38,7 @@ def test_constructor(self):
ASCIIDocExporter()


@dec.onlyif_cmds_exist('pandoc')
@onlyif_cmds_exist('pandoc')
def test_export(self):
"""
Can a ASCIIDocExporter export something?
Expand All @@ -49,7 +49,7 @@ def test_export(self):
assert re.findall(in_regex, output)
assert re.findall(out_regex, output)

@dec.onlyif_cmds_exist('pandoc')
@onlyif_cmds_exist('pandoc')
def test_export_no_prompt(self):
"""
Can a ASCIIDocExporter export something without prompts?
Expand Down
2 changes: 1 addition & 1 deletion nbconvert/exporters/tests/test_latex.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@

from .base import ExportersTestsBase
from ..latex import LatexExporter
from ...utils.io import onlyif_cmds_exist

from traitlets.config import Config
from nbformat import write
from nbformat import v4
from ipython_genutils.testing.decorators import onlyif_cmds_exist
from testpath.tempdir import TemporaryDirectory

from jinja2 import DictLoader
Expand Down
5 changes: 2 additions & 3 deletions nbconvert/exporters/tests/test_pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
import os
import shutil

from ipython_genutils.testing import decorators as dec
from testpath import tempdir

from .base import ExportersTestsBase
from ..pdf import PDFExporter
from ...utils.io import onlyif_cmds_exist


#-----------------------------------------------------------------------------
Expand All @@ -28,8 +28,7 @@ def test_constructor(self):
self.exporter_class()


@dec.onlyif_cmds_exist('xelatex')
@dec.onlyif_cmds_exist('pandoc')
@onlyif_cmds_exist('xelatex', 'pandoc')
def test_export(self):
"""Smoke test PDFExporter"""
with tempdir.TemporaryDirectory() as td:
Expand Down
2 changes: 1 addition & 1 deletion nbconvert/exporters/tests/test_rst.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

from .base import ExportersTestsBase
from ..rst import RSTExporter
from ipython_genutils.testing.decorators import onlyif_cmds_exist
from ...utils.io import onlyif_cmds_exist


class TestRSTExporter(ExportersTestsBase):
Expand Down
10 changes: 5 additions & 5 deletions nbconvert/filters/tests/test_markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
from functools import partial

from ipython_genutils.py3compat import string_types
from ipython_genutils.testing import decorators as dec

from ...utils.io import onlyif_cmds_exist
from ...tests.base import TestsBase
from ..pandoc import convert_pandoc
from ..markdown import markdown2html
Expand Down Expand Up @@ -48,7 +48,7 @@ class TestMarkdown(TestsBase):
('test', 'https://google.com/'),
]

@dec.onlyif_cmds_exist('pandoc')
@onlyif_cmds_exist('pandoc')
def test_markdown2latex(self):
"""markdown2latex test"""
for index, test in enumerate(self.tests):
Expand All @@ -57,7 +57,7 @@ def test_markdown2latex(self):
convert_pandoc, from_format='markdown', to_format='latex'),
test, self.tokens[index])

@dec.onlyif_cmds_exist('pandoc')
@onlyif_cmds_exist('pandoc')
def test_markdown2latex_markup(self):
"""markdown2latex with markup kwarg test"""
# This string should be passed through unaltered with pandoc's
Expand All @@ -79,7 +79,7 @@ def test_markdown2latex_markup(self):
convert_pandoc(s, 'markdown_strict+tex_math_dollars', 'latex'),
expected)

@dec.onlyif_cmds_exist('pandoc')
@onlyif_cmds_exist('pandoc')
def test_pandoc_extra_args(self):
# pass --no-wrap
s = '\n'.join([
Expand Down Expand Up @@ -227,7 +227,7 @@ def test_markdown2html_math_paragraph(self):
s = markdown2html(case)
self.assertIn(case, self._unescape(s))

@dec.onlyif_cmds_exist('pandoc')
@onlyif_cmds_exist('pandoc')
def test_markdown2rst(self):
"""markdown2rst test"""

Expand Down
5 changes: 3 additions & 2 deletions nbconvert/preprocessors/tests/test_svg2pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
# Copyright (c) IPython Development Team.
# Distributed under the terms of the Modified BSD License.

from ipython_genutils.testing import decorators as dec
from nbformat import v4 as nbformat

from .base import PreprocessorTestsBase
from ..svg2pdf import SVG2PDFPreprocessor
from ...utils.io import onlyif_cmds_exist


class Testsvg2pdf(PreprocessorTestsBase):
Expand Down Expand Up @@ -63,11 +63,12 @@ def test_constructor(self):
self.build_preprocessor()


@dec.onlyif_cmds_exist('inkscape')
@onlyif_cmds_exist('inkscape')
def test_output(self):
"""Test the output of the SVG2PDFPreprocessor"""
nb = self.build_notebook()
res = self.build_resources()
preprocessor = self.build_preprocessor()
nb, res = preprocessor(nb, res)
self.assertIn('application/pdf', nb.cells[0].outputs[0].data)

26 changes: 12 additions & 14 deletions nbconvert/tests/test_nbconvertapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@

from .base import TestsBase
from ..postprocessors import PostProcessorBase
from ..utils.io import onlyif_cmds_exist
from nbconvert import nbconvertapp
from nbconvert.exporters import Exporter


from traitlets.tests.utils import check_help_all_output
from ipython_genutils.testing import decorators as dec
from testpath import tempdir
import pytest

Expand Down Expand Up @@ -117,8 +118,7 @@ def test_relative_template_file(self):
text = f.read()
assert text == test_output

@dec.onlyif_cmds_exist('xelatex')
@dec.onlyif_cmds_exist('pandoc')
@onlyif_cmds_exist('pandoc', 'xelatex')
def test_filename_spaces(self):
"""
Generate PDFs with graphics if notebooks have spaces in the name?
Expand All @@ -133,8 +133,7 @@ def test_filename_spaces(self):
assert os.path.isfile('notebook with spaces.pdf')


@dec.onlyif_cmds_exist('xelatex')
@dec.onlyif_cmds_exist('pandoc')
@onlyif_cmds_exist('pandoc', 'xelatex')
def test_pdf(self):
"""
Check to see if pdfs compile, even if strikethroughs are included.
Expand All @@ -154,7 +153,7 @@ def test_post_processor(self):
'--post nbconvert.tests.test_nbconvertapp.DummyPost')
self.assertIn('Dummy:notebook1.py', out)

@dec.onlyif_cmds_exist('pandoc')
@onlyif_cmds_exist('pandoc')
def test_spurious_cr(self):
"""Check for extra CR characters"""
with self.create_temp_cwd(['notebook2.ipynb']):
Expand All @@ -169,7 +168,7 @@ def test_spurious_cr(self):
self.assertEqual(tex.count('\r'), tex.count('\r\n'))
self.assertEqual(html.count('\r'), html.count('\r\n'))

@dec.onlyif_cmds_exist('pandoc')
@onlyif_cmds_exist('pandoc')
def test_png_base64_html_ok(self):
"""Is embedded png data well formed in HTML?"""
with self.create_temp_cwd(['notebook2.ipynb']):
Expand All @@ -179,7 +178,7 @@ def test_png_base64_html_ok(self):
with open('notebook2.html') as f:
assert "data:image/png;base64,b'" not in f.read()

@dec.onlyif_cmds_exist('pandoc')
@onlyif_cmds_exist('pandoc')
def test_template(self):
"""
Do export templates work?
Expand Down Expand Up @@ -254,7 +253,7 @@ def test_accents_in_filename(self):
self.nbconvert('--log-level 0 --to Python nb1_*')
assert os.path.isfile(u'nb1_análisis.py')

@dec.onlyif_cmds_exist('xelatex', 'pandoc')
@onlyif_cmds_exist('xelatex', 'pandoc')
def test_filename_accent_pdf(self):
"""
Generate PDFs if notebooks have an accent in their name?
Expand Down Expand Up @@ -408,8 +407,7 @@ def test_convert_from_stdin(self):
assert '```python' not in output1 # shouldn't have language
assert "```" in output1 # but should have fenced blocks

@dec.onlyif_cmds_exist('xelatex')
@dec.onlyif_cmds_exist('pandoc')
@onlyif_cmds_exist('pandoc', 'xelatex')
def test_linked_images(self):
"""
Generate PDFs with an image linked in a markdown cell
Expand All @@ -418,7 +416,7 @@ def test_linked_images(self):
self.nbconvert('--to pdf latex-linked-image.ipynb')
assert os.path.isfile('latex-linked-image.pdf')

@dec.onlyif_cmds_exist('pandoc')
@onlyif_cmds_exist('pandoc')
def test_embedded_jpeg(self):
"""
Verify that latex conversion succeeds
Expand All @@ -429,7 +427,7 @@ def test_embedded_jpeg(self):
self.nbconvert('--to latex notebook4_jpeg.ipynb')
assert os.path.isfile('notebook4_jpeg.tex')

@dec.onlyif_cmds_exist('pandoc')
@onlyif_cmds_exist('pandoc')
def test_markdown_display_priority(self):
"""
Check to see if markdown conversion embedds PNGs,
Expand All @@ -444,7 +442,7 @@ def test_markdown_display_priority(self):
assert ("markdown_display_priority_files/"
"markdown_display_priority_0_1.png") in markdown_output

@dec.onlyif_cmds_exist('pandoc')
@onlyif_cmds_exist('pandoc')
def test_write_figures_to_custom_path(self):
"""
Check if figure files are copied to configured path.
Expand Down
14 changes: 13 additions & 1 deletion nbconvert/utils/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@

import codecs
import sys
from ipython_genutils.py3compat import PY3

import pytest

from ipython_genutils.py3compat import PY3, which

def unicode_std_stream(stream='stdout'):
u"""Get a wrapper to write unicode to stdout/stderr as UTF-8.
Expand Down Expand Up @@ -51,3 +53,13 @@ def unicode_stdin_stream():
stream_b = stream

return codecs.getreader('utf-8')(stream_b)

def onlyif_cmds_exist(*commands):
"""
Decorator to skip test when at least one of `commands` is not found.
"""
for cmd in commands:
if not which(cmd):
return pytest.mark.skip("This test runs only if command '{0}' "
"is installed".format(cmd))
return lambda f: f
6 changes: 4 additions & 2 deletions nbconvert/utils/tests/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
import io as stdlib_io
import sys

from ipython_genutils.testing.decorators import skipif
import pytest

from ..io import unicode_std_stream
from ipython_genutils.py3compat import PY3

Expand Down Expand Up @@ -36,7 +37,8 @@ def test_UnicodeStdStream():
finally:
sys.stdout = orig_stdout

@skipif(not PY3, "Not applicable on Python 2")
@pytest.mark.skipif(not PY3,
reason = "Not applicable on Python 2")
def test_UnicodeStdStream_nowrap():
# If we replace stdout with a StringIO, it shouldn't get wrapped.
orig_stdout = sys.stdout
Expand Down
6 changes: 3 additions & 3 deletions nbconvert/utils/tests/test_pandoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import os
import warnings

from ipython_genutils.testing import decorators as dec
from ..io import onlyif_cmds_exist

from nbconvert.tests.base import TestsBase
from .. import pandoc
Expand All @@ -27,7 +27,7 @@ def __init__(self, *args, **kwargs):
super(TestPandoc, self).__init__(*args, **kwargs)
self.original_env = os.environ.copy()

@dec.onlyif_cmds_exist('pandoc')
@onlyif_cmds_exist('pandoc')
def test_pandoc_available(self):
""" Test behaviour that pandoc functions raise PandocMissing as documented """
pandoc.clean_cache()
Expand All @@ -48,7 +48,7 @@ def test_pandoc_available(self):
pandoc.pandoc("", "markdown", "html")
self.assertEqual(w, [])

@dec.onlyif_cmds_exist('pandoc')
@onlyif_cmds_exist('pandoc')
def test_minimal_version(self):
original_minversion = pandoc._minimal_version

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def run(self):
]

extra_requirements = {
'test': ['pytest', 'pytest-cov', 'ipykernel', 'jupyter_client>=4.2', 'nose'],
'test': ['pytest', 'pytest-cov', 'ipykernel', 'jupyter_client>=4.2'],
'serve': ['tornado>=4.0'],
'execute': ['jupyter_client>=4.2'],
}
Expand Down

0 comments on commit 626c82a

Please sign in to comment.