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

Skip to content

Commit cf69193

Browse files
committed
reportdiff(): print a "plain diff" style diff.
XXX This should really be a unified diff, but I can't be bothered.
1 parent 0a07639 commit cf69193

1 file changed

Lines changed: 30 additions & 4 deletions

File tree

Lib/test/regrtest.py

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -351,10 +351,36 @@ def runtest(test, generate, verbose, quiet, testdir = None):
351351
def reportdiff(expected, output):
352352
print "*" * 70
353353
import difflib
354-
a = expected.splitlines(1)
355-
b = output.splitlines(1)
356-
diff = difflib.ndiff(a, b)
357-
print ''.join(diff),
354+
a = expected.splitlines()
355+
b = output.splitlines()
356+
sm = difflib.SequenceMatcher(a=a, b=b)
357+
tuples = sm.get_opcodes()
358+
def pair(x0, x1):
359+
x0 += 1
360+
if x0 >= x1:
361+
return str(x0)
362+
else:
363+
return "%d,%d" % (x0, x1)
364+
for op, a0, a1, b0, b1 in tuples:
365+
if op == 'equal':
366+
pass
367+
elif op == 'delete':
368+
print pair(a0, a1) + "d" + pair(b0, b1)
369+
for line in a[a0:a1]:
370+
print "<", line
371+
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
378+
elif op == 'insert':
379+
print str(a0) + "a" + pair(b0, b1)
380+
for line in b[b0:b1]:
381+
print ">", line
382+
else:
383+
print "get_opcodes() returned bad tuple?!?!", (op, a0, a1, b0, b1)
358384
print "*" * 70
359385

360386
def findtestdir():

0 commit comments

Comments
 (0)