/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-04 04:15:51 UTC
  • mfrom: (4583 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4585.
  • Revision ID: mbp@sourcefrog.net-20090804041551-xkpsxewk2v7wo0qc
merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
102
102
                          TestLoader,
103
103
                          )
104
104
from bzrlib.tests.treeshape import build_tree_contents
 
105
from bzrlib.ui import NullProgressView
105
106
from bzrlib.ui.text import TextUIFactory
106
107
import bzrlib.version_info_formats.format_custom
107
108
from bzrlib.workingtree import WorkingTree, WorkingTreeFormat2
113
114
 
114
115
default_transport = LocalURLServer
115
116
 
 
117
# Subunit result codes, defined here to prevent a hard dependency on subunit.
 
118
SUBUNIT_SEEK_SET = 0
 
119
SUBUNIT_SEEK_CUR = 1
 
120
 
116
121
 
117
122
class ExtendedTestResult(unittest._TextTestResult):
118
123
    """Accepts, reports and accumulates the results of running tests.
134
139
 
135
140
    def __init__(self, stream, descriptions, verbosity,
136
141
                 bench_history=None,
137
 
                 num_tests=None,
138
142
                 strict=False,
139
143
                 ):
140
144
        """Construct new TestResult.
159
163
            bench_history.write("--date %s %s\n" % (time.time(), revision_id))
160
164
        self._bench_history = bench_history
161
165
        self.ui = ui.ui_factory
162
 
        self.num_tests = num_tests
 
166
        self.num_tests = 0
163
167
        self.error_count = 0
164
168
        self.failure_count = 0
165
169
        self.known_failure_count = 0
359
363
            self.stream.writeln(self.separator2)
360
364
            self.stream.writeln("%s" % err)
361
365
 
 
366
    def progress(self, offset, whence):
 
367
        """The test is adjusting the count of tests to run."""
 
368
        if whence == SUBUNIT_SEEK_SET:
 
369
            self.num_tests = offset
 
370
        elif whence == SUBUNIT_SEEK_CUR:
 
371
            self.num_tests += offset
 
372
        else:
 
373
            raise errors.BzrError("Unknown whence %r" % whence)
 
374
 
362
375
    def finished(self):
363
376
        pass
364
377
 
379
392
 
380
393
    def __init__(self, stream, descriptions, verbosity,
381
394
                 bench_history=None,
382
 
                 num_tests=None,
383
395
                 pb=None,
384
396
                 strict=None,
385
397
                 ):
386
398
        ExtendedTestResult.__init__(self, stream, descriptions, verbosity,
387
 
            bench_history, num_tests, strict)
 
399
            bench_history, strict)
388
400
        if pb is None:
389
401
            self.pb = self.ui.nested_progress_bar()
390
402
            self._supplied_pb = False
410
422
        ##     a += ', %d skip' % self.skip_count
411
423
        ## if self.known_failure_count:
412
424
        ##     a += '+%dX' % self.known_failure_count
413
 
        if self.num_tests is not None:
 
425
        if self.num_tests:
414
426
            a +='/%d' % self.num_tests
415
427
        a += ' in '
416
428
        runtime = time.time() - self._overall_start_time
566
578
                              self.descriptions,
567
579
                              self.verbosity,
568
580
                              bench_history=self._bench_history,
569
 
                              num_tests=test.countTestCases(),
570
581
                              strict=self._strict,
571
582
                              )
572
583
        result.stop_early = self.stop_on_failure
709
720
    Hide the progress bar but emit note()s.
710
721
    Redirect stdin.
711
722
    Allows get_password to be tested without real tty attached.
 
723
 
 
724
    See also CannedInputUIFactory which lets you provide programmatic input in
 
725
    a structured way.
712
726
    """
 
727
    # XXX: Should probably unify more with CannedInputUIFactory or a
 
728
    # particular configuration of TextUIFactory, or otherwise have a clearer
 
729
    # idea of how they're supposed to be different.
 
730
    # See https://bugs.edge.launchpad.net/bzr/+bug/408213
713
731
 
714
732
    def __init__(self, stdout=None, stderr=None, stdin=None):
715
733
        if stdin is not None:
720
738
            stdin = StringIOWrapper(stdin)
721
739
        super(TestUIFactory, self).__init__(stdin, stdout, stderr)
722
740
 
723
 
    def clear(self):
724
 
        """See progress.ProgressBar.clear()."""
725
 
 
726
 
    def clear_term(self):
727
 
        """See progress.ProgressBar.clear_term()."""
728
 
 
729
 
    def finished(self):
730
 
        """See progress.ProgressBar.finished()."""
731
 
 
732
 
    def note(self, fmt_string, *args):
733
 
        """See progress.ProgressBar.note()."""
734
 
        if args:
735
 
            fmt_string = fmt_string % args
736
 
        self.stdout.write(fmt_string + "\n")
737
 
 
738
 
    def progress_bar(self):
739
 
        return self
740
 
 
741
 
    def nested_progress_bar(self):
742
 
        return self
 
741
    def make_progress_view(self):
 
742
        return NullProgressView()
743
743
 
744
744
    def update(self, message, count=None, total=None):
745
745
        """See progress.ProgressBar.update()."""
2752
2752
        decorators.append(filter_tests(pattern))
2753
2753
    if suite_decorators:
2754
2754
        decorators.extend(suite_decorators)
 
2755
    # tell the result object how many tests will be running:
 
2756
    decorators.append(CountingDecorator)
2755
2757
    for decorator in decorators:
2756
2758
        suite = decorator(suite)
2757
2759
    result = runner.run(suite)
2861
2863
        return result
2862
2864
 
2863
2865
 
 
2866
class CountingDecorator(TestDecorator):
 
2867
    """A decorator which calls result.progress(self.countTestCases)."""
 
2868
 
 
2869
    def run(self, result):
 
2870
        progress_method = getattr(result, 'progress', None)
 
2871
        if callable(progress_method):
 
2872
            progress_method(self.countTestCases(), SUBUNIT_SEEK_SET)
 
2873
        return super(CountingDecorator, self).run(result)
 
2874
 
 
2875
 
2864
2876
class ExcludeDecorator(TestDecorator):
2865
2877
    """A decorator which excludes test matching an exclude pattern."""
2866
2878