/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: Canonical.com Patch Queue Manager
  • Date: 2009-03-01 12:18:57 UTC
  • mfrom: (4063.1.3 integration)
  • Revision ID: pqm@pqm.ubuntu.com-20090301121857-3lxdqurjbln7ybd2
(robertc) Move skipping-test detection to TestCase from TestResult.
        (Robert Collins)

Show diffs side-by-side

added added

removed removed

Lines of Context:
216
216
        fails with an unexpected error.
217
217
        """
218
218
        self._testConcluded(test)
219
 
        if isinstance(err[1], TestSkipped):
220
 
            return self._addSkipped(test, err)
 
219
        if isinstance(err[1], TestNotApplicable):
 
220
            return self._addNotApplicable(test, err)
221
221
        elif isinstance(err[1], UnavailableFeature):
222
222
            return self.addNotSupported(test, err[1].args[0])
223
223
        else:
286
286
        self.unsupported[str(feature)] += 1
287
287
        self.report_unsupported(test, feature)
288
288
 
289
 
    def _addSkipped(self, test, skip_excinfo):
 
289
    def addSkip(self, test, reason):
 
290
        """A test has not run for 'reason'."""
 
291
        self.skip_count += 1
 
292
        self.report_skip(test, reason)
 
293
 
 
294
    def _addNotApplicable(self, test, skip_excinfo):
290
295
        if isinstance(skip_excinfo[1], TestNotApplicable):
291
296
            self.not_applicable_count += 1
292
297
            self.report_not_applicable(test, skip_excinfo)
293
 
        else:
294
 
            self.skip_count += 1
295
 
            self.report_skip(test, skip_excinfo)
296
298
        try:
297
299
            test.tearDown()
298
300
        except KeyboardInterrupt:
299
301
            raise
300
302
        except:
301
 
            self.addError(test, test._exc_info())
 
303
            self.addError(test, test.exc_info())
302
304
        else:
303
305
            # seems best to treat this as success from point-of-view of unittest
304
306
            # -- it actually does nothing so it barely matters :)
416
418
        self.pb.note('XFAIL: %s\n%s\n',
417
419
            self._test_description(test), err[1])
418
420
 
419
 
    def report_skip(self, test, skip_excinfo):
 
421
    def report_skip(self, test, reason):
420
422
        pass
421
423
 
422
424
    def report_not_applicable(self, test, skip_excinfo):
485
487
        # used to show the output in PQM.
486
488
        self.stream.flush()
487
489
 
488
 
    def report_skip(self, test, skip_excinfo):
 
490
    def report_skip(self, test, reason):
489
491
        self.stream.writeln(' SKIP %s\n%s'
490
 
                % (self._testTimeString(test),
491
 
                   self._error_summary(skip_excinfo)))
 
492
                % (self._testTimeString(test), reason))
492
493
 
493
494
    def report_not_applicable(self, test, skip_excinfo):
494
495
        self.stream.writeln('  N/A %s\n%s'
775
776
        TestCase._active_threads = threading.activeCount()
776
777
        self.addCleanup(self._check_leaked_threads)
777
778
 
 
779
    def exc_info(self):
 
780
        absent_attr = object()
 
781
        exc_info = getattr(self, '_exc_info', absent_attr)
 
782
        if exc_info is absent_attr:
 
783
            exc_info = getattr(self, '_TestCase__exc_info')
 
784
        return exc_info()
 
785
 
778
786
    def _check_leaked_threads(self):
779
787
        active = threading.activeCount()
780
788
        leaked_threads = active - TestCase._active_threads
1282
1290
        """This test has failed for some known reason."""
1283
1291
        raise KnownFailure(reason)
1284
1292
 
 
1293
    def _do_skip(self, result, reason):
 
1294
        addSkip = getattr(result, 'addSkip', None)
 
1295
        if not callable(addSkip):
 
1296
            result.addError(self, self.exc_info())
 
1297
        else:
 
1298
            addSkip(self, reason)
 
1299
 
1285
1300
    def run(self, result=None):
1286
1301
        if result is None: result = self.defaultTestResult()
1287
1302
        for feature in getattr(self, '_test_needs_features', []):
1294
1309
                result.stopTest(self)
1295
1310
                return
1296
1311
        try:
1297
 
            return unittest.TestCase.run(self, result)
 
1312
            try:
 
1313
                result.startTest(self)
 
1314
                absent_attr = object()
 
1315
                # Python 2.5
 
1316
                method_name = getattr(self, '_testMethodName', absent_attr)
 
1317
                if method_name is absent_attr:
 
1318
                    # Python 2.4
 
1319
                    method_name = getattr(self, '_TestCase__testMethodName')
 
1320
                testMethod = getattr(self, method_name)
 
1321
                try:
 
1322
                    try:
 
1323
                        self.setUp()
 
1324
                    except KeyboardInterrupt:
 
1325
                        raise
 
1326
                    except TestSkipped, e:
 
1327
                        self._do_skip(result, e.args[0])
 
1328
                        self.tearDown()
 
1329
                        return
 
1330
                    except:
 
1331
                        result.addError(self, self.exc_info())
 
1332
                        return
 
1333
 
 
1334
                    ok = False
 
1335
                    try:
 
1336
                        testMethod()
 
1337
                        ok = True
 
1338
                    except self.failureException:
 
1339
                        result.addFailure(self, self.exc_info())
 
1340
                    except TestSkipped, e:
 
1341
                        if not e.args:
 
1342
                            reason = "No reason given."
 
1343
                        else:
 
1344
                            reason = e.args[0]
 
1345
                        self._do_skip(result, reason)
 
1346
                    except KeyboardInterrupt:
 
1347
                        raise
 
1348
                    except:
 
1349
                        result.addError(self, self.exc_info())
 
1350
 
 
1351
                    try:
 
1352
                        self.tearDown()
 
1353
                    except KeyboardInterrupt:
 
1354
                        raise
 
1355
                    except:
 
1356
                        result.addError(self, self.exc_info())
 
1357
                        ok = False
 
1358
                    if ok: result.addSuccess(self)
 
1359
                finally:
 
1360
                    result.stopTest(self)
 
1361
                return
 
1362
            except TestNotApplicable:
 
1363
                # Not moved from the result [yet].
 
1364
                raise
 
1365
            except KeyboardInterrupt:
 
1366
                raise
1298
1367
        finally:
1299
1368
            saved_attrs = {}
1300
1369
            absent_attr = object()
1306
1375
 
1307
1376
    def tearDown(self):
1308
1377
        self._runCleanups()
 
1378
        self._log_contents = ''
1309
1379
        unittest.TestCase.tearDown(self)
1310
1380
 
1311
1381
    def time(self, callable, *args, **kwargs):