test.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:pycma 作者: CMA-ES 项目源码 文件源码
def doctest_files(file_list=files_for_doctest, **kwargs):
    """doctest all (listed) files of the `cma` package.

    Details: accepts ``verbose`` and all other keyword arguments that
    `doctest.testfile` would accept, while negative ``verbose`` values
    are passed as 0.
    """
    # print("__name__ is", __name__, sys.modules[__name__])
    # print(__package__)
    if not isinstance(file_list, list) and is_str(file_list):
        file_list = [file_list]
    verbosity_here = kwargs.get('verbose', 0)
    if verbosity_here < 0:
        kwargs['verbose'] = 0
    failures = 0
    for file_ in file_list:
        file_ = file_.strip().strip(os.path.sep)
        if file_.startswith('cma' + os.path.sep):
            file_ = file_[4:]
        if verbosity_here >= 0:
            print('doctesting %s ...' % file_,
                  ' ' * (max(len(_file) for _file in file_list) -
                         len(file_)),
                  end="")  # does not work in Python 2.5
            sys.stdout.flush()
        protected_files = os.listdir('.')
        report = doctest.testfile(file_,
                                  package=__package__,  # 'cma', # sys.modules[__name__],
                                  **kwargs)
        _clean_up('.', _files_written, protected_files)
        failures += report[0]
        if verbosity_here >= 0:
            print(report)
    return failures
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号