示例#1
0
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__)
示例#2
0
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
示例#3
0
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
示例#4
0
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__)
示例#5
0
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__)