Skip to content

Commit

Permalink
Merge pull request #595 from mpacer/to_spite_the_face
Browse files Browse the repository at this point in the history
"…to spite the face"
  • Loading branch information
takluyver authored May 26, 2017
2 parents 62628fd + 95760ac commit 21bf6c4
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 45 deletions.
1 change: 1 addition & 0 deletions nbconvert/exporters/html.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
"""HTML Exporter class"""

# Copyright (c) Jupyter Development Team.
Expand Down
1 change: 1 addition & 0 deletions nbconvert/filters/markdown_mistune.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
"""Markdown filters with mistune
Used from markdown.py
Expand Down
14 changes: 6 additions & 8 deletions nbconvert/filters/tests/test_metadata.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import nose.tools as nt

from nbconvert.filters import get_metadata

def test_get_metadata():
Expand All @@ -13,9 +11,9 @@ def test_get_metadata():
}
}
}
nt.assert_is(get_metadata(output, 'nowhere'), None)
nt.assert_equal(get_metadata(output, 'height'), 2)
nt.assert_equal(get_metadata(output, 'unconfined'), None)
nt.assert_equal(get_metadata(output, 'unconfined', 'image/png'), True)
nt.assert_equal(get_metadata(output, 'width', 'image/png'), 1)
nt.assert_equal(get_metadata(output, 'height', 'image/png'), 3)
assert get_metadata(output, 'nowhere') is None
assert get_metadata(output, 'height') == 2
assert get_metadata(output, 'unconfined') == None
assert get_metadata(output, 'unconfined', 'image/png') == True
assert get_metadata(output, 'width', 'image/png') == 1
assert get_metadata(output, 'height', 'image/png') == 3
8 changes: 5 additions & 3 deletions nbconvert/postprocessors/tests/test_serve.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,20 @@
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.

from nose import SkipTest
import pytest
from ...tests.base import TestsBase


class TestServe(TestsBase):
"""Contains test functions for serve.py"""


def test_constructor(self):
"""Can a ServePostProcessor be constructed?"""
pytest.importorskip("tornado")
try:
from ..serve import ServePostProcessor
except ImportError:
raise SkipTest("Serve post-processor test requires tornado")
print("Something weird is happening.\n"
"Tornado is sometimes present, sometimes not.")
raise
ServePostProcessor()
17 changes: 9 additions & 8 deletions nbconvert/preprocessors/tests/test_execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@

import nbformat
import sys
import pytest

from .base import PreprocessorTestsBase
from ..execute import ExecutePreprocessor, CellExecutionError, executenb

from nbconvert.filters import strip_ansi
from nose.tools import assert_raises, assert_in
from testpath import modified_env

addr_pat = re.compile(r'0x[0-9a-f]{7,9}')
Expand Down Expand Up @@ -157,7 +157,8 @@ def test_timeout(self):
except NameError:
exception = RuntimeError

assert_raises(exception, self.run_notebook, filename, dict(timeout=1), res)
with pytest.raises(exception):
self.run_notebook(filename, dict(timeout=1), res)

def test_timeout_func(self):
"""Check that an error is raised when a computation times out"""
Expand All @@ -173,7 +174,8 @@ def test_timeout_func(self):
def timeout_func(source):
return 10

assert_raises(exception, self.run_notebook, filename, dict(timeout_func=timeout_func), res)
with pytest.raises(exception):
self.run_notebook(filename, dict(timeout_func=timeout_func), res)

def test_allow_errors(self):
"""
Expand All @@ -183,14 +185,13 @@ def test_allow_errors(self):
filename = os.path.join(current_dir, 'files', 'Skip Exceptions.ipynb')
res = self.build_resources()
res['metadata']['path'] = os.path.dirname(filename)
with assert_raises(CellExecutionError) as exc:
with pytest.raises(CellExecutionError) as exc:
self.run_notebook(filename, dict(allow_errors=False), res)
self.assertIsInstance(str(exc.exception), str)
self.assertIsInstance(str(exc.value), str)
if sys.version_info >= (3, 0):
assert_in(u"# üñîçø∂é", str(exc.exception))
assert u"# üñîçø∂é" in str(exc.value)
else:
assert_in(u"# üñîçø∂é".encode('utf8', 'replace'),
str(exc.exception))
assert u"# üñîçø∂é".encode('utf8', 'replace') in str(exc.value)

def test_custom_kernel_manager(self):
from .fake_kernelmanager import FakeCustomKernelManager
Expand Down
15 changes: 5 additions & 10 deletions nbconvert/tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
import nbconvert
from subprocess import Popen, PIPE

import nose.tools as nt

from nbformat import v4, write
from testpath.tempdir import TemporaryWorkingDirectory

Expand Down Expand Up @@ -161,14 +159,11 @@ def assert_big_text_equal(a, b, chunk_size=80):
for i in range(0, len(a), chunk_size):
chunk_a = a[i:i + chunk_size]
chunk_b = b[i:i + chunk_size]
nt.assert_equal(chunk_a, chunk_b, "[offset: %i]\n%r != \n%r" % (
i, chunk_a, chunk_b))
assert chunk_a == chunk_b, "[offset: %i]\n%r != \n%r" % (i, chunk_a, chunk_b)

if len(a) > len(b):
nt.fail("Length doesn't match (%i > %i). Extra text:\n%r" % (
len(a), len(b), a[len(b):]
))
raise AssertionError("Length doesn't match (%i > %i). Extra text:\n%r" % (
len(a), len(b), a[len(b):]))
elif len(a) < len(b):
nt.fail("Length doesn't match (%i < %i). Extra text:\n%r" % (
len(a), len(b), b[len(a):]
))
raise AssertionError("Length doesn't match (%i < %i). Extra text:\n%r" % (
len(a), len(b), a[len(b):]))
22 changes: 11 additions & 11 deletions nbconvert/tests/test_nbconvertapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from traitlets.tests.utils import check_help_all_output
from ipython_genutils.testing import decorators as dec
from testpath import tempdir
from nose.tools import assert_raises, assert_in, assert_not_in
import pytest

#-----------------------------------------------------------------------------
# Classes and functions
Expand Down Expand Up @@ -351,7 +351,7 @@ def test_allow_errors(self):
assert '42' in output3

# Executing the notebook should raise an exception if --allow-errors is not specified
with assert_raises(OSError):
with pytest.raises(OSError):
self.nbconvert('--execute --to markdown --stdout notebook3*.ipynb')

def test_errors_print_traceback(self):
Expand All @@ -361,9 +361,9 @@ def test_errors_print_traceback(self):
with self.create_temp_cwd(['notebook3_with_errors.ipynb']):
_, error_output = self.nbconvert('--execute --to markdown --stdout notebook3_with_errors.ipynb',
ignore_return_code=True)
assert_in('print("Some text before the error")', error_output)
assert_in('raise RuntimeError("This is a deliberate exception")', error_output)
assert_in('RuntimeError: This is a deliberate exception', error_output)
assert 'print("Some text before the error")' in error_output
assert 'raise RuntimeError("This is a deliberate exception")' in error_output
assert 'RuntimeError: This is a deliberate exception' in error_output

def test_fenced_code_blocks_markdown(self):
"""
Expand Down Expand Up @@ -391,8 +391,8 @@ def test_convert_from_stdin_to_stdout(self):
with io.open('notebook1.ipynb') as f:
notebook = f.read().encode()
output1, _ = self.nbconvert('--to markdown --stdin --stdout', stdin=notebook)
assert_not_in('```python', output1) # shouldn't have language
assert_in("```", output1) # but should have fenced blocks
assert '```python' not in output1 # shouldn't have language
assert "```" in output1 # but should have fenced blocks

def test_convert_from_stdin(self):
"""
Expand All @@ -405,8 +405,8 @@ def test_convert_from_stdin(self):
assert os.path.isfile("notebook.md") # default name for stdin input
with io.open('notebook.md') as f:
output1 = f.read()
assert_not_in('```python', output1) # shouldn't have language
assert_in("```", output1) # but should have fenced blocks
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')
Expand Down Expand Up @@ -441,8 +441,8 @@ def test_markdown_display_priority(self):
assert os.path.isfile('markdown_display_priority.md')
with io.open('markdown_display_priority.md') as f:
markdown_output = f.read()
assert_in("markdown_display_priority_files/"
"markdown_display_priority_0_1.png", markdown_output)
assert ("markdown_display_priority_files/"
"markdown_display_priority_0_1.png") in markdown_output

@dec.onlyif_cmds_exist('pandoc')
def test_write_figures_to_custom_path(self):
Expand Down
4 changes: 2 additions & 2 deletions nbconvert/utils/tests/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def test_UnicodeStdStream():
unicode_std_stream().write(sample)

output = stdoutb.getvalue().decode('utf-8')
nt.assert_equal(output, sample)
assert output == sample
assert not stdout.closed
finally:
sys.stdout = orig_stdout
Expand All @@ -44,7 +44,7 @@ def test_UnicodeStdStream_nowrap():
orig_stdout = sys.stdout
sys.stdout = StringIO()
try:
nt.assert_is(unicode_std_stream(), sys.stdout)
assert unicode_std_stream() is sys.stdout
assert not sys.stdout.closed
finally:
sys.stdout = orig_stdout
4 changes: 1 addition & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,7 @@ def run(self):
]

extra_requirements = {
# FIXME: tests still require nose for some utility calls,
# but we are running with pytest
'test': ['pytest', 'pytest-cov', 'nose', 'ipykernel', 'jupyter_client>=4.2'],
'test': ['pytest', 'pytest-cov', 'ipykernel', 'jupyter_client>=4.2'],
'serve': ['tornado>=4.0'],
'execute': ['jupyter_client>=4.2'],
}
Expand Down

0 comments on commit 21bf6c4

Please sign in to comment.