diff --git a/tests/python/ipnbdoctest.py b/tests/python/ipnbdoctest.py index 5d7d00d10..cdf4a4407 100755 --- a/tests/python/ipnbdoctest.py +++ b/tests/python/ipnbdoctest.py @@ -180,21 +180,41 @@ def canonical_dict(dict, ignores): return dict +def keep_dict(dict): + # pandas imports Matplotlib, which can display a message about building the + # the font cache if it does not exist, and if doing so takes more than 5 + # seconds. Just ignore those. + if ('name' in dict and dict['name'] == 'stderr' and + type(dict['text']) is str and + dict['text'].startswith("Matplotlib is building the font cache")): + return False + return True + + def compare_outputs(ref, test, ignores=[]): '''Check that two lists of outputs are equivalent and report the result.''' + cref = [canonical_dict(d, ignores) for d in ref if keep_dict(d)] + ctest = [canonical_dict(d, ignores) for d in test if keep_dict(d)] + + ok = True + + if len(cref) != len(ctest): + print("output length mismatch (expected {}, got {})".format( + len(cref), len(ctest))) + ok = False # There can be several outputs. For instance wnen the cell both # prints a result (goes to "stdout") and displays an automaton # (goes to "data"). - exp = pprint.pformat([canonical_dict(d, ignores) for d in ref], width=132) - eff = pprint.pformat([canonical_dict(d, ignores) for d in test], width=132) + exp = pprint.pformat(cref, width=132) + eff = pprint.pformat(ctest, width=132) if exp[:-1] != '\n': exp += '\n' if eff[:-1] != '\n': eff += '\n' if exp == eff: - return True + return ok else: print(''.join(diff(exp.splitlines(1), eff.splitlines(1), fromfile='expected', tofile='effective'))) @@ -296,10 +316,6 @@ def test_notebook(ipynb): continue failed = False - if len(outs) != len(cell.outputs): - print("output length mismatch (expected {}, got {})".format( - len(cell.outputs), len(outs))) - failed = True if not compare_outputs(cell.outputs, outs): failed = True print("cell %d: " % i, end="")