* tests/python/ipnbdoctest.py: Ignore matplotlib font cache messages.

This commit is contained in:
Alexandre Duret-Lutz 2020-07-27 10:26:17 +02:00
parent 5ec9d55fea
commit ff3a3f8144

View file

@ -180,21 +180,41 @@ def canonical_dict(dict, ignores):
return dict 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=[]): def compare_outputs(ref, test, ignores=[]):
'''Check that two lists of outputs are equivalent and report the '''Check that two lists of outputs are equivalent and report the
result.''' 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 # There can be several outputs. For instance wnen the cell both
# prints a result (goes to "stdout") and displays an automaton # prints a result (goes to "stdout") and displays an automaton
# (goes to "data"). # (goes to "data").
exp = pprint.pformat([canonical_dict(d, ignores) for d in ref], width=132) exp = pprint.pformat(cref, width=132)
eff = pprint.pformat([canonical_dict(d, ignores) for d in test], width=132) eff = pprint.pformat(ctest, width=132)
if exp[:-1] != '\n': if exp[:-1] != '\n':
exp += '\n' exp += '\n'
if eff[:-1] != '\n': if eff[:-1] != '\n':
eff += '\n' eff += '\n'
if exp == eff: if exp == eff:
return True return ok
else: else:
print(''.join(diff(exp.splitlines(1), eff.splitlines(1), print(''.join(diff(exp.splitlines(1), eff.splitlines(1),
fromfile='expected', tofile='effective'))) fromfile='expected', tofile='effective')))
@ -296,10 +316,6 @@ def test_notebook(ipynb):
continue continue
failed = False 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): if not compare_outputs(cell.outputs, outs):
failed = True failed = True
print("cell %d: " % i, end="") print("cell %d: " % i, end="")