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
评论列表
文章目录