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

  • Committer: Richard Wilbur
  • Date: 2016-02-04 19:07:28 UTC
  • mto: This revision was merged to the branch mainline in revision 6618.
  • Revision ID: richard.wilbur@gmail.com-20160204190728-p0zvfii6zase0fw7
Update COPYING.txt from the original http://www.gnu.org/licenses/gpl-2.0.txt  (Only differences were in whitespace.)  Thanks to Petr Stodulka for pointing out the discrepancy.

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
19
20
import logging
20
21
import unittest
21
22
import weakref
22
23
 
23
 
from .. import pyutils
 
24
from bzrlib import pyutils
24
25
 
25
26
# Mark this python module as being part of the implementation
26
27
# of unittest: this gives us better tracebacks where the last
32
33
 
33
34
    def __init__(self):
34
35
        logging.Handler.__init__(self)
35
 
        self.records = []
 
36
        self.records=[]
36
37
 
37
38
    def emit(self, record):
38
39
        self.records.append(record.getMessage())
41
42
def makeCollectingLogger():
42
43
    """I make a logger instance that collects its logs for programmatic analysis
43
44
    -> (logger, collector)"""
44
 
    logger = logging.Logger("collector")
45
 
    handler = LogCollector()
 
45
    logger=logging.Logger("collector")
 
46
    handler=LogCollector()
46
47
    handler.setFormatter(logging.Formatter("%(levelname)s: %(message)s"))
47
48
    logger.addHandler(handler)
48
49
    return logger, handler
51
52
def visitTests(suite, visitor):
52
53
    """A foreign method for visiting the tests in a test suite."""
53
54
    for test in suite._tests:
54
 
        # Abusing types to avoid monkey patching unittest.TestCase.
 
55
        #Abusing types to avoid monkey patching unittest.TestCase.
55
56
        # Maybe that would be better?
56
57
        try:
57
58
            test.visit(visitor)
62
63
                visitor.visitSuite(test)
63
64
                visitTests(test, visitor)
64
65
            else:
65
 
                print("unvisitable non-unittest.TestCase element %r (%r)" % (
66
 
                    test, test.__class__))
 
66
                print "unvisitable non-unittest.TestCase element %r (%r)" % (
 
67
                    test, test.__class__)
67
68
 
68
69
 
69
70
class FailedCollectionCase(unittest.TestCase):
102
103
        self._tests = []
103
104
        stored_count = 0
104
105
        count_stored_tests = getattr(result, "_count_stored_tests", int)
105
 
        from breezy.tests import selftest_debug_flags
 
106
        from bzrlib.tests import selftest_debug_flags
106
107
        notify = "uncollected_cases" in selftest_debug_flags
107
108
        while tests:
108
109
            if result.shouldStop:
154
155
        result.addTests(self.loadTestsFromModule(module))
155
156
        return result
156
157
 
 
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
 
157
195
    def getTestCaseNames(self, test_case_class):
158
196
        test_fn_names = self.test_func_names.get(test_case_class, None)
159
197
        if test_fn_names is not None: