41
41
from unittest import TestResult, TestCase
43
# XXX: Don't need this anymore now we depend on python2.4
44
43
def _need_subprocess():
45
44
sys.stderr.write("sorry, this test suite requires the subprocess module\n"
46
45
"this is shipped with python2.4 and available separately for 2.3\n")
171
170
def log(self, msg):
172
171
"""Log a message to a progress file"""
173
# XXX: The problem with this is that code that writes straight
174
# to the log file won't be shown when we display the log
175
# buffer; would be better to not have the in-memory buffer and
176
# instead just a log file per test, which is read in and
177
# displayed if the test fails. That seems to imply one log
178
# per test case, not globally. OK?
179
172
self._log_buf = self._log_buf + str(msg) + '\n'
180
173
print >>self.TEST_LOG, msg
206
199
self.log("check contents of file %s" % filename)
207
200
contents = file(filename, 'r').read()
208
201
if contents != expect:
209
self.log("expected: %r" % expect)
202
self.log("expected: %r" % expected)
210
203
self.log("actually: %r" % contents)
211
204
self.fail("contents of %s not as expected")
235
228
No special behaviour for now.
237
def __init__(self, out, style):
230
def __init__(self, out):
239
232
TestResult.__init__(self)
240
assert style in ('none', 'progress', 'verbose')
244
234
def startTest(self, test):
245
235
# TODO: Maybe show test.shortDescription somewhere?
248
238
if what == 'runit':
249
239
what = test.shortDescription()
251
if self.style == 'verbose':
252
print >>self.out, '%-60.60s' % what,
254
elif self.style == 'progress':
241
print >>self.out, '%-60.60s' % what,
257
243
TestResult.startTest(self, test)
260
245
def stopTest(self, test):
262
247
TestResult.stopTest(self, test)
265
250
def addError(self, test, err):
266
if self.style == 'verbose':
267
print >>self.out, 'ERROR'
251
print >>self.out, 'ERROR'
268
252
TestResult.addError(self, test, err)
269
253
_show_test_failure('error', test, err, self.out)
271
255
def addFailure(self, test, err):
272
if self.style == 'verbose':
273
print >>self.out, 'FAILURE'
256
print >>self.out, 'FAILURE'
274
257
TestResult.addFailure(self, test, err)
275
258
_show_test_failure('failure', test, err, self.out)
277
260
def addSuccess(self, test):
278
if self.style == 'verbose':
279
print >>self.out, 'OK'
261
print >>self.out, 'OK'
280
262
TestResult.addSuccess(self, test)
284
def run_suite(suite, name='test', verbose=False):
266
def run_suite(suite, name="test"):