/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 breezy/tests/TestUtil.py

  • Committer: Breezy landing bot
  • Author(s): Colin Watson
  • Date: 2020-11-16 21:47:08 UTC
  • mfrom: (7521.1.1 remove-lp-workaround)
  • Revision ID: breezy.the.bot@gmail.com-20201116214708-jos209mgxi41oy15
Remove breezy.git workaround for bazaar.launchpad.net.

Merged from https://code.launchpad.net/~cjwatson/brz/remove-lp-workaround/+merge/393710

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
17
#
18
18
 
19
 
import sys
20
19
import logging
21
20
import unittest
22
21
import weakref
23
22
 
24
 
from bzrlib import pyutils
 
23
from .. import pyutils
25
24
 
26
25
# Mark this python module as being part of the implementation
27
26
# of unittest: this gives us better tracebacks where the last
33
32
 
34
33
    def __init__(self):
35
34
        logging.Handler.__init__(self)
36
 
        self.records=[]
 
35
        self.records = []
37
36
 
38
37
    def emit(self, record):
39
38
        self.records.append(record.getMessage())
42
41
def makeCollectingLogger():
43
42
    """I make a logger instance that collects its logs for programmatic analysis
44
43
    -> (logger, collector)"""
45
 
    logger=logging.Logger("collector")
46
 
    handler=LogCollector()
 
44
    logger = logging.Logger("collector")
 
45
    handler = LogCollector()
47
46
    handler.setFormatter(logging.Formatter("%(levelname)s: %(message)s"))
48
47
    logger.addHandler(handler)
49
48
    return logger, handler
52
51
def visitTests(suite, visitor):
53
52
    """A foreign method for visiting the tests in a test suite."""
54
53
    for test in suite._tests:
55
 
        #Abusing types to avoid monkey patching unittest.TestCase.
 
54
        # Abusing types to avoid monkey patching unittest.TestCase.
56
55
        # Maybe that would be better?
57
56
        try:
58
57
            test.visit(visitor)
63
62
                visitor.visitSuite(test)
64
63
                visitTests(test, visitor)
65
64
            else:
66
 
                print "unvisitable non-unittest.TestCase element %r (%r)" % (
67
 
                    test, test.__class__)
 
65
                print("unvisitable non-unittest.TestCase element %r (%r)" % (
 
66
                    test, test.__class__))
68
67
 
69
68
 
70
69
class FailedCollectionCase(unittest.TestCase):
103
102
        self._tests = []
104
103
        stored_count = 0
105
104
        count_stored_tests = getattr(result, "_count_stored_tests", int)
106
 
        from bzrlib.tests import selftest_debug_flags
 
105
        from breezy.tests import selftest_debug_flags
107
106
        notify = "uncollected_cases" in selftest_debug_flags
108
107
        while tests:
109
108
            if result.shouldStop:
155
154
        result.addTests(self.loadTestsFromModule(module))
156
155
        return result
157
156
 
158
 
    def loadTestsFromModule(self, module):
159
 
        """Load tests from a module object.
160
 
 
161
 
        This extension of the python test loader looks for an attribute
162
 
        load_tests in the module object, and if not found falls back to the
163
 
        regular python loadTestsFromModule.
164
 
 
165
 
        If a load_tests attribute is found, it is called and the result is
166
 
        returned.
167
 
 
168
 
        load_tests should be defined like so:
169
 
        >>> def load_tests(standard_tests, module, loader):
170
 
        >>>    pass
171
 
 
172
 
        standard_tests is the tests found by the stock TestLoader in the
173
 
        module, module and loader are the module and loader instances.
174
 
 
175
 
        For instance, to run every test twice, you might do:
176
 
        >>> def load_tests(standard_tests, module, loader):
177
 
        >>>     result = loader.suiteClass()
178
 
        >>>     for test in iter_suite_tests(standard_tests):
179
 
        >>>         result.addTests([test, test])
180
 
        >>>     return result
181
 
        """
182
 
        if sys.version_info < (2, 7):
183
 
            basic_tests = super(TestLoader, self).loadTestsFromModule(module)
184
 
        else:
185
 
            # GZ 2010-07-19: Python 2.7 unittest also uses load_tests but with
186
 
            #                a different and incompatible signature
187
 
            basic_tests = super(TestLoader, self).loadTestsFromModule(module,
188
 
                use_load_tests=False)
189
 
        load_tests = getattr(module, "load_tests", None)
190
 
        if load_tests is not None:
191
 
            return load_tests(basic_tests, module, self)
192
 
        else:
193
 
            return basic_tests
194
 
 
195
157
    def getTestCaseNames(self, test_case_class):
196
158
        test_fn_names = self.test_func_names.get(test_case_class, None)
197
159
        if test_fn_names is not None: