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

Tim Peters python-dev@python.org
Sat, 30 Dec 2000 14:21:25 -0800


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

Modified Files:
	regrtest.py 
Log Message:
Christmas present to myself:  changed regrtest in two ways:
1. When running in verbose mode, if any test happens to pass, print
   a warning that the apparent success may be bogus (stdout isn't
   compared in verbose mode).  Been fooled by that too often.
2. When a test fails because the expected stdout doesn't match the
   actual stdout, print as much of stdout as did match before the
   first failing write.  Else we get failures of the form "expected
   'a', got 'b'" and a glance at the expected output file shows
   500 instances of 'a' -- no idea where it failed, and, as in #1,
   trying to run in verbose mode instead doesn't help because
   stdout isn't compared then.


Index: regrtest.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/regrtest.py,v
retrieving revision 1.28
retrieving revision 1.29
diff -C2 -r1.28 -r1.29
*** regrtest.py	2000/12/12 23:11:42	1.28
--- regrtest.py	2000/12/30 22:21:22	1.29
***************
*** 159,162 ****
--- 159,165 ----
              print "All",
          print count(len(good), "test"), "OK."
+         if verbose:
+             print "CAUTION:  stdout isn't compared in verbose mode:  a test"
+             print "that passes in verbose mode may fail without it."
      if bad:
          print count(len(bad), "test"), "failed:",
***************
*** 281,290 ****
      def __init__(self, filename):
          self.fp = open(filename, 'r')
  
      def write(self, data):
          expected = self.fp.read(len(data))
!         if data != expected:
!             raise test_support.TestFailed, \
!                     'Writing: '+`data`+', expected: '+`expected`
  
      def writelines(self, listoflines):
--- 284,315 ----
      def __init__(self, filename):
          self.fp = open(filename, 'r')
+         self.stuffthatmatched = []
  
      def write(self, data):
          expected = self.fp.read(len(data))
!         if data == expected:
!             self.stuffthatmatched.append(expected)
!         else:
!             # This Compare instance is spoofing stdout, so we need to write
!             # to stderr instead.
!             from sys import stderr as e
!             print >> e, "The actual stdout doesn't match the expected stdout."
!             if self.stuffthatmatched:
!                 print >> e, "This much did match (between asterisk lines):"
!                 print >> e, "*" * 70
!                 good = "".join(self.stuffthatmatched)
!                 e.write(good)
!                 if not good.endswith("\n"):
!                     e.write("\n")
!                 print >> e, "*" * 70
!                 print >> e, "Then ..."
!             else:
!                 print >> e, "The first write to stdout clashed:"
!             # Note that the prompts are the same length in next two lines.
!             # This is so what we expected and what we got line up.
!             print >> e, "We expected (repr):", `expected`
!             print >> e, "But instead we got:", `data`
!             raise test_support.TestFailed('Writing: ' + `data`+
!                                           ', expected: ' + `expected`)
  
      def writelines(self, listoflines):
***************
*** 297,301 ****
          leftover = self.fp.read()
          if leftover:
!             raise test_support.TestFailed, 'Unread: '+`leftover`
          self.fp.close()
  
--- 322,327 ----
          leftover = self.fp.read()
          if leftover:
!             raise test_support.TestFailed('Tail of expected stdout unseen: ' +
!                                           `leftover`)
          self.fp.close()