1
##############################################################################
3
# Copyright (c) 2004-2008 Zope Corporation and Contributors.
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.
13
##############################################################################
14
"""Test harness for the test runner itself.
16
$Id: __init__.py 86215 2008-05-03 14:08:12Z ctheune $
25
from zope.testing import doctest
26
from zope.testing import renormalizing
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:'),
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'),
42
#rewrite pdb prompt to ... the current location
43
(re.compile('^> [^\n]+->None$', re.M), '> ...->None'),
45
(re.compile(r"<module>"),(r'?')),
46
(re.compile(r"<type 'exceptions.(\w+)Error'>:"),
47
r'exceptions.\1Error:'),
49
(re.compile("'[A-Za-z]:\\\\"), "'"), # hopefully, we'll make Windows happy
50
# replaces drives with nothing
52
(re.compile(r'\\\\'), '/'), # more Windows happiness
53
# double backslashes in coverage???
55
(re.compile(r'\\'), '/'), # even more Windows happiness
56
# replaces backslashes in paths
58
#this is a magic to put linefeeds into the doctest
59
(re.compile('##r##\n'), '\r'),
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+\)'),
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{'),
73
# omit traceback entries for unittest.py or doctest.py from
75
(re.compile(r'^ +File "[^\n]*(doc|unit)test.py", [^\n]+\n[^\n]+\n',
78
(re.compile(r'^{\w+} +File "{\w+}[^\n]*(doc|unit)test.py{\w+}", [^\n]+\n[^\n]+\n',
81
#(re.compile('^> [^\n]+->None$', re.M), '> ...->None'),
82
(re.compile('import pdb; pdb'), 'Pdb()'), # Py 2.3
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:'),
91
#rewrite pdb prompt to ... the current location
92
(re.compile('^> [^\n]+->None$', re.M), '> ...->None'),
94
(re.compile(r"<module>"),(r'?')),
95
(re.compile(r"<type 'exceptions.(\w+)Error'>:"),
96
r'exceptions.\1Error:'),
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'),
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+\)'),
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{'),
115
# omit traceback entries for unittest.py or doctest.py from
117
(re.compile(r'^ +File "[^\n]*(doc|unit)test.py", [^\n]+\n[^\n]+\n',
120
(re.compile(r'^{\w+} +File "{\w+}[^\n]*(doc|unit)test.py{\w+}", [^\n]+\n[^\n]+\n',
123
(re.compile('import pdb; pdb'), 'Pdb()'), # Py 2.3
127
test.globs['saved-sys-info'] = (
133
test.globs['this_directory'] = os.path.split(__file__)[0]
134
test.globs['testrunner_script'] = sys.argv[0]
138
sys.path[:], sys.argv[:] = test.globs['saved-sys-info'][:2]
139
gc.set_threshold(*test.globs['saved-sys-info'][3])
141
sys.modules.update(test.globs['saved-sys-info'][2])
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',
165
'testrunner-knit.txt',
166
setUp=setUp, tearDown=tearDown,
167
optionflags=doctest.ELLIPSIS+doctest.NORMALIZE_WHITESPACE,
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'),
176
if sys.platform == 'win32':
178
doctest.DocFileSuite(
179
'testrunner-coverage-win32.txt',
180
setUp=setUp, tearDown=tearDown,
181
optionflags=doctest.ELLIPSIS+doctest.NORMALIZE_WHITESPACE,
184
# Python <= 2.4.1 had a bug that prevented hotshot from running in
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)
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'),
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'),
224
if hasattr(sys, 'gettotalrefcount'):
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+'),
238
(re.compile(r"^ +(int|type) +-?\d+ +-?\d+ *\n", re.M),
246
doctest.DocFileSuite(
247
'testrunner-leaks-err.txt',
248
setUp=setUp, tearDown=tearDown,
249
optionflags=doctest.ELLIPSIS+doctest.NORMALIZE_WHITESPACE,
253
return unittest.TestSuite(suites)