Show More
@@ -465,23 +465,3 b" def help_all_output_test(subcommand=''):" | |||||
465 | nt.assert_in("Class parameters", out) |
|
465 | nt.assert_in("Class parameters", out) | |
466 | return out, err |
|
466 | return out, err | |
467 |
|
467 | |||
468 | def assert_big_text_equal(a, b, chunk_size=80): |
|
|||
469 | """assert that large strings are equal |
|
|||
470 |
|
||||
471 | Zooms in on first chunk that differs, |
|
|||
472 | to give better info than vanilla assertEqual for large text blobs. |
|
|||
473 | """ |
|
|||
474 | for i in range(0, len(a), chunk_size): |
|
|||
475 | chunk_a = a[i:i + chunk_size] |
|
|||
476 | chunk_b = b[i:i + chunk_size] |
|
|||
477 | nt.assert_equal(chunk_a, chunk_b, "[offset: %i]\n%r != \n%r" % ( |
|
|||
478 | i, chunk_a, chunk_b)) |
|
|||
479 |
|
||||
480 | if len(a) > len(b): |
|
|||
481 | nt.fail("Length doesn't match (%i > %i). Extra text:\n%r" % ( |
|
|||
482 | len(a), len(b), a[len(b):] |
|
|||
483 | )) |
|
|||
484 | elif len(a) < len(b): |
|
|||
485 | nt.fail("Length doesn't match (%i < %i). Extra text:\n%r" % ( |
|
|||
486 | len(a), len(b), b[len(a):] |
|
|||
487 | )) |
|
@@ -9,7 +9,7 b' from .base import ExportersTestsBase' | |||||
9 | from ..notebook import NotebookExporter |
|
9 | from ..notebook import NotebookExporter | |
10 |
|
10 | |||
11 | from IPython.nbformat import validate |
|
11 | from IPython.nbformat import validate | |
12 |
from |
|
12 | from jupyter_nbconvert.tests.base import assert_big_text_equal | |
13 |
|
13 | |||
14 | class TestNotebookExporter(ExportersTestsBase): |
|
14 | class TestNotebookExporter(ExportersTestsBase): | |
15 | """Contains test functions for notebook.py""" |
|
15 | """Contains test functions for notebook.py""" |
@@ -11,10 +11,12 b' import shutil' | |||||
11 | import sys |
|
11 | import sys | |
12 | import unittest |
|
12 | import unittest | |
13 |
|
13 | |||
|
14 | import nose.tools as nt | |||
|
15 | ||||
14 | from IPython.nbformat import v4, write |
|
16 | from IPython.nbformat import v4, write | |
15 | from IPython.utils.tempdir import TemporaryWorkingDirectory |
|
17 | from IPython.utils.tempdir import TemporaryWorkingDirectory | |
16 | from IPython.utils.process import get_output_error_code |
|
18 | from IPython.utils.process import get_output_error_code | |
17 |
|
19 | from IPython.utils.py3compat import string_types | ||
18 |
|
20 | |||
19 | class TestsBase(unittest.TestCase): |
|
21 | class TestsBase(unittest.TestCase): | |
20 | """Base tests class. Contains useful fuzzy comparison and nbconvert |
|
22 | """Base tests class. Contains useful fuzzy comparison and nbconvert | |
@@ -143,3 +145,24 b' class TestsBase(unittest.TestCase):' | |||||
143 | if not (retcode == 0 or ignore_return_code): |
|
145 | if not (retcode == 0 or ignore_return_code): | |
144 | raise OSError(stderr) |
|
146 | raise OSError(stderr) | |
145 | return stdout, stderr |
|
147 | return stdout, stderr | |
|
148 | ||||
|
149 | def assert_big_text_equal(a, b, chunk_size=80): | |||
|
150 | """assert that large strings are equal | |||
|
151 | ||||
|
152 | Zooms in on first chunk that differs, | |||
|
153 | to give better info than vanilla assertEqual for large text blobs. | |||
|
154 | """ | |||
|
155 | for i in range(0, len(a), chunk_size): | |||
|
156 | chunk_a = a[i:i + chunk_size] | |||
|
157 | chunk_b = b[i:i + chunk_size] | |||
|
158 | nt.assert_equal(chunk_a, chunk_b, "[offset: %i]\n%r != \n%r" % ( | |||
|
159 | i, chunk_a, chunk_b)) | |||
|
160 | ||||
|
161 | if len(a) > len(b): | |||
|
162 | nt.fail("Length doesn't match (%i > %i). Extra text:\n%r" % ( | |||
|
163 | len(a), len(b), a[len(b):] | |||
|
164 | )) | |||
|
165 | elif len(a) < len(b): | |||
|
166 | nt.fail("Length doesn't match (%i < %i). Extra text:\n%r" % ( | |||
|
167 | len(a), len(b), b[len(a):] | |||
|
168 | )) |
General Comments 0
You need to be logged in to leave comments.
Login now