~ubuntu-branches/debian/jessie/cherrypy3/jessie

« back to all changes in this revision

Viewing changes to cherrypy/test/logtest.py

  • Committer: Package Import Robot
  • Author(s): Gustavo Noronha Silva, JCF Ploemen, Stéphane Graber, Gustavo Noronha
  • Date: 2012-01-06 10:13:27 UTC
  • mfrom: (1.1.4) (7.1.2 sid)
  • Revision ID: package-import@ubuntu.com-20120106101327-smxnhguqs14ubl7e
Tags: 3.2.2-1
[ JCF Ploemen ]
* New upstream release (Closes: #571196).
* Bumped Standards-Version to 3.8.4 (no changes needed).
* Removing patch 02: no longer needed, incorporated upstream.
* Updating patch 00 to match release.
* Install cherryd man page via debian/manpages.
* debian/copyright:
  + Added notice for cherrypy/lib/httpauth.py.
  + Fixed years.
* debian/watch:
  + Don't hit on the -py3 release by blocking '-' from the version.
  + Mangle upstream version, inserting a tilde for beta/rc.

[ Stéphane Graber <stgraber@ubuntu.com> ]
 * Convert from python-support to dh_python2 (#654375)
  - debian/pyversions: Removed (no longer needed)
  - debian/rules
   + Replace call to dh_pysupport by dh_python2
   + Add --with=python2 to all dh calls
  - debian/control
   + Drop build-depends on python-support
   + Bump build-depends on python-all to >= 2.6.6-3~
   + Replace XS-Python-Version by X-Python-Version
   + Remove XB-Python-Version from binary package

[ Gustavo Noronha ]
* debian/control, debian/rules, debian/manpages:
 - use help2man to generate a manpage for cherryd at build time, since
  one is no longer shipped along with the source code
* debian/control:
- add python-nose to Build-Depends, since it's used during the
  documentation build for cross-reference generation

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
import sys
4
4
import time
5
5
 
 
6
import cherrypy
 
7
from cherrypy._cpcompat import basestring, ntob, unicodestr
 
8
 
6
9
 
7
10
try:
8
11
    # On Windows, msvcrt.getch reads a single char without output.
38
41
    
39
42
    logfile = None
40
43
    lastmarker = None
41
 
    markerPrefix = "test suite marker: "
 
44
    markerPrefix = ntob("test suite marker: ")
42
45
    
43
46
    def _handleLogError(self, msg, data, marker, pattern):
44
 
        print
45
 
        print "    ERROR:", msg
 
47
        print("")
 
48
        print("    ERROR: %s" % msg)
46
49
        
47
50
        if not self.interactive:
48
51
            raise self.failureException(msg)
49
52
        
50
53
        p = "    Show: [L]og [M]arker [P]attern; [I]gnore, [R]aise, or sys.e[X]it >> "
51
 
        print p,
 
54
        sys.stdout.write(p + ' ')
 
55
        # ARGH
 
56
        sys.stdout.flush()
52
57
        while True:
53
58
            i = getchar().upper()
54
59
            if i not in "MPLIRX":
55
60
                continue
56
 
            print i.upper()  # Also prints new line
 
61
            print(i.upper())  # Also prints new line
57
62
            if i == "L":
58
63
                for x, line in enumerate(data):
59
64
                    if (x + 1) % self.console_height == 0:
60
65
                        # The \r and comma should make the next line overwrite
61
 
                        print "<-- More -->\r",
 
66
                        sys.stdout.write("<-- More -->\r ")
62
67
                        m = getchar().lower()
63
68
                        # Erase our "More" prompt
64
 
                        print "            \r",
 
69
                        sys.stdout.write("            \r ")
65
70
                        if m == "q":
66
71
                            break
67
 
                    print line.rstrip()
 
72
                    print(line.rstrip())
68
73
            elif i == "M":
69
 
                print repr(marker or self.lastmarker)
 
74
                print(repr(marker or self.lastmarker))
70
75
            elif i == "P":
71
 
                print repr(pattern)
 
76
                print(repr(pattern))
72
77
            elif i == "I":
73
78
                # return without raising the normal exception
74
79
                return
76
81
                raise self.failureException(msg)
77
82
            elif i == "X":
78
83
                self.exit()
79
 
            print p,
 
84
            sys.stdout.write(p + ' ')
80
85
    
81
86
    def exit(self):
82
87
        sys.exit()
91
96
            key = str(time.time())
92
97
        self.lastmarker = key
93
98
        
94
 
        open(self.logfile, 'ab+').write("%s%s\n" % (self.markerPrefix, key))
 
99
        open(self.logfile, 'ab+').write(ntob("%s%s\n" % (self.markerPrefix, key),"utf-8"))
95
100
    
96
101
    def _read_marked_region(self, marker=None):
97
102
        """Return lines from self.logfile in the marked region.
107
112
        if marker is None:
108
113
            return open(logfile, 'rb').readlines()
109
114
        
 
115
        if isinstance(marker, unicodestr):
 
116
            marker = marker.encode('utf-8')
110
117
        data = []
111
118
        in_region = False
112
119
        for line in open(logfile, 'rb'):
158
165
            # Single arg. Use __getitem__ and allow lines to be str or list.
159
166
            if isinstance(lines, (tuple, list)):
160
167
                lines = lines[0]
 
168
            if isinstance(lines, unicodestr):
 
169
                lines = lines.encode('utf-8')
161
170
            if lines not in data[sliceargs]:
162
171
                msg = "%r not found on log line %r" % (lines, sliceargs)
163
 
                self._handleLogError(msg, [data[sliceargs]], marker, lines)
 
172
                self._handleLogError(msg, [data[sliceargs],"--EXTRA CONTEXT--"] + data[sliceargs+1:sliceargs+6], marker, lines)
164
173
        else:
165
174
            # Multiple args. Use __getslice__ and require lines to be list.
166
175
            if isinstance(lines, tuple):
171
180
            
172
181
            start, stop = sliceargs
173
182
            for line, logline in zip(lines, data[start:stop]):
 
183
                if isinstance(line, unicodestr):
 
184
                    line = line.encode('utf-8')
174
185
                if line not in logline:
175
186
                    msg = "%r not found in log" % line
176
187
                    self._handleLogError(msg, data[start:stop], marker, line)