~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/__init__.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2010-09-26 14:39:52 UTC
  • mfrom: (5387.2.9 2.3-filter-tests)
  • Revision ID: pqm@pqm.ubuntu.com-20100926143952-qdatcpmr3xkus9h2
(jameinel) Remove 'log' information from "successful" tests (John A Meinel)

Show diffs side-by-side

added added

removed removed

Lines of Context:
846
846
        import pdb
847
847
        pdb.Pdb().set_trace(sys._getframe().f_back)
848
848
 
 
849
    def discardDetail(self, name):
 
850
        """Extend the addDetail, getDetails api so we can remove a detail.
 
851
 
 
852
        eg. bzr always adds the 'log' detail at startup, but we don't want to
 
853
        include it for skipped, xfail, etc tests.
 
854
 
 
855
        It is safe to call this for a detail that doesn't exist, in case this
 
856
        gets called multiple times.
 
857
        """
 
858
        # We cheat. details is stored in __details which means we shouldn't
 
859
        # touch it. but getDetails() returns the dict directly, so we can
 
860
        # mutate it.
 
861
        details = self.getDetails()
 
862
        if name in details:
 
863
            del details[name]
 
864
 
849
865
    def _clear_debug_flags(self):
850
866
        """Prevent externally set debug flags affecting tests.
851
867
 
1569
1585
        """This test has failed for some known reason."""
1570
1586
        raise KnownFailure(reason)
1571
1587
 
 
1588
    def _suppress_log(self):
 
1589
        """Remove the log info from details."""
 
1590
        self.discardDetail('log')
 
1591
 
1572
1592
    def _do_skip(self, result, reason):
 
1593
        self._suppress_log()
1573
1594
        addSkip = getattr(result, 'addSkip', None)
1574
1595
        if not callable(addSkip):
1575
1596
            result.addSuccess(result)
1578
1599
 
1579
1600
    @staticmethod
1580
1601
    def _do_known_failure(self, result, e):
 
1602
        self._suppress_log()
1581
1603
        err = sys.exc_info()
1582
1604
        addExpectedFailure = getattr(result, 'addExpectedFailure', None)
1583
1605
        if addExpectedFailure is not None:
1591
1613
            reason = 'No reason given'
1592
1614
        else:
1593
1615
            reason = e.args[0]
 
1616
        self._suppress_log ()
1594
1617
        addNotApplicable = getattr(result, 'addNotApplicable', None)
1595
1618
        if addNotApplicable is not None:
1596
1619
            result.addNotApplicable(self, reason)
1598
1621
            self._do_skip(result, reason)
1599
1622
 
1600
1623
    @staticmethod
 
1624
    def _report_skip(self, result, err):
 
1625
        """Override the default _report_skip.
 
1626
 
 
1627
        We want to strip the 'log' detail. If we waint until _do_skip, it has
 
1628
        already been formatted into the 'reason' string, and we can't pull it
 
1629
        out again.
 
1630
        """
 
1631
        self._suppress_log()
 
1632
        super(TestCase, self)._report_skip(self, result, err)
 
1633
 
 
1634
    @staticmethod
 
1635
    def _report_expected_failure(self, result, err):
 
1636
        """Strip the log.
 
1637
 
 
1638
        See _report_skip for motivation.
 
1639
        """
 
1640
        self._suppress_log()
 
1641
        super(TestCase, self)._report_expected_failure(self, result, err)
 
1642
 
 
1643
    @staticmethod
1601
1644
    def _do_unsupported_or_skip(self, result, e):
1602
1645
        reason = e.args[0]
 
1646
        self._suppress_log()
1603
1647
        addNotSupported = getattr(result, 'addNotSupported', None)
1604
1648
        if addNotSupported is not None:
1605
1649
            result.addNotSupported(self, reason)
4459
4503
try:
4460
4504
    from subunit import TestProtocolClient
4461
4505
    from subunit.test_results import AutoTimingTestResultDecorator
 
4506
    class SubUnitBzrProtocolClient(TestProtocolClient):
 
4507
 
 
4508
        def addSuccess(self, test, details=None):
 
4509
            # The subunit client always includes the details in the subunit
 
4510
            # stream, but we don't want to include it in ours.
 
4511
            if details is not None and 'log' in details:
 
4512
                del details['log']
 
4513
            return super(SubUnitBzrProtocolClient, self).addSuccess(
 
4514
                test, details)
 
4515
 
4462
4516
    class SubUnitBzrRunner(TextTestRunner):
4463
4517
        def run(self, test):
4464
4518
            result = AutoTimingTestResultDecorator(
4465
 
                TestProtocolClient(self.stream))
 
4519
                SubUnitBzrProtocolClient(self.stream))
4466
4520
            test.run(result)
4467
4521
            return result
4468
4522
except ImportError: