~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/__init__.py

Merge bzr.dev

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."""
496
500
            a += ', %d err' % self.error_count
497
501
        if self.failure_count:
498
502
            a += ', %d fail' % self.failure_count
499
 
        if self.unsupported:
500
 
            a += ', %d missing' % len(self.unsupported)
 
503
        # if self.unsupported:
 
504
        #     a += ', %d missing' % len(self.unsupported)
501
505
        a += ']'
502
506
        return a
503
507
 
512
516
        return self._shortened_test_description(test)
513
517
 
514
518
    def report_error(self, test, err):
515
 
        self.pb.note('ERROR: %s\n    %s\n',
 
519
        ui.ui_factory.note('ERROR: %s\n    %s\n' % (
516
520
            self._test_description(test),
517
521
            err[1],
518
 
            )
 
522
            ))
519
523
 
520
524
    def report_failure(self, test, err):
521
 
        self.pb.note('FAIL: %s\n    %s\n',
 
525
        ui.ui_factory.note('FAIL: %s\n    %s\n' % (
522
526
            self._test_description(test),
523
527
            err[1],
524
 
            )
 
528
            ))
525
529
 
526
530
    def report_known_failure(self, test, err):
527
 
        self.pb.note('XFAIL: %s\n%s\n',
528
 
            self._test_description(test), err[1])
 
531
        ui.ui_factory.note('XFAIL: %s\n%s\n' % (
 
532
            self._test_description(test), err[1]))
529
533
 
530
534
    def report_skip(self, test, reason):
531
535
        pass
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)
3661
3690
        'bzrlib.tests.per_repository',
3662
3691
        'bzrlib.tests.per_repository_chk',
3663
3692
        'bzrlib.tests.per_repository_reference',
 
3693
        'bzrlib.tests.per_uifactory',
3664
3694
        'bzrlib.tests.per_versionedfile',
3665
3695
        'bzrlib.tests.per_workingtree',
3666
3696
        'bzrlib.tests.test__annotator',
3669
3699
        'bzrlib.tests.test__groupcompress',
3670
3700
        'bzrlib.tests.test__known_graph',
3671
3701
        'bzrlib.tests.test__rio',
 
3702
        'bzrlib.tests.test__simple_set',
 
3703
        'bzrlib.tests.test__static_tuple',
3672
3704
        'bzrlib.tests.test__walkdirs_win32',
3673
3705
        'bzrlib.tests.test_ancestry',
3674
3706
        'bzrlib.tests.test_annotate',
4203
4235
HTTPSServerFeature = _HTTPSServerFeature()
4204
4236
 
4205
4237
 
 
4238
class _ParamikoFeature(Feature):
 
4239
    """Is paramiko available?"""
 
4240
 
 
4241
    def _probe(self):
 
4242
        try:
 
4243
            from bzrlib.transport.sftp import SFTPAbsoluteServer
 
4244
            return True
 
4245
        except errors.ParamikoNotPresent:
 
4246
            return False
 
4247
 
 
4248
    def feature_name(self):
 
4249
        return "Paramiko"
 
4250
 
 
4251
 
 
4252
ParamikoFeature = _ParamikoFeature()
 
4253
 
 
4254
 
4206
4255
class _UnicodeFilename(Feature):
4207
4256
    """Does the filesystem support Unicode filenames?"""
4208
4257
 
4234
4283
UTF8Filesystem = _UTF8Filesystem()
4235
4284
 
4236
4285
 
 
4286
class _BreakinFeature(Feature):
 
4287
    """Does this platform support the breakin feature?"""
 
4288
 
 
4289
    def _probe(self):
 
4290
        from bzrlib import breakin
 
4291
        if breakin.determine_signal() is None:
 
4292
            return False
 
4293
        if sys.platform == 'win32':
 
4294
            # Windows doesn't have os.kill, and we catch the SIGBREAK signal.
 
4295
            # We trigger SIGBREAK via a Console api so we need ctypes to
 
4296
            # access the function
 
4297
            if not have_ctypes:
 
4298
                return False
 
4299
        return True
 
4300
 
 
4301
    def feature_name(self):
 
4302
        return "SIGQUIT or SIGBREAK w/ctypes on win32"
 
4303
 
 
4304
 
 
4305
BreakinFeature = _BreakinFeature()
 
4306
 
 
4307
 
4237
4308
class _CaseInsCasePresFilenameFeature(Feature):
4238
4309
    """Is the file-system case insensitive, but case-preserving?"""
4239
4310