~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to testsweet.py

  • Committer: Martin Pool
  • Date: 2005-07-22 23:31:09 UTC
  • Revision ID: mbp@sourcefrog.net-20050722233109-7b030502e5311685
- selftest is less verbose by default, and takes a -v option if you want it

Show diffs side-by-side

added added

removed removed

Lines of Context:
227
227
 
228
228
    No special behaviour for now.
229
229
    """
230
 
    def __init__(self, out):
 
230
    def __init__(self, out, style):
231
231
        self.out = out
232
232
        TestResult.__init__(self)
 
233
        assert style in ('none', 'progress', 'verbose')
 
234
        self.style = style
 
235
 
233
236
 
234
237
    def startTest(self, test):
235
238
        # TODO: Maybe show test.shortDescription somewhere?
238
241
        if what == 'runit':
239
242
            what = test.shortDescription()
240
243
        
241
 
        print >>self.out, '%-60.60s' % what,
242
 
        self.out.flush()
 
244
        if self.style == 'verbose':
 
245
            print >>self.out, '%-60.60s' % what,
 
246
            self.out.flush()
 
247
        elif self.style == 'progress':
 
248
            self.out.write('~')
 
249
            self.out.flush()
243
250
        TestResult.startTest(self, test)
244
251
 
 
252
 
245
253
    def stopTest(self, test):
246
254
        # print
247
255
        TestResult.stopTest(self, test)
248
256
 
249
257
 
250
258
    def addError(self, test, err):
251
 
        print >>self.out, 'ERROR'
 
259
        if self.style == 'verbose':
 
260
            print >>self.out, 'ERROR'
252
261
        TestResult.addError(self, test, err)
253
262
        _show_test_failure('error', test, err, self.out)
254
263
 
255
264
    def addFailure(self, test, err):
256
 
        print >>self.out, 'FAILURE'
 
265
        if self.style == 'verbose':
 
266
            print >>self.out, 'FAILURE'
257
267
        TestResult.addFailure(self, test, err)
258
268
        _show_test_failure('failure', test, err, self.out)
259
269
 
260
270
    def addSuccess(self, test):
261
 
        print >>self.out, 'OK'
 
271
        if self.style == 'verbose':
 
272
            print >>self.out, 'OK'
262
273
        TestResult.addSuccess(self, test)
263
274
 
264
275
 
265
276
 
266
 
def run_suite(suite, name="test"):
 
277
def run_suite(suite, name='test', verbose=False):
267
278
    import os
268
279
    import shutil
269
280
    import time
278
289
    real_stderr = sys.stderr
279
290
    sys.stdout = sys.stderr = TestBase.TEST_LOG
280
291
    try:
281
 
        result = _MyResult(real_stdout)
 
292
        if verbose:
 
293
            style = 'verbose'
 
294
        else:
 
295
            style = 'progress'
 
296
        result = _MyResult(real_stdout, style)
282
297
        suite.run(result)
283
298
    finally:
284
299
        sys.stdout = real_stdout