当前位置: 首页>>代码示例>>Python>>正文


Python TestUtils.get_tests_directory方法代码示例

本文整理汇总了Python中TestUtils.get_tests_directory方法的典型用法代码示例。如果您正苦于以下问题:Python TestUtils.get_tests_directory方法的具体用法?Python TestUtils.get_tests_directory怎么用?Python TestUtils.get_tests_directory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TestUtils的用法示例。


在下文中一共展示了TestUtils.get_tests_directory方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_scripts

# 需要导入模块: import TestUtils [as 别名]
# 或者: from TestUtils import get_tests_directory [as 别名]
def test_scripts():
    '''yield list of scripts to test.'''
    # the current directory
    current_dir = os.getcwd()

    # directory location of tests
    testing_dir = TestUtils.get_tests_directory()

    # directory location of scripts
    scripts_dir = os.path.join(os.path.dirname(testing_dir), "CGAT", "scripts")

    # directories with tests (correspond to script names and
    # hence end in .py)
    test_dirs = glob.glob(os.path.join(testing_dir, "*.py"))

    # the config file
    config_file = os.path.join(testing_dir, "_test_scripts.yaml")

    if os.path.exists(config_file):
        config = yaml.load(open(config_file))
        if config is not None:
            if "restrict" in config and config["restrict"]:
                values = config["restrict"]
                if "glob" in values:
                    test_dirs = os.path.join(testing_dir, values["glob"])
                if "manifest" in values:
                    # take scripts defined in the MANIFEST.in file
                    test_dirs = [x for x in open("MANIFEST.in")
                                 if x.startswith("include CGAT/scripts") and
                                 x.endswith(".py\n")]
                    test_dirs = [re.sub("include\s*CGAT/scripts/", "tests/",
                                        x[:-1]) for x in test_dirs]

                if "regex" in values:
                    rx = re.compile(values["regex"])
                    test_dirs = list(filter(rx.search, test_dirs))

    # ignore those which don't exist as tests (files added through MANIFEST.in,
    # such as version.py, __init__.py, ...
    test_dirs = [x for x in test_dirs if os.path.exists(x)]

    # ignore non-directories
    test_dirs = [x for x in test_dirs if os.path.isdir(x)]

    test_dirs.sort()

    # restrict tests run according to chunk parameters
    starting_test_number = os.getenv('CGAT_TASK_ID', None)
    test_increment = os.getenv('CGAT_TASK_STEPSIZE', None)

    try:
        starting_test_number, test_increment = \
            (int(starting_test_number) - 1,
             int(test_increment))
        test_dirs = test_dirs[starting_test_number:
                              starting_test_number + test_increment]
    except TypeError:
        pass

    for test_script in test_dirs:

        script_name = os.path.basename(test_script)

        check_main.description = os.path.join(script_name, "def_main")
        yield (check_main,
               os.path.abspath(os.path.join(scripts_dir, script_name)))

        fn = '%s/tests.yaml' % test_script
        if not os.path.exists(fn):
            continue

        script_tests = yaml.load(open(fn))

        for test, values in sorted(list(script_tests.items())):
            check_script.description = os.path.join(script_name, test)
            if "skip_python" in values:
                versions = [x.strip() for x in
                            str(values["skip_python"]).split(",")]
                versions = [x for x in versions
                            if PYTHON_VERSION.startswith(x)]
                if len(versions) > 0:
                    continue
            if "skip_travis" in values and TRAVIS:
                continue
            if "skip_jenkins" in values and JENKINS:
                continue
 
            # deal with scripts in subdirectories. These are prefixed
            # by a "<subdir>_" for example: optic_compare_projects.py
            # is optic/compare_procjets.py
            if "_" in script_name:
                parts = script_name.split("_")
                if os.path.exists(os.path.join(
                        "scripts", parts[0], "_".join(parts[1:]))):
                    script_name = os.path.join(parts[0], "_".join(parts[1:]))

            yield(check_script,
                  test,
                  os.path.abspath(os.path.join(scripts_dir, script_name)),
                  values.get('stdin', None),
#.........这里部分代码省略.........
开发者ID:CGATOxford,项目名称:cgat,代码行数:103,代码来源:test_scripts.py


注:本文中的TestUtils.get_tests_directory方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。