Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c377b16

Browse files
committed
Since the most likely failure mode for an expected-output test is a change
somewhere inside a line, use ndiff so that intraline difference marking can point out what changed within a line. I don't remember diff-style abbreviations either (haven't used it since '94, except to produce patches), so say the rest in English too.
1 parent 58b072d commit c377b16

1 file changed

Lines changed: 22 additions & 15 deletions

File tree

Lib/test/regrtest.py

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -349,38 +349,45 @@ def runtest(test, generate, verbose, quiet, testdir = None):
349349
return 0
350350

351351
def reportdiff(expected, output):
352-
print "*" * 70
353352
import difflib
354-
a = expected.splitlines()
355-
b = output.splitlines()
353+
print "*" * 70
354+
a = expected.splitlines(1)
355+
b = output.splitlines(1)
356356
sm = difflib.SequenceMatcher(a=a, b=b)
357357
tuples = sm.get_opcodes()
358+
358359
def pair(x0, x1):
360+
# x0:x1 are 0-based slice indices; convert to 1-based line indices.
359361
x0 += 1
360362
if x0 >= x1:
361-
return str(x0)
363+
return "line " + str(x0)
362364
else:
363-
return "%d,%d" % (x0, x1)
365+
return "lines %d-%d" % (x0, x1)
366+
364367
for op, a0, a1, b0, b1 in tuples:
365368
if op == 'equal':
366369
pass
370+
367371
elif op == 'delete':
368-
print pair(a0, a1) + "d" + pair(b0, b1)
372+
print "***", pair(a0, a1), "of expected output missing:"
369373
for line in a[a0:a1]:
370-
print "<", line
374+
print "-", line,
375+
371376
elif op == 'replace':
372-
print pair(a0, a1) + "c" + pair(b0, b1)
373-
for line in a[a0:a1]:
374-
print "<", line
375-
print "---"
376-
for line in b[b0:b1]:
377-
print ">", line
377+
print "*** mismatch between", pair(a0, a1), "of expected", \
378+
"output and", pair(b0, b1), "of actual output:"
379+
for line in difflib.ndiff(a[a0:a1], b[b0:b1]):
380+
print line,
381+
378382
elif op == 'insert':
379-
print str(a0) + "a" + pair(b0, b1)
383+
print "***", pair(b0, b1), "of actual output doesn't appear", \
384+
"in expected output after line", str(a1)+":"
380385
for line in b[b0:b1]:
381-
print ">", line
386+
print "+", line,
387+
382388
else:
383389
print "get_opcodes() returned bad tuple?!?!", (op, a0, a1, b0, b1)
390+
384391
print "*" * 70
385392

386393
def findtestdir():

0 commit comments

Comments
 (0)