def absmodpath(module): #{{{ if isinstance(module, basestring): return _amp_str(module) elif isfilemodule(module): p = op.abspath(module.__file__) if ispackage(module): p = op.dirname(p) return absmodpath(p) elif ismodule(module): return module.__name__ raise TypeError("Cannot determine module path of %s object" %module.__class__.__name__)
def _ts_gen(suite, regex, filenames): #{{{ if not isinstance(regex, _REType): raise TypeError("%s object is not a compiled regular expression" %regex.__class__.__name__) topdir = suite if ispackage(suite): topdir = op.dirname(suite.__file__) for dir, subdir, files in os.walk(topdir): for d in subdir: path = op.join(topdir, d) if hasinit(path) and regex.match(d): yield (path if filenames else absmodpath(path)) break
def _tm_gen(suite, regex, filenames): #{{{ if not isinstance(regex, _REType): raise TypeError("%s object is not a compiled regular expression" %regex.__class__.__name__) topdir = suite if ispackage(suite): topdir = op.dirname(suite.__file__) for dir, subdir, files in os.walk(topdir): for f in files: name, ext = op.splitext(f) if ext == '.py' and regex.match(name): path = op.join(topdir, f) yield (path if filenames else absmodpath(path)) break
def alltestnames(suite, regex=None, filenames=False): #{{{ if not regex: regex = _DefaultModNameRegex if ispackage(suite) or (isinstance(suite, basestring) and op.isdir(suite)): return _atn_gen(suite, regex, filenames) raise TypeError('Cannot walk through sub packages/modules of %s object' %suite.__class__.__name__)
def alltestobjects(suite, regex=None, filenames=False): #{{{ if not regex: regex = _DefaultModNameRegex if ispackage(suite) or (isinstance(suite, basestring) and op.isdir(suite)): return _ato_gen(suite, regex, filenames) raise TypeError("%s object is not a package" %suite.__class__.__name__)