[Python-checkins] CVS: python/dist/src/Lib/test regrtest.py,1.54,1.55

Tim Peters tim_one@users.sourceforge.net
Fri, 21 Sep 2001 22:31:05 -0700


Update of /cvsroot/python/python/dist/src/Lib/test
In directory usw-pr-cvs1:/tmp/cvs-serv2728/python/Lib/test

Modified Files:
	regrtest.py 
Log Message:
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.


Index: regrtest.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/regrtest.py,v
retrieving revision 1.54
retrieving revision 1.55
diff -C2 -d -r1.54 -r1.55
*** regrtest.py	2001/09/21 21:06:22	1.54
--- regrtest.py	2001/09/22 05:31:03	1.55
***************
*** 350,385 ****
  
  def reportdiff(expected, output):
-     print "*" * 70
      import difflib
!     a = expected.splitlines()
!     b = output.splitlines()
      sm = difflib.SequenceMatcher(a=a, b=b)
      tuples = sm.get_opcodes()
      def pair(x0, x1):
          x0 += 1
          if x0 >= x1:
!             return str(x0)
          else:
!             return "%d,%d" % (x0, x1)
      for op, a0, a1, b0, b1 in tuples:
          if op == 'equal':
              pass
          elif op == 'delete':
!             print pair(a0, a1) + "d" + pair(b0, b1)
              for line in a[a0:a1]:
!                 print "<", line
          elif op == 'replace':
!             print pair(a0, a1) + "c" + pair(b0, b1)
!             for line in a[a0:a1]:
!                 print "<", line
!             print "---"
!             for line in b[b0:b1]:
!                 print ">", line
          elif op == 'insert':
!             print str(a0) + "a" + pair(b0, b1)
              for line in b[b0:b1]:
!                 print ">", line
          else:
              print "get_opcodes() returned bad tuple?!?!", (op, a0, a1, b0, b1)
      print "*" * 70
  
--- 350,392 ----
  
  def reportdiff(expected, output):
      import difflib
!     print "*" * 70
!     a = expected.splitlines(1)
!     b = output.splitlines(1)
      sm = difflib.SequenceMatcher(a=a, b=b)
      tuples = sm.get_opcodes()
+ 
      def pair(x0, x1):
+         # x0:x1 are 0-based slice indices; convert to 1-based line indices.
          x0 += 1
          if x0 >= x1:
!             return "line " + str(x0)
          else:
!             return "lines %d-%d" % (x0, x1)
! 
      for op, a0, a1, b0, b1 in tuples:
          if op == 'equal':
              pass
+ 
          elif op == 'delete':
!             print "***", pair(a0, a1), "of expected output missing:"
              for line in a[a0:a1]:
!                 print "-", line,
! 
          elif op == 'replace':
!             print "*** mismatch between", pair(a0, a1), "of expected", \
!                   "output and", pair(b0, b1), "of actual output:"
!             for line in difflib.ndiff(a[a0:a1], b[b0:b1]):
!                 print line,
! 
          elif op == 'insert':
!             print "***", pair(b0, b1), "of actual output doesn't appear", \
!                   "in expected output after line", str(a1)+":"
              for line in b[b0:b1]:
!                 print "+", line,
! 
          else:
              print "get_opcodes() returned bad tuple?!?!", (op, a0, a1, b0, b1)
+ 
      print "*" * 70