Source

sandbox/raymondh / test_diff / ctest.py

import itertools
import os
import pprint
import glob
import sys

verbose = False

def test(f1, f2, n):
    filt = " | egrep '^[*\-]+ .*[*\-]+$' > a.tmp"
    cmds = [
        "diff -C {n} {f1} {f2}" + filt,
        sys.executable + " ~/cpython/Tools/scripts/diff.py -l {n} -c {f1} {f2}" + filt,
    ]
    results = []
    for cmd in cmds:
        cmd = cmd.format(**locals())
        if verbose:
            print(cmd)
        os.system(cmd)
        with open('a.tmp') as f:
            result = f.read().replace('\n', '!').rstrip()
            results.append(result)
    print('{n}  {f1:14}  {f2:14}  {results!r}'.format(**locals()))
    assert results[0] == results[1]


filenames = glob.glob('*.txt')
for f1, f2 in itertools.product(filenames, repeat=2):
    for n in range(4):
        test(f1, f2, n)