Commit c376ad2c authored by Akim Demaille's avatar Akim Demaille
Browse files

tests: change object pretty-printer

* tests/bin/ Let's try to look like the actual output
from IPython.  It's output is pretty-printed, but it does not look
like what I get using pprint.  They seem use the json module.

* tests/bin/update-test: Enable patches based on diffs.
parent 491c1944
#! /usr/bin/env python
import argparse
import json
import os
import pprint
import re
import subprocess
import sys
......@@ -203,7 +203,7 @@ def canonical_dict(dict, ignores):
if 'data' in dict:
for k in dict['data']:
dict['data'][k] = canonicalize(dict['data'][k], k, ignores)
dict['data'][k] = canonicalize(dict['data'][k], k, ignores).splitlines(True)
# FIXME: Probably not the best way to deal with this, but right know
# I want the test skip to be green again
if 'text/plain' in dict['data']:
......@@ -235,11 +235,24 @@ def check_outputs(ref, test, ignores):
SKIP('widgets are used')
# There can be several outputs. For instance wnen the cell both
# There can be several outputs. For instance when 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)
# Also IPython saves the actual outputs not a strings, but as
# arrays of strings that represent the lines. That makes it much
# more readable.
# Finally, put all this into a {'cells':[ {'outputs': [LINES]} ] },
# to imitate the format used by Jupyter: this will enable that we
# use update-test to upgrade notebooks after the test suite ran.
def pretty(ds):
return json.dumps({'cells':[{'outputs':[canonical_dict(d, ignores) for d in ds]}]},
exp = pretty(ref)
eff = pretty(test)
if exp == eff:
log('check_outputs', 'pass', level=2)
......@@ -8,6 +8,7 @@
# update-test --builddir=_build tests/python/*.py tests/python/determinize.dir/*
import argparse
import os
import re
......@@ -15,10 +16,17 @@ def getargs():
p = argparse.ArgumentParser(description='Update test cases.')
opt = p.add_argument
opt('tests', metavar='test', nargs='+', type=str, default=None,
help='a test file to update')
help='test files to update')
opt('--builddir', metavar='DIR', type=str, default='.',
help='look for the logs in DIR')
opt('--log', metavar='FILE', nargs="+", type=str, default=[],
opt('-d', '--diffs', action='store_true',
help='''also parse the diffs. By default diffs are not
read, only the "Expected" and "Effective" sections of the log
files are parsed, because often the context of the diffs are
too coarse, and the subsitution is too eager. But on occasions,
for instance to process notebooks, diffs are better suited.
opt('-l', '--log', metavar='FILE', nargs="+", type=str, default=[],
help='consider DIR/FILE')
opt('-v', '--verbose', action='store_true',
help='Be verbose')
......@@ -35,6 +43,7 @@ def log(*args_):
def contents(file):
'''The contents of a file.'''
f = open(file)
......@@ -65,9 +74,6 @@ def diff_to_re(match):
def exp_eff_to_re(match):
fr = ''
to = ''
# For some reason, with python-2.7 on OS X, I raise an
# exception.TypeError when I use (keepends = True) instead of
# (True)!!!
for l in
fr += l[1:]
# Drop the final \n.
......@@ -80,27 +86,26 @@ def exp_eff_to_re(match):
def update(test, logfile):
logfile = args.builddir + '/' + logfile
l = contents(logfile)
logfile = os.path.join(args.builddir, logfile)
if os.path.isfile(logfile):
log("LOG: ", logfile)
l = contents(logfile)
global subst # pylint: disable=global-statement
subst = dict()
re.sub(r'Expected (?:out.*?|error)::\n\n((?:^\t.*\n)+)\n'
+ 'Effective (?:out.*?|error)::\n\n((?:^\t.*\n)+)\n',
exp_eff_to_re, l, flags=re.MULTILINE)
# re.sub(r'((?:^\t[-+ ].*\n)+)',
# diff_to_re, l, flags = re.MULTILINE)
if subst != dict():
if args.diffs:
re.sub(r'((?:^\t[-+ ].*\n)+)',
diff_to_re, l, flags = re.MULTILINE)
if subst:
# Turn "subst{frm} -> to" into a large RE.
frm = '|'.join([re.escape(x) for x in subst])
log("FROM:", frm)
test = re.sub("(" + frm + ")",
lambda m: subst[],
test, flags=re.MULTILINE)
return test
except IOError:
return test
return test
for t in args.tests:
log("FILE:", t)
# Check thabt we detect incorrect outputs.
abb => ab
# Check that we detect incorrect outputs. -*- shell-script -*-
# Use some patterns that is unlikely to be found in other tests, so
# that we can use update-test easily.
abbbbbbbbbbbbbbbbbbbbbb => ab
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment