##// END OF EJS Templates
add assert_big_text_equal...
MinRK -
Show More
@@ -8,6 +8,8 b' import json'
8 from .base import ExportersTestsBase
8 from .base import ExportersTestsBase
9 from ..notebook import NotebookExporter
9 from ..notebook import NotebookExporter
10
10
11 from IPython.testing.tools import assert_big_text_equal
12
11 class TestNotebookExporter(ExportersTestsBase):
13 class TestNotebookExporter(ExportersTestsBase):
12 """Contains test functions for notebook.py"""
14 """Contains test functions for notebook.py"""
13
15
@@ -21,7 +23,7 b' class TestNotebookExporter(ExportersTestsBase):'
21 file_contents = f.read()
23 file_contents = f.read()
22 (output, resources) = self.exporter_class().from_filename(self._get_notebook())
24 (output, resources) = self.exporter_class().from_filename(self._get_notebook())
23 assert len(output) > 0
25 assert len(output) > 0
24 self.assertEqual(output, file_contents)
26 assert_big_text_equal(output, file_contents)
25
27
26 def test_downgrade_3(self):
28 def test_downgrade_3(self):
27 exporter = self.exporter_class(nbformat_version=3)
29 exporter = self.exporter_class(nbformat_version=3)
@@ -465,3 +465,23 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 ))
General Comments 0
You need to be logged in to leave comments. Login now