/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:12:10 UTC
  • mfrom: (4581 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4582.
  • Revision ID: mbp@sourcefrog.net-20090803061210-cuq09gc56h3egcx8
merge news

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
359
362
            self.stream.writeln(self.separator2)
360
363
            self.stream.writeln("%s" % err)
361
364
 
 
365
    def progress(self, offset, whence):
 
366
        """The test is adjusting the count of tests to run."""
 
367
        if whence == SUBUNIT_SEEK_SET:
 
368
            self.num_tests = offset
 
369
        elif whence == SUBUNIT_SEEK_CUR:
 
370
            self.num_tests += offset
 
371
        else:
 
372
            raise errors.BzrError("Unknown whence %r" % whence)
 
373
 
362
374
    def finished(self):
363
375
        pass
364
376
 
379
391
 
380
392
    def __init__(self, stream, descriptions, verbosity,
381
393
                 bench_history=None,
382
 
                 num_tests=None,
383
394
                 pb=None,
384
395
                 strict=None,
385
396
                 ):
386
397
        ExtendedTestResult.__init__(self, stream, descriptions, verbosity,
387
 
            bench_history, num_tests, strict)
 
398
            bench_history, strict)
388
399
        if pb is None:
389
400
            self.pb = self.ui.nested_progress_bar()
390
401
            self._supplied_pb = False
410
421
        ##     a += ', %d skip' % self.skip_count
411
422
        ## if self.known_failure_count:
412
423
        ##     a += '+%dX' % self.known_failure_count
413
 
        if self.num_tests is not None:
 
424
        if self.num_tests:
414
425
            a +='/%d' % self.num_tests
415
426
        a += ' in '
416
427
        runtime = time.time() - self._overall_start_time
566
577
                              self.descriptions,
567
578
                              self.verbosity,
568
579
                              bench_history=self._bench_history,
569
 
                              num_tests=test.countTestCases(),
570
580
                              strict=self._strict,
571
581
                              )
572
582
        result.stop_early = self.stop_on_failure
2752
2762
        decorators.append(filter_tests(pattern))
2753
2763
    if suite_decorators:
2754
2764
        decorators.extend(suite_decorators)
 
2765
    # tell the result object how many tests will be running:
 
2766
    decorators.append(CountingDecorator)
2755
2767
    for decorator in decorators:
2756
2768
        suite = decorator(suite)
2757
2769
    result = runner.run(suite)
2861
2873
        return result
2862
2874
 
2863
2875
 
 
2876
class CountingDecorator(TestDecorator):
 
2877
    """A decorator which calls result.progress(self.countTestCases)."""
 
2878
 
 
2879
    def run(self, result):
 
2880
        progress_method = getattr(result, 'progress', None)
 
2881
        if callable(progress_method):
 
2882
            progress_method(self.countTestCases(), SUBUNIT_SEEK_SET)
 
2883
        return super(CountingDecorator, self).run(result)
 
2884
 
 
2885
 
2864
2886
class ExcludeDecorator(TestDecorator):
2865
2887
    """A decorator which excludes test matching an exclude pattern."""
2866
2888