~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/__init__.py

  • Committer: John Arbash Meinel
  • Date: 2009-10-20 19:46:46 UTC
  • mfrom: (4759 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4771.
  • Revision ID: john@arbash-meinel.com-20091020194646-wnqpd15qs19y28z7
Merge bzr.dev 4759, bringing in static_tuple and streaming improvements.

Show diffs side-by-side

added added

removed removed

Lines of Context:
222
222
                '%s is leaking threads among %d leaking tests.\n' % (
223
223
                TestCase._first_thread_leaker_id,
224
224
                TestCase._leaking_threads_tests))
 
225
            # We don't report the main thread as an active one.
 
226
            self.stream.write(
 
227
                '%d non-main threads were left active in the end.\n'
 
228
                % (TestCase._active_threads - 1))
225
229
 
226
230
    def _extractBenchmarkTime(self, testCase):
227
231
        """Add a benchmark time for the current test case."""
846
850
        active = threading.activeCount()
847
851
        leaked_threads = active - TestCase._active_threads
848
852
        TestCase._active_threads = active
849
 
        if leaked_threads:
 
853
        # If some tests make the number of threads *decrease*, we'll consider
 
854
        # that they are just observing old threads dieing, not agressively kill
 
855
        # random threads. So we don't report these tests as leaking. The risk
 
856
        # is that we have false positives that way (the test see 2 threads
 
857
        # going away but leak one) but it seems less likely than the actual
 
858
        # false positives (the test see threads going away and does not leak).
 
859
        if leaked_threads > 0:
850
860
            TestCase._leaking_threads_tests += 1
851
861
            if TestCase._first_thread_leaker_id is None:
852
862
                TestCase._first_thread_leaker_id = self.id()
1146
1156
            self.fail("Incorrect length: wanted %d, got %d for %r" % (
1147
1157
                length, len(obj_with_len), obj_with_len))
1148
1158
 
 
1159
    def assertLogsError(self, exception_class, func, *args, **kwargs):
 
1160
        """Assert that func(*args, **kwargs) quietly logs a specific exception.
 
1161
        """
 
1162
        from bzrlib import trace
 
1163
        captured = []
 
1164
        orig_log_exception_quietly = trace.log_exception_quietly
 
1165
        try:
 
1166
            def capture():
 
1167
                orig_log_exception_quietly()
 
1168
                captured.append(sys.exc_info())
 
1169
            trace.log_exception_quietly = capture
 
1170
            func(*args, **kwargs)
 
1171
        finally:
 
1172
            trace.log_exception_quietly = orig_log_exception_quietly
 
1173
        self.assertLength(1, captured)
 
1174
        err = captured[0][1]
 
1175
        self.assertIsInstance(err, exception_class)
 
1176
        return err
 
1177
 
1149
1178
    def assertPositive(self, val):
1150
1179
        """Assert that val is greater than 0."""
1151
1180
        self.assertTrue(val > 0, 'expected a positive value, but got %s' % val)
3650
3679
        'bzrlib.tests.commands',
3651
3680
        'bzrlib.tests.per_branch',
3652
3681
        'bzrlib.tests.per_bzrdir',
 
3682
        'bzrlib.tests.per_foreign_vcs',
3653
3683
        'bzrlib.tests.per_interrepository',
3654
3684
        'bzrlib.tests.per_intertree',
3655
3685
        'bzrlib.tests.per_inventory',
3661
3691
        'bzrlib.tests.per_repository',
3662
3692
        'bzrlib.tests.per_repository_chk',
3663
3693
        'bzrlib.tests.per_repository_reference',
 
3694
        'bzrlib.tests.per_uifactory',
3664
3695
        'bzrlib.tests.per_versionedfile',
3665
3696
        'bzrlib.tests.per_workingtree',
3666
3697
        'bzrlib.tests.test__annotator',