/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: Robert J. Tanner
  • Date: 2009-04-28 23:20:23 UTC
  • mfrom: (4309 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4310.
  • Revision ID: tanner@real-time.com-20090428232023-9oevb3ggwhjaxgmp
[merge] bzr-1.13.2 back to trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
133
133
    def __init__(self, stream, descriptions, verbosity,
134
134
                 bench_history=None,
135
135
                 num_tests=None,
 
136
                 strict=False,
136
137
                 ):
137
138
        """Construct new TestResult.
138
139
 
165
166
        self.unsupported = {}
166
167
        self.count = 0
167
168
        self._overall_start_time = time.time()
 
169
        self._strict = strict
 
170
 
 
171
    def done(self):
 
172
        if self._strict:
 
173
            ok = self.wasStrictlySuccessful()
 
174
        else:
 
175
            ok = self.wasSuccessful()
 
176
        if ok:
 
177
            self.stream.write('tests passed\n')
 
178
        else:
 
179
            self.stream.write('tests failed\n')
 
180
        if TestCase._first_thread_leaker_id:
 
181
            self.stream.write(
 
182
                '%s is leaking threads among %d leaking tests.\n' % (
 
183
                TestCase._first_thread_leaker_id,
 
184
                TestCase._leaking_threads_tests))
168
185
 
169
186
    def _extractBenchmarkTime(self, testCase):
170
187
        """Add a benchmark time for the current test case."""
196
213
 
197
214
    def startTest(self, test):
198
215
        unittest.TestResult.startTest(self, test)
 
216
        if self.count == 0:
 
217
            self.startTests()
199
218
        self.report_test_start(test)
200
219
        test.number = self.count
201
220
        self._recordTestStartTime()
202
221
 
 
222
    def startTests(self):
 
223
        self.stream.write(
 
224
            'testing: %s\n' % (osutils.realpath(sys.argv[0]),))
 
225
        self.stream.write(
 
226
            '   %s (%s python%s)\n' % (
 
227
                    bzrlib.__path__[0],
 
228
                    bzrlib.version_string,
 
229
                    bzrlib._format_version_tuple(sys.version_info),
 
230
                    ))
 
231
        self.stream.write('\n')
 
232
 
203
233
    def _recordTestStartTime(self):
204
234
        """Record that a test has started."""
205
235
        self._start_time = time.time()
349
379
                 bench_history=None,
350
380
                 num_tests=None,
351
381
                 pb=None,
 
382
                 strict=None,
352
383
                 ):
353
384
        ExtendedTestResult.__init__(self, stream, descriptions, verbosity,
354
 
            bench_history, num_tests)
 
385
            bench_history, num_tests, strict)
355
386
        if pb is None:
356
387
            self.pb = self.ui.nested_progress_bar()
357
388
            self._supplied_pb = False
512
543
                 descriptions=0,
513
544
                 verbosity=1,
514
545
                 bench_history=None,
515
 
                 list_only=False
 
546
                 list_only=False,
 
547
                 strict=False,
516
548
                 ):
517
549
        self.stream = unittest._WritelnDecorator(stream)
518
550
        self.descriptions = descriptions
519
551
        self.verbosity = verbosity
520
552
        self._bench_history = bench_history
521
553
        self.list_only = list_only
 
554
        self._strict = strict
522
555
 
523
556
    def run(self, test):
524
557
        "Run the given test case or test suite."
532
565
                              self.verbosity,
533
566
                              bench_history=self._bench_history,
534
567
                              num_tests=test.countTestCases(),
 
568
                              strict=self._strict,
535
569
                              )
536
570
        result.stop_early = self.stop_on_failure
537
571
        result.report_starting()
716
750
        return password
717
751
 
718
752
 
719
 
def _report_leaked_threads():
720
 
    bzrlib.trace.warning('%s is leaking threads among %d leaking tests',
721
 
                         TestCase._first_thread_leaker_id,
722
 
                         TestCase._leaking_threads_tests)
723
 
 
724
 
 
725
753
class TestCase(unittest.TestCase):
726
754
    """Base class for bzr unit tests.
727
755
 
787
815
            TestCase._leaking_threads_tests += 1
788
816
            if TestCase._first_thread_leaker_id is None:
789
817
                TestCase._first_thread_leaker_id = self.id()
790
 
                # we're not specifically told when all tests are finished.
791
 
                # This will do. We use a function to avoid keeping a reference
792
 
                # to a TestCase object.
793
 
                atexit.register(_report_leaked_threads)
794
818
 
795
819
    def _clear_debug_flags(self):
796
820
        """Prevent externally set debug flags affecting tests.
2617
2641
              exclude_pattern=None,
2618
2642
              strict=False,
2619
2643
              runner_class=None,
2620
 
              suite_decorators=None):
 
2644
              suite_decorators=None,
 
2645
              stream=None):
2621
2646
    """Run a test suite for bzr selftest.
2622
2647
 
2623
2648
    :param runner_class: The class of runner to use. Must support the
2632
2657
        verbosity = 1
2633
2658
    if runner_class is None:
2634
2659
        runner_class = TextTestRunner
2635
 
    runner = runner_class(stream=sys.stdout,
 
2660
    if stream is None:
 
2661
        stream = sys.stdout
 
2662
    runner = runner_class(stream=stream,
2636
2663
                            descriptions=0,
2637
2664
                            verbosity=verbosity,
2638
2665
                            bench_history=bench_history,
2639
2666
                            list_only=list_only,
 
2667
                            strict=strict,
2640
2668
                            )
2641
2669
    runner.stop_on_failure=stop_on_failure
2642
2670
    # built in decorator factories:
2655
2683
    result = runner.run(suite)
2656
2684
    if list_only:
2657
2685
        return True
 
2686
    result.done()
2658
2687
    if strict:
2659
2688
        return result.wasStrictlySuccessful()
2660
2689
    else:
3908
3937
    from subunit import TestProtocolClient
3909
3938
    class SubUnitBzrRunner(TextTestRunner):
3910
3939
        def run(self, test):
3911
 
            # undo out claim for testing which looks like a test start to subunit
3912
 
            self.stream.write("success: %s\n" % (osutils.realpath(sys.argv[0]),))
3913
3940
            result = TestProtocolClient(self.stream)
3914
3941
            test.run(result)
3915
3942
            return result