/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

MergeĀ lp:bzr.

Show diffs side-by-side

added added

removed removed

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