~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to testsweet.py

  • Committer: Robert Collins
  • Date: 2005-08-23 08:48:06 UTC
  • mto: (974.1.50) (1185.1.10) (1092.3.1)
  • mto: This revision was merged to the branch mainline in revision 1139.
  • Revision ID: robertc@robertcollins.net-20050823084805-4494544ab6fff3cd
consolidate MyResult more closely with TextTestResult

Show diffs side-by-side

added added

removed removed

Lines of Context:
264
264
 
265
265
    No special behaviour for now.
266
266
    """
267
 
    def __init__(self, stream, descriptions, verbosity, style):
268
 
        super(_MyResult, self).__init__(stream, descriptions, verbosity)
269
 
        self.out = stream
270
 
        assert style in ('none', 'progress', 'verbose')
271
 
        self.style = style
272
267
 
273
268
    def startTest(self, test):
274
 
        super(_MyResult, self).startTest(test)
 
269
        unittest.TestResult.startTest(self, test)
275
270
        # TODO: Maybe show test.shortDescription somewhere?
276
271
        what = test.id()
277
272
        # python2.3 has the bad habit of just "runit" for doctests
278
273
        if what == 'runit':
279
274
            what = test.shortDescription()
280
 
        if self.style == 'verbose':
281
 
            print >>self.stream, '%-60.60s' % what,
282
 
            self.stream.flush()
 
275
        if self.showAll:
 
276
            self.stream.write('%-60.60s' % what)
 
277
        self.stream.flush()
283
278
 
284
279
    def addError(self, test, err):
285
 
        if self.style == 'verbose':
286
 
            print >>self.stream, 'ERROR'
287
 
        elif self.style == 'progress':
288
 
            self.stream.write('E')
289
 
        self.stream.flush()
290
280
        super(_MyResult, self).addError(test, err)
 
281
        self.stream.flush()
291
282
 
292
283
    def addFailure(self, test, err):
293
 
        if self.style == 'verbose':
294
 
            print >>self.stream, 'FAILURE'
295
 
        elif self.style == 'progress':
296
 
            self.stream.write('F')
297
 
        self.stream.flush()
298
284
        super(_MyResult, self).addFailure(test, err)
 
285
        self.stream.flush()
299
286
 
300
287
    def addSuccess(self, test):
301
 
        if self.style == 'verbose':
302
 
            print >>self.stream, 'OK'
303
 
        elif self.style == 'progress':
 
288
        if self.showAll:
 
289
            self.stream.writeln('OK')
 
290
        elif self.dots:
304
291
            self.stream.write('~')
305
292
        self.stream.flush()
306
 
        super(_MyResult, self).addSuccess(test)
307
 
 
308
 
    def printErrors(self):
309
 
        if self.style == 'progress':
310
 
            self.stream.writeln()
311
 
        super(_MyResult, self).printErrors()
 
293
        unittest.TestResult.addSuccess(self, test)
312
294
 
313
295
    def printErrorList(self, flavour, errors):
314
296
        for test, err in errors:
325
307
 
326
308
class TextTestRunner(unittest.TextTestRunner):
327
309
 
328
 
    def __init__(self, stream=sys.stderr, descriptions=1, verbosity=0, style='progress'):
 
310
    def __init__(self, stream=sys.stderr, descriptions=0, verbosity=1):
329
311
        super(TextTestRunner, self).__init__(stream, descriptions, verbosity)
330
 
        self.style = style
331
312
 
332
313
    def _makeResult(self):
333
 
        return _MyResult(self.stream, self.descriptions, self.verbosity, self.style)
 
314
        return _MyResult(self.stream, self.descriptions, self.verbosity)
334
315
 
335
316
    # If we want the old 4 line summary output (count, 0 failures, 0 errors)
336
317
    # we can override run() too.
340
321
    import shutil
341
322
    InTempDir._TEST_NAME = name
342
323
    if verbose:
343
 
        style = 'verbose'
344
324
        verbosity = 2
345
325
    else:
346
 
        style = 'progress'
347
326
        verbosity = 1
348
 
    runner = TextTestRunner(stream=sys.stdout, style=style)
 
327
    runner = TextTestRunner(stream=sys.stdout, verbosity=verbosity)
349
328
    result = runner.run(suite)
350
329
    # This is still a little bogus, 
351
330
    # but only a little. Folk not using our testrunner will