~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/TestUtil.py

  • Committer: John Arbash Meinel
  • Date: 2011-05-11 11:35:28 UTC
  • mto: This revision was merged to the branch mainline in revision 5851.
  • Revision ID: john@arbash-meinel.com-20110511113528-qepibuwxicjrbb2h
Break compatibility with python <2.6.

This includes auditing the code for places where we were doing
explicit 'sys.version' checks and removing them as appropriate.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2010 Canonical Ltd
 
1
# Copyright (C) 2005-2011 Canonical Ltd
2
2
#       Author: Robert Collins <robert.collins@canonical.com>
3
3
#
4
4
# This program is free software; you can redistribute it and/or modify
20
20
import logging
21
21
import unittest
22
22
 
 
23
from bzrlib import pyutils
 
24
 
23
25
# Mark this python module as being part of the implementation
24
26
# of unittest: this gives us better tracebacks where the last
25
27
# shown frame is the test code, not our assertXYZ.
27
29
 
28
30
 
29
31
class LogCollector(logging.Handler):
 
32
 
30
33
    def __init__(self):
31
34
        logging.Handler.__init__(self)
32
35
        self.records=[]
 
36
 
33
37
    def emit(self, record):
34
38
        self.records.append(record.getMessage())
35
39
 
58
62
                visitor.visitSuite(test)
59
63
                visitTests(test, visitor)
60
64
            else:
61
 
                print "unvisitable non-unittest.TestCase element %r (%r)" % (test, test.__class__)
 
65
                print "unvisitable non-unittest.TestCase element %r (%r)" % (
 
66
                    test, test.__class__)
62
67
 
63
68
 
64
69
class TestSuite(unittest.TestSuite):
106
111
 
107
112
    def loadTestsFromModuleName(self, name):
108
113
        result = self.suiteClass()
109
 
        module = _load_module_by_name(name)
 
114
        module = pyutils.get_named_object(name)
110
115
 
111
116
        result.addTests(self.loadTestsFromModule(module))
112
117
        return result
179
184
            return self.suiteClass()
180
185
 
181
186
 
182
 
def _load_module_by_name(mod_name):
183
 
    parts = mod_name.split('.')
184
 
    module = __import__(mod_name)
185
 
    del parts[0]
186
 
    # for historical reasons python returns the top-level module even though
187
 
    # it loads the submodule; we need to walk down to get the one we want.
188
 
    while parts:
189
 
        module = getattr(module, parts.pop(0))
190
 
    return module
191
 
 
192
 
 
193
187
class TestVisitor(object):
194
188
    """A visitor for Tests"""
 
189
 
195
190
    def visitSuite(self, aTestSuite):
196
191
        pass
 
192
 
197
193
    def visitCase(self, aTestCase):
198
194
        pass