Source

CherryPy / cherrypy / test / logtest.py

Diff from to

cherrypy/test/logtest.py

 
 class LogCase(object):
     """unittest.TestCase mixin for testing log messages.
-    
+
     logfile: a filename for the desired log. Yes, I know modes are evil,
         but it makes the test functions so much cleaner to set this once.
-    
+
     lastmarker: the last marker in the log. This can be used to search for
         messages since the last marker.
-    
+
     markerPrefix: a string with which to prefix log markers. This should be
         unique enough from normal log output to use for marker identification.
     """
-    
+
     logfile = None
     lastmarker = None
     markerPrefix = ntob("test suite marker: ")
-    
+
     def _handleLogError(self, msg, data, marker, pattern):
         print("")
         print("    ERROR: %s" % msg)
-        
+
         if not self.interactive:
             raise self.failureException(msg)
-        
+
         p = "    Show: [L]og [M]arker [P]attern; [I]gnore, [R]aise, or sys.e[X]it >> "
         sys.stdout.write(p + ' ')
         # ARGH
             elif i == "X":
                 self.exit()
             sys.stdout.write(p + ' ')
-    
+
     def exit(self):
         sys.exit()
-    
+
     def emptyLog(self):
         """Overwrite self.logfile with 0 bytes."""
         open(self.logfile, 'wb').write("")
-    
+
     def markLog(self, key=None):
         """Insert a marker line into the log and set self.lastmarker."""
         if key is None:
             key = str(time.time())
         self.lastmarker = key
-        
+
         open(self.logfile, 'ab+').write(ntob("%s%s\n" % (self.markerPrefix, key),"utf-8"))
-    
+
     def _read_marked_region(self, marker=None):
         """Return lines from self.logfile in the marked region.
-        
+
         If marker is None, self.lastmarker is used. If the log hasn't
         been marked (using self.markLog), the entire log will be returned.
         """
 ##        # Give the logger time to finish writing?
 ##        time.sleep(0.5)
-        
+
         logfile = self.logfile
         marker = marker or self.lastmarker
         if marker is None:
             return open(logfile, 'rb').readlines()
-        
+
         if isinstance(marker, unicodestr):
             marker = marker.encode('utf-8')
         data = []
             elif marker in line:
                 in_region = True
         return data
-    
+
     def assertInLog(self, line, marker=None):
         """Fail if the given (partial) line is not in the log.
-        
+
         The log will be searched from the given marker to the next marker.
         If marker is None, self.lastmarker is used. If the log hasn't
         been marked (using self.markLog), the entire log will be searched.
                 return
         msg = "%r not found in log" % line
         self._handleLogError(msg, data, marker, line)
-    
+
     def assertNotInLog(self, line, marker=None):
         """Fail if the given (partial) line is in the log.
-        
+
         The log will be searched from the given marker to the next marker.
         If marker is None, self.lastmarker is used. If the log hasn't
         been marked (using self.markLog), the entire log will be searched.
             if line in logline:
                 msg = "%r found in log" % line
                 self._handleLogError(msg, data, marker, line)
-    
+
     def assertLog(self, sliceargs, lines, marker=None):
         """Fail if log.readlines()[sliceargs] is not contained in 'lines'.
-        
+
         The log will be searched from the given marker to the next marker.
         If marker is None, self.lastmarker is used. If the log hasn't
         been marked (using self.markLog), the entire log will be searched.
             elif isinstance(lines, basestring):
                 raise TypeError("The 'lines' arg must be a list when "
                                 "'sliceargs' is a tuple.")
-            
+
             start, stop = sliceargs
             for line, logline in zip(lines, data[start:stop]):
                 if isinstance(line, unicodestr):