Lines Matching +full:module +full:- +full:path +full:- +full:tests
18 # we would need to avoid loading the same tests multiple times
20 VALID_MODULE_NAME = re.compile(r'[_a-z]\w*\.py$', re.IGNORECASE)
39 message = 'Failed to import test module: %s\n%s' % (
60 def _jython_aware_splitext(path): argument
61 if path.lower().endswith('$py.class'):
62 return path[:-9]
63 return os.path.splitext(path)[0]
68 This class is responsible for loading tests according to various criteria
81 # avoid infinite re-entrancy.
98 def loadTestsFromModule(self, module, *args, pattern=None, **kws): argument
99 """Return a suite of all test cases contained in the given module"""
110 # required `module` argument.
120 tests = []
121 for name in dir(module):
122 obj = getattr(module, name)
124 tests.append(self.loadTestsFromTestCase(obj))
126 load_tests = getattr(module, 'load_tests', None)
127 tests = self.suiteClass(tests)
130 return load_tests(self, tests, pattern)
133 module.__name__, e, self.suiteClass)
136 return tests
138 def loadTestsFromName(self, name, module=None): argument
141 The name may resolve either to a module, a test case class, a
145 The method optionally resolves the names relative to a given module.
149 if module is None:
154 module = __import__(module_name)
166 obj = module
178 # ImportError - it is more informative.
197 name = parts[-1]
199 # static methods follow a different path
216 def loadTestsFromNames(self, names, module=None): argument
220 suites = [self.loadTestsFromName(name, module) for name in names]
245 tests found within them. Only test files that match the pattern will
254 this exists then it will be called with (loader, tests, pattern) unless
256 invocation, in which case the package module object is not scanned for
257 tests - this ensures that when a package uses discover to further
258 discover child tests that infinite recursion does not happen.
261 load_tests is responsible for loading all tests in the package.
268 order even on filesystems with non-alphabetical ordering like ext3/4.
278 top_level_dir = os.path.abspath(top_level_dir)
280 if not top_level_dir in sys.path:
283 # in sys.path to minimise likelihood of conflicts between installed
285 sys.path.insert(0, top_level_dir)
289 if os.path.isdir(os.path.abspath(start_dir)):
290 start_dir = os.path.abspath(start_dir)
292 is_not_importable = not os.path.isfile(os.path.join(start_dir, '__init__.py'))
294 # support for discovery from dotted module names
303 start_dir = os.path.abspath(
304 os.path.dirname((the_module.__file__)))
307 # builtin module
309 'as dotted module names') from None
317 sys.path.remove(top_level_dir)
322 tests = list(self._find_tests(start_dir, pattern))
323 return self.suiteClass(tests)
326 module = sys.modules[module_name]
327 full_path = os.path.abspath(module.__file__)
329 if os.path.basename(full_path).lower().startswith('__init__.py'):
330 return os.path.dirname(os.path.dirname(full_path))
332 # here we have been given a module rather than a package - so
333 # all we can do is search the *same* directory the module is in
335 return os.path.dirname(full_path)
337 def _get_name_from_path(self, path): argument
338 if path == self._top_level_dir:
340 path = _jython_aware_splitext(os.path.normpath(path))
342 _relpath = os.path.relpath(path, self._top_level_dir)
343 assert not os.path.isabs(_relpath), "Path must be within the project"
344 assert not _relpath.startswith('..'), "Path must be within the project"
346 name = _relpath.replace(os.path.sep, '.')
353 def _match_path(self, path, full_path, pattern): argument
355 return fnmatch(path, pattern)
366 tests, should_recurse = self._find_test_path(start_dir, pattern)
367 if tests is not None:
368 yield tests
375 for path in paths:
376 full_path = os.path.join(start_dir, path)
377 tests, should_recurse = self._find_test_path(full_path, pattern)
378 if tests is not None:
379 yield tests
392 Loads tests from a single file, or a directories' __init__.py when
397 basename = os.path.basename(full_path)
398 if os.path.isfile(full_path):
407 module = self._get_module_from_name(name)
416 mod_file = os.path.abspath(
417 getattr(module, '__file__', full_path))
419 os.path.realpath(mod_file))
421 os.path.realpath(full_path))
423 module_dir = os.path.dirname(realpath)
425 os.path.basename(full_path))
426 expected_dir = os.path.dirname(full_path)
427 msg = ("%r module incorrectly imported from %r. Expected "
428 "%r. Is this module globally installed?")
431 return self.loadTestsFromModule(module, pattern=pattern), False
432 elif os.path.isdir(full_path):
433 if not os.path.isfile(os.path.join(full_path, '__init__.py')):
437 tests = None
453 tests = self.loadTestsFromModule(package, pattern=pattern)
455 # loadTestsFromModule(package) has loaded tests for us.
456 return tests, False
457 return tests, True
499 def findTestCases(module, prefix='test', sortUsing=util.three_way_cmp, argument
508 module)