~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/TestUtil.py

Merge from bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
89
89
        """
90
90
        result = self.suiteClass()
91
91
        for name in names:
92
 
            module = _load_module_by_name(name)
93
 
            result.addTests(self.loadTestsFromModule(module))
 
92
            result.addTests(self.loadTestsFromModuleName(name))
 
93
        return result
 
94
 
 
95
    def loadTestsFromModuleName(self, name):
 
96
        result = self.suiteClass()
 
97
        module = _load_module_by_name(name)
 
98
 
 
99
        result.addTests(self.loadTestsFromModule(module))
94
100
        return result
95
101
 
96
102
    def loadTestsFromModule(self, module):
127
133
    def getTestCaseNames(self, test_case_class):
128
134
        test_fn_names = self.test_func_names.get(test_case_class, None)
129
135
        if test_fn_names is not None:
130
 
            # We already calculate that
 
136
            # We already know them
131
137
            return test_fn_names
132
138
 
133
139
        test_fn_names = unittest.TestLoader.getTestCaseNames(self,
135
141
        self.test_func_names[test_case_class] = test_fn_names
136
142
        return test_fn_names
137
143
 
 
144
 
 
145
class FilteredByModuleTestLoader(TestLoader):
 
146
    """A test loader that import only the needed modules."""
 
147
 
 
148
    def __init__(self, needs_module):
 
149
        """Constructor.
 
150
 
 
151
        :param needs_module: a callable taking a module name as a
 
152
            parameter returing True if the module should be loaded.
 
153
        """
 
154
        TestLoader.__init__(self)
 
155
        self.needs_module = needs_module
 
156
 
 
157
    def loadTestsFromModuleName(self, name):
 
158
        if self.needs_module(name):
 
159
            return TestLoader.loadTestsFromModuleName(self, name)
 
160
        else:
 
161
            return self.suiteClass()
 
162
 
 
163
 
138
164
def _load_module_by_name(mod_name):
139
165
    parts = mod_name.split('.')
140
166
    module = __import__(mod_name)