_test_common.py 文件源码

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

项目:xmlschema 作者: brunato 项目源码 文件源码
def tests_factory(test_function_builder, pathname, label="validation", suffix="xml"):
    tests = {}
    test_num = 0
    for line in fileinput.input(glob.iglob(pathname)):
        line = line.strip()
        if not line or line[0] == '#':
            continue

        test_args = test_line_parser.parse_args(get_test_args(line))
        test_file = os.path.join(os.path.dirname(fileinput.filename()), test_args.filename)
        if not os.path.isfile(test_file) or os.path.splitext(test_file)[1].lower() != '.%s' % suffix:
            continue

        if test_args.inspect:
            schema_class = ObservedXMLSchema
        else:
            schema_class = xmlschema.XMLSchema

        test_func = test_function_builder(test_file, schema_class, test_args.tot_errors, test_args.inspect)
        test_name = os.path.join(os.path.dirname(sys.argv[0]), os.path.relpath(test_file))
        test_num += 1
        class_name = 'Test{0}{1:03}'.format(label.title(), test_num)
        tests[class_name] = type(
            class_name, (XMLSchemaTestCase,),
            {'test_{0}_{1:03}_{2}'.format(label, test_num, test_name): test_func}
        )
    return tests
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号