Lines Matching +full:test +full:- +full:path
19 VALID_MODULE_NAME = re.compile(r'[_a-z]\w*\.py$', re.IGNORECASE)
23 message = 'Failed to import test module: %s\n%s' % (name, traceback.format_exc())
43 testMethodPrefix = 'test'
49 """Return a suite of all test cases contained in testCaseClass"""
51 raise TypeError("Test cases should not be derived from TestSuite." \
60 """Return a suite of all test cases contained in the given module"""
78 """Return a suite of all test cases given a string specifier.
80 The name may resolve either to a module, a test case class, a
81 test method within a test case class, or a callable object which
94 del parts_copy[-1]
109 name = parts[-1]
115 test = obj()
116 if isinstance(test, suite.TestSuite):
117 return test
118 elif isinstance(test, case.TestCase):
119 return self.suiteClass([test])
121 raise TypeError("calling %s returned %s, not a test" %
122 (obj, test))
124 raise TypeError("don't know how to make test from: %s" % obj)
127 """Return a suite of all test cases found using the given sequence
145 def discover(self, start_dir, pattern='test*.py', top_level_dir=None):
146 """Find and return all test modules from the specified start
147 directory, recursing into subdirectories to find them. Only test files
151 All test modules must be importable from the top level of the project.
155 If a test package name (directory with '__init__.py') matches the
174 top_level_dir = os.path.abspath(top_level_dir)
176 if not top_level_dir in sys.path:
177 # all test modules must be importable from the top level directory
179 # in sys.path to minimise likelihood of conflicts between installed
181 sys.path.insert(0, top_level_dir)
185 if os.path.isdir(os.path.abspath(start_dir)):
186 start_dir = os.path.abspath(start_dir)
188 is_not_importable = not os.path.isfile(os.path.join(start_dir, '__init__.py'))
198 start_dir = os.path.abspath(os.path.dirname((the_module.__file__)))
201 sys.path.remove(top_level_dir)
211 full_path = os.path.abspath(module.__file__)
213 if os.path.basename(full_path).lower().startswith('__init__.py'):
214 return os.path.dirname(os.path.dirname(full_path))
216 # here we have been given a module rather than a package - so
219 return os.path.dirname(full_path)
221 def _get_name_from_path(self, path): argument
222 path = os.path.splitext(os.path.normpath(path))[0]
224 _relpath = os.path.relpath(path, self._top_level_dir)
225 assert not os.path.isabs(_relpath), "Path must be within the project"
226 assert not _relpath.startswith('..'), "Path must be within the project"
228 name = _relpath.replace(os.path.sep, '.')
235 def _match_path(self, path, full_path, pattern): argument
237 return fnmatch(path, pattern)
240 """Used by discovery. Yields test suites it loads."""
243 for path in paths:
244 full_path = os.path.join(start_dir, path)
245 if os.path.isfile(full_path):
246 if not VALID_MODULE_NAME.match(path):
249 if not self._match_path(path, full_path, pattern):
251 # if the test file matches, load it
258 mod_file = os.path.abspath(getattr(module, '__file__', full_path))
259 realpath = os.path.splitext(os.path.realpath(mod_file))[0]
260 fullpath_noext = os.path.splitext(os.path.realpath(full_path))[0]
262 module_dir = os.path.dirname(realpath)
263 mod_name = os.path.splitext(os.path.basename(full_path))[0]
264 expected_dir = os.path.dirname(full_path)
269 elif os.path.isdir(full_path):
270 if not os.path.isfile(os.path.join(full_path, '__init__.py')):
275 if fnmatch(path, pattern):
287 for test in self._find_tests(full_path, pattern):
288 yield test
310 def makeSuite(testCaseClass, prefix='test', sortUsing=cmp,
314 def findTestCases(module, prefix='test', sortUsing=cmp,