/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/__init__.py

  • Committer: Martin Pool
  • Date: 2009-08-03 06:29:41 UTC
  • mfrom: (4581 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4584.
  • Revision ID: mbp@sourcefrog.net-20090803062941-67p53bo533l7srud
merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
113
113
 
114
114
default_transport = LocalURLServer
115
115
 
 
116
# Subunit result codes, defined here to prevent a hard dependency on subunit.
 
117
SUBUNIT_SEEK_SET = 0
 
118
SUBUNIT_SEEK_CUR = 1
 
119
 
116
120
 
117
121
class ExtendedTestResult(unittest._TextTestResult):
118
122
    """Accepts, reports and accumulates the results of running tests.
134
138
 
135
139
    def __init__(self, stream, descriptions, verbosity,
136
140
                 bench_history=None,
137
 
                 num_tests=None,
138
141
                 strict=False,
139
142
                 ):
140
143
        """Construct new TestResult.
159
162
            bench_history.write("--date %s %s\n" % (time.time(), revision_id))
160
163
        self._bench_history = bench_history
161
164
        self.ui = ui.ui_factory
162
 
        self.num_tests = num_tests
 
165
        self.num_tests = 0
163
166
        self.error_count = 0
164
167
        self.failure_count = 0
165
168
        self.known_failure_count = 0
361
364
            self.stream.writeln(self.separator2)
362
365
            self.stream.writeln("%s" % err)
363
366
 
 
367
    def progress(self, offset, whence):
 
368
        """The test is adjusting the count of tests to run."""
 
369
        if whence == SUBUNIT_SEEK_SET:
 
370
            self.num_tests = offset
 
371
        elif whence == SUBUNIT_SEEK_CUR:
 
372
            self.num_tests += offset
 
373
        else:
 
374
            raise errors.BzrError("Unknown whence %r" % whence)
 
375
 
364
376
    def finished(self):
365
377
        pass
366
378
 
381
393
 
382
394
    def __init__(self, stream, descriptions, verbosity,
383
395
                 bench_history=None,
384
 
                 num_tests=None,
385
396
                 pb=None,
386
397
                 strict=None,
387
398
                 ):
388
399
        ExtendedTestResult.__init__(self, stream, descriptions, verbosity,
389
 
            bench_history, num_tests, strict)
 
400
            bench_history, strict)
390
401
        # We no longer pass them around, but just rely on the UIFactory stack
391
402
        # for state
392
403
        if pb is not None:
426
437
        ##     a += ', %d skip' % self.skip_count
427
438
        ## if self.known_failure_count:
428
439
        ##     a += '+%dX' % self.known_failure_count
429
 
        if self.num_tests is not None:
 
440
        if self.num_tests:
430
441
            a +='/%d' % self.num_tests
431
442
        a += ' in '
432
443
        runtime = time.time() - self._overall_start_time
578
589
                              self.descriptions,
579
590
                              self.verbosity,
580
591
                              bench_history=self._bench_history,
581
 
                              num_tests=test.countTestCases(),
582
592
                              strict=self._strict,
583
593
                              )
584
594
        result.stop_early = self.stop_on_failure
2764
2774
        decorators.append(filter_tests(pattern))
2765
2775
    if suite_decorators:
2766
2776
        decorators.extend(suite_decorators)
 
2777
    # tell the result object how many tests will be running:
 
2778
    decorators.append(CountingDecorator)
2767
2779
    for decorator in decorators:
2768
2780
        suite = decorator(suite)
2769
2781
    result = runner.run(suite)
2873
2885
        return result
2874
2886
 
2875
2887
 
 
2888
class CountingDecorator(TestDecorator):
 
2889
    """A decorator which calls result.progress(self.countTestCases)."""
 
2890
 
 
2891
    def run(self, result):
 
2892
        progress_method = getattr(result, 'progress', None)
 
2893
        if callable(progress_method):
 
2894
            progress_method(self.countTestCases(), SUBUNIT_SEEK_SET)
 
2895
        return super(CountingDecorator, self).run(result)
 
2896
 
 
2897
 
2876
2898
class ExcludeDecorator(TestDecorator):
2877
2899
    """A decorator which excludes test matching an exclude pattern."""
2878
2900