~landscape/zope3/newer-from-ztk

« back to all changes in this revision

Viewing changes to src/zope/testing/testrunner/tests.py

  • Committer: Thomas Hervé
  • Date: 2009-09-21 16:46:07 UTC
  • Revision ID: thomas@canonical.com-20090921164607-sky3xhlt02ji80ka
Revert r8: regression with test failures

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
##############################################################################
2
 
#
3
 
# Copyright (c) 2004-2008 Zope Corporation and Contributors.
4
 
# All Rights Reserved.
5
 
#
6
 
# This software is subject to the provisions of the Zope Public License,
7
 
# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
8
 
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
9
 
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
10
 
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
11
 
# FOR A PARTICULAR PURPOSE.
12
 
#
13
 
##############################################################################
14
 
"""Test harness for the test runner itself.
15
 
 
16
 
$Id: __init__.py 86215 2008-05-03 14:08:12Z ctheune $
17
 
"""
18
 
 
19
 
import re
20
 
import gc
21
 
import os
22
 
import sys
23
 
import unittest
24
 
 
25
 
from zope.testing import doctest
26
 
from zope.testing import renormalizing
27
 
 
28
 
 
29
 
#separated checkers for the different platform,
30
 
#because it s...s to maintain just one
31
 
if sys.platform == 'win32':
32
 
    checker = renormalizing.RENormalizing([
33
 
        # 2.5 changed the way pdb reports exceptions
34
 
        (re.compile(r"<class 'exceptions.(\w+)Error'>:"),
35
 
                    r'exceptions.\1Error:'),
36
 
 
37
 
        #rewrite pdb prompt to ... the current location
38
 
        #windows, py2.4 pdb seems not to put the '>' on doctest locations
39
 
        #therefore we cut it here
40
 
        (re.compile('^> doctest[^\n]+->None$', re.M), '...->None'),
41
 
 
42
 
        #rewrite pdb prompt to ... the current location
43
 
        (re.compile('^> [^\n]+->None$', re.M), '> ...->None'),
44
 
 
45
 
        (re.compile(r"<module>"),(r'?')),
46
 
        (re.compile(r"<type 'exceptions.(\w+)Error'>:"),
47
 
                    r'exceptions.\1Error:'),
48
 
 
49
 
        (re.compile("'[A-Za-z]:\\\\"), "'"), # hopefully, we'll make Windows happy
50
 
                                             # replaces drives with nothing
51
 
 
52
 
        (re.compile(r'\\\\'), '/'), # more Windows happiness
53
 
                                    # double backslashes in coverage???
54
 
 
55
 
        (re.compile(r'\\'), '/'), # even more Windows happiness
56
 
                                  # replaces backslashes in paths
57
 
 
58
 
        #this is a magic to put linefeeds into the doctest
59
 
        (re.compile('##r##\n'), '\r'),
60
 
 
61
 
        (re.compile(r'\d+[.]\d\d\d seconds'), 'N.NNN seconds'),
62
 
        (re.compile(r'\d+[.]\d\d\d s'), 'N.NNN s'),
63
 
        (re.compile(r'\d+[.]\d\d\d{'), 'N.NNN{'),
64
 
        (re.compile('( |")[^\n]+testrunner-ex'), r'\1testrunner-ex'),
65
 
        (re.compile('( |")[^\n]+testrunner.py'), r'\1testrunner.py'),
66
 
        (re.compile(r'> [^\n]*(doc|unit)test[.]py\(\d+\)'),
67
 
                    r'\1test.py(NNN)'),
68
 
        (re.compile(r'[.]py\(\d+\)'), r'.py(NNN)'),
69
 
        (re.compile(r'[.]py:\d+'), r'.py:NNN'),
70
 
        (re.compile(r' line \d+,', re.IGNORECASE), r' Line NNN,'),
71
 
        (re.compile(r' line {([a-z]+)}\d+{', re.IGNORECASE), r' Line {\1}NNN{'),
72
 
 
73
 
        # omit traceback entries for unittest.py or doctest.py from
74
 
        # output:
75
 
        (re.compile(r'^ +File "[^\n]*(doc|unit)test.py", [^\n]+\n[^\n]+\n',
76
 
                    re.MULTILINE),
77
 
         r''),
78
 
        (re.compile(r'^{\w+} +File "{\w+}[^\n]*(doc|unit)test.py{\w+}", [^\n]+\n[^\n]+\n',
79
 
                    re.MULTILINE),
80
 
         r''),
81
 
        #(re.compile('^> [^\n]+->None$', re.M), '> ...->None'),
82
 
        (re.compile('import pdb; pdb'), 'Pdb()'), # Py 2.3
83
 
        ])
84
 
else:
85
 
    #*nix
86
 
    checker = renormalizing.RENormalizing([
87
 
        # 2.5 changed the way pdb reports exceptions
88
 
        (re.compile(r"<class 'exceptions.(\w+)Error'>:"),
89
 
                    r'exceptions.\1Error:'),
90
 
 
91
 
        #rewrite pdb prompt to ... the current location
92
 
        (re.compile('^> [^\n]+->None$', re.M), '> ...->None'),
93
 
 
94
 
        (re.compile(r"<module>"),(r'?')),
95
 
        (re.compile(r"<type 'exceptions.(\w+)Error'>:"),
96
 
                    r'exceptions.\1Error:'),
97
 
 
98
 
        #this is a magic to put linefeeds into the doctest
99
 
        #on win it takes one step, linux is crazy about the same...
100
 
        (re.compile('##r##'), r'\r'),
101
 
        (re.compile(r'\r'), '\\\\r\n'),
102
 
 
103
 
        (re.compile(r'\d+[.]\d\d\d seconds'), 'N.NNN seconds'),
104
 
        (re.compile(r'\d+[.]\d\d\d s'), 'N.NNN s'),
105
 
        (re.compile(r'\d+[.]\d\d\d{'), 'N.NNN{'),
106
 
        (re.compile('( |")[^\n]+testrunner-ex'), r'\1testrunner-ex'),
107
 
        (re.compile('( |")[^\n]+testrunner.py'), r'\1testrunner.py'),
108
 
        (re.compile(r'> [^\n]*(doc|unit)test[.]py\(\d+\)'),
109
 
                    r'\1test.py(NNN)'),
110
 
        (re.compile(r'[.]py\(\d+\)'), r'.py(NNN)'),
111
 
        (re.compile(r'[.]py:\d+'), r'.py:NNN'),
112
 
        (re.compile(r' line \d+,', re.IGNORECASE), r' Line NNN,'),
113
 
        (re.compile(r' line {([a-z]+)}\d+{', re.IGNORECASE), r' Line {\1}NNN{'),
114
 
 
115
 
        # omit traceback entries for unittest.py or doctest.py from
116
 
        # output:
117
 
        (re.compile(r'^ +File "[^\n]*(doc|unit)test.py", [^\n]+\n[^\n]+\n',
118
 
                    re.MULTILINE),
119
 
         r''),
120
 
        (re.compile(r'^{\w+} +File "{\w+}[^\n]*(doc|unit)test.py{\w+}", [^\n]+\n[^\n]+\n',
121
 
                    re.MULTILINE),
122
 
         r''),
123
 
        (re.compile('import pdb; pdb'), 'Pdb()'), # Py 2.3
124
 
        ])
125
 
 
126
 
def setUp(test):
127
 
    test.globs['saved-sys-info'] = (
128
 
        sys.path[:],
129
 
        sys.argv[:],
130
 
        sys.modules.copy(),
131
 
        gc.get_threshold(),
132
 
        )
133
 
    test.globs['this_directory'] = os.path.split(__file__)[0]
134
 
    test.globs['testrunner_script'] = sys.argv[0]
135
 
 
136
 
 
137
 
def tearDown(test):
138
 
    sys.path[:], sys.argv[:] = test.globs['saved-sys-info'][:2]
139
 
    gc.set_threshold(*test.globs['saved-sys-info'][3])
140
 
    sys.modules.clear()
141
 
    sys.modules.update(test.globs['saved-sys-info'][2])
142
 
 
143
 
 
144
 
def test_suite():
145
 
    suites = [
146
 
        doctest.DocFileSuite(
147
 
        'testrunner-arguments.txt',
148
 
        'testrunner-coverage.txt',
149
 
        'testrunner-debugging-layer-setup.test',
150
 
        'testrunner-debugging.txt',
151
 
        'testrunner-edge-cases.txt',
152
 
        'testrunner-errors.txt',
153
 
        'testrunner-layers-buff.txt',
154
 
        'testrunner-layers-ntd.txt',
155
 
        'testrunner-layers.txt',
156
 
        'testrunner-layers-api.txt',
157
 
        'testrunner-progress.txt',
158
 
        'testrunner-colors.txt',
159
 
        'testrunner-simple.txt',
160
 
        'testrunner-test-selection.txt',
161
 
        'testrunner-verbose.txt',
162
 
        'testrunner-wo-source.txt',
163
 
        'testrunner-repeat.txt',
164
 
        'testrunner-gc.txt',
165
 
        'testrunner-knit.txt',
166
 
        setUp=setUp, tearDown=tearDown,
167
 
        optionflags=doctest.ELLIPSIS+doctest.NORMALIZE_WHITESPACE,
168
 
        checker=checker),
169
 
        doctest.DocTestSuite('zope.testing.testrunner'),
170
 
        doctest.DocTestSuite('zope.testing.testrunner.coverage',
171
 
            optionflags=doctest.ELLIPSIS+doctest.NORMALIZE_WHITESPACE),
172
 
        doctest.DocTestSuite('zope.testing.testrunner.options'),
173
 
        doctest.DocTestSuite('zope.testing.testrunner.find'),
174
 
        ]
175
 
 
176
 
    if sys.platform == 'win32':
177
 
        suites.append(
178
 
            doctest.DocFileSuite(
179
 
            'testrunner-coverage-win32.txt',
180
 
            setUp=setUp, tearDown=tearDown,
181
 
            optionflags=doctest.ELLIPSIS+doctest.NORMALIZE_WHITESPACE,
182
 
            checker=checker))
183
 
 
184
 
    # Python <= 2.4.1 had a bug that prevented hotshot from running in
185
 
    # non-optimize mode
186
 
    if sys.version_info[:3] > (2,4,1) or not __debug__:
187
 
        # some Linux distributions don't include the profiling module (which
188
 
        # hotshot.stats depends on)
189
 
        try:
190
 
            import hotshot.stats
191
 
        except ImportError:
192
 
            pass
193
 
        else:
194
 
            suites.append(
195
 
                doctest.DocFileSuite(
196
 
                    'testrunner-profiling.txt',
197
 
                    setUp=setUp, tearDown=tearDown,
198
 
                    optionflags=doctest.ELLIPSIS+doctest.NORMALIZE_WHITESPACE,
199
 
                    checker = renormalizing.RENormalizing([
200
 
                        (re.compile(r'tests_profile[.]\S*[.]prof'),
201
 
                         'tests_profile.*.prof'),
202
 
                        ]),
203
 
                    )
204
 
                )
205
 
        try:
206
 
            import cProfile
207
 
            import pstats
208
 
        except ImportError:
209
 
            pass
210
 
        else:
211
 
            suites.append(
212
 
                doctest.DocFileSuite(
213
 
                    'testrunner-profiling-cprofiler.txt',
214
 
                    setUp=setUp, tearDown=tearDown,
215
 
                    optionflags=doctest.ELLIPSIS+doctest.NORMALIZE_WHITESPACE,
216
 
                    checker = renormalizing.RENormalizing([
217
 
                        (re.compile(r'tests_profile[.]\S*[.]prof'),
218
 
                         'tests_profile.*.prof'),
219
 
                        ]),
220
 
                    )
221
 
                )
222
 
 
223
 
 
224
 
    if hasattr(sys, 'gettotalrefcount'):
225
 
        suites.append(
226
 
            doctest.DocFileSuite(
227
 
            'testrunner-leaks.txt',
228
 
            setUp=setUp, tearDown=tearDown,
229
 
            optionflags=doctest.ELLIPSIS+doctest.NORMALIZE_WHITESPACE,
230
 
            checker = renormalizing.RENormalizing([
231
 
              (re.compile(r'\d+[.]\d\d\d seconds'), 'N.NNN seconds'),
232
 
              (re.compile(r'sys refcount=\d+ +change=\d+'),
233
 
               'sys refcount=NNNNNN change=NN'),
234
 
              (re.compile(r'sum detail refcount=\d+ +'),
235
 
               'sum detail refcount=NNNNNN '),
236
 
              (re.compile(r'total +\d+ +\d+'),
237
 
               'total               NNNN    NNNN'),
238
 
              (re.compile(r"^ +(int|type) +-?\d+ +-?\d+ *\n", re.M),
239
 
               ''),
240
 
              ]),
241
 
 
242
 
            )
243
 
        )
244
 
    else:
245
 
        suites.append(
246
 
            doctest.DocFileSuite(
247
 
            'testrunner-leaks-err.txt',
248
 
            setUp=setUp, tearDown=tearDown,
249
 
            optionflags=doctest.ELLIPSIS+doctest.NORMALIZE_WHITESPACE,
250
 
            checker=checker,
251
 
            )
252
 
        )
253
 
    return unittest.TestSuite(suites)