diff --git a/IPython/nbconvert/exporters/tests/test_notebook.py b/IPython/nbconvert/exporters/tests/test_notebook.py index ac51218..65e98e4 100644 --- a/IPython/nbconvert/exporters/tests/test_notebook.py +++ b/IPython/nbconvert/exporters/tests/test_notebook.py @@ -8,6 +8,8 @@ import json from .base import ExportersTestsBase from ..notebook import NotebookExporter +from IPython.testing.tools import assert_big_text_equal + class TestNotebookExporter(ExportersTestsBase): """Contains test functions for notebook.py""" @@ -21,7 +23,7 @@ class TestNotebookExporter(ExportersTestsBase): file_contents = f.read() (output, resources) = self.exporter_class().from_filename(self._get_notebook()) assert len(output) > 0 - self.assertEqual(output, file_contents) + assert_big_text_equal(output, file_contents) def test_downgrade_3(self): exporter = self.exporter_class(nbformat_version=3) diff --git a/IPython/testing/tools.py b/IPython/testing/tools.py index 5970775..03537a3 100644 --- a/IPython/testing/tools.py +++ b/IPython/testing/tools.py @@ -465,3 +465,23 @@ def help_all_output_test(subcommand=''): nt.assert_in("Class parameters", out) return out, err +def assert_big_text_equal(a, b, chunk_size=80): + """assert that large strings are equal + + Zooms in on first chunk that differs, + to give better info than vanilla assertEqual for large text blobs. + """ + 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)) + + if len(a) > len(b): + nt.fail("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):] + ))