~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/__init__.py

  • Committer: Andrew Bennetts
  • Date: 2010-09-23 07:40:07 UTC
  • mfrom: (5050.17.24 2.2)
  • mto: This revision was merged to the branch mainline in revision 5440.
  • Revision ID: andrew.bennetts@canonical.com-20100923074007-bqk101393z4npbw0
MergeĀ lp:bzr/2.2.

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
 
 
865
849
    def _clear_debug_flags(self):
866
850
        """Prevent externally set debug flags affecting tests.
867
851
 
1585
1569
        """This test has failed for some known reason."""
1586
1570
        raise KnownFailure(reason)
1587
1571
 
1588
 
    def _suppress_log(self):
1589
 
        """Remove the log info from details."""
1590
 
        self.discardDetail('log')
1591
 
 
1592
1572
    def _do_skip(self, result, reason):
1593
 
        self._suppress_log()
1594
1573
        addSkip = getattr(result, 'addSkip', None)
1595
1574
        if not callable(addSkip):
1596
1575
            result.addSuccess(result)
1599
1578
 
1600
1579
    @staticmethod
1601
1580
    def _do_known_failure(self, result, e):
1602
 
        self._suppress_log()
1603
1581
        err = sys.exc_info()
1604
1582
        addExpectedFailure = getattr(result, 'addExpectedFailure', None)
1605
1583
        if addExpectedFailure is not None:
1613
1591
            reason = 'No reason given'
1614
1592
        else:
1615
1593
            reason = e.args[0]
1616
 
        self._suppress_log ()
1617
1594
        addNotApplicable = getattr(result, 'addNotApplicable', None)
1618
1595
        if addNotApplicable is not None:
1619
1596
            result.addNotApplicable(self, reason)
1621
1598
            self._do_skip(result, reason)
1622
1599
 
1623
1600
    @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
1644
1601
    def _do_unsupported_or_skip(self, result, e):
1645
1602
        reason = e.args[0]
1646
 
        self._suppress_log()
1647
1603
        addNotSupported = getattr(result, 'addNotSupported', None)
1648
1604
        if addNotSupported is not None:
1649
1605
            result.addNotSupported(self, reason)
4503
4459
try:
4504
4460
    from subunit import TestProtocolClient
4505
4461
    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
 
 
4516
4462
    class SubUnitBzrRunner(TextTestRunner):
4517
4463
        def run(self, test):
4518
4464
            result = AutoTimingTestResultDecorator(
4519
 
                SubUnitBzrProtocolClient(self.stream))
 
4465
                TestProtocolClient(self.stream))
4520
4466
            test.run(result)
4521
4467
            return result
4522
4468
except ImportError: