1 | import libxml2 |
---|
2 | from subprocess import * |
---|
3 | import os |
---|
4 | import shutil |
---|
5 | import fnmatch |
---|
6 | import xml.parsers.expat |
---|
7 | from string import * |
---|
8 | |
---|
9 | parabix_home = "/home/linda/workspace/parabix/proto/parabix2/src" |
---|
10 | xmlconf_home = "/home/linda/workspace/parabix/trunk/QA/xmlconf" |
---|
11 | output_home = "/home/linda/workspace/parabix/trunk/QA/testoutput" |
---|
12 | output_files = output_home+"/Files" |
---|
13 | output_messages = output_home+"/Messages" |
---|
14 | program_to_test = "xmlwf" |
---|
15 | edition5_program_to_test = 'markup_stats_5e' |
---|
16 | testcases = [] |
---|
17 | |
---|
18 | subdir_prefix = '' |
---|
19 | |
---|
20 | def load(filename): |
---|
21 | xml_conf = libxml2.createFileParserCtxt(filename) |
---|
22 | xml_conf.replaceEntities(1) |
---|
23 | xml_conf.parseDocument() |
---|
24 | doc = xml_conf.doc() |
---|
25 | return doc |
---|
26 | |
---|
27 | def start_element(name, attrs): |
---|
28 | global subdir_prefix |
---|
29 | if name == 'TESTCASES': |
---|
30 | for a in attrs: |
---|
31 | if a == 'xml:base': |
---|
32 | subdir_prefix = '/'+attrs[a] |
---|
33 | elif name == 'TEST': |
---|
34 | program = program_to_test |
---|
35 | #for a in attrs: |
---|
36 | #if a == 'EDITION': |
---|
37 | #if attrs[a] == '5': |
---|
38 | #program = edition5_program_to_test |
---|
39 | for a in attrs: |
---|
40 | if a == 'RECOMMENDATION': |
---|
41 | if attrs[a] == 'XML1.1': |
---|
42 | return |
---|
43 | for a in attrs: |
---|
44 | if a == 'URI': |
---|
45 | addr = attrs[a].split('/') |
---|
46 | filename = addr[len(addr)-1] |
---|
47 | subdir = attrs[a][:attrs[a].find(filename)] |
---|
48 | do_file(subdir, filename, program_to_test) |
---|
49 | |
---|
50 | def parser(xml_file): |
---|
51 | p = xml.parsers.expat.ParserCreate() |
---|
52 | p.StartElementHandler = start_element |
---|
53 | p.Parse(xml_file, 1) |
---|
54 | |
---|
55 | def do_file(subdir,filename,program): |
---|
56 | global testcases |
---|
57 | fulldir = subdir_prefix + subdir |
---|
58 | exe_f = open(xmlconf_home + fulldir + filename, 'r') |
---|
59 | filedata = exe_f.read() |
---|
60 | if filedata.find('DOCTYPE')==-1: |
---|
61 | encoding = filedata[:2].encode("hex") |
---|
62 | if encoding != '0000' and encoding != 'feff' and encoding != 'fffe' and encoding != '003c' and encoding != '3c00' and encoding != '4c6f': |
---|
63 | testcases.append((fulldir,filename,program)) |
---|
64 | |
---|
65 | |
---|
66 | def run_test(): |
---|
67 | for testcase in testcases: |
---|
68 | print testcase[0] + testcase[1] |
---|
69 | messagedir = output_messages + testcase[0] |
---|
70 | outputdir = output_files + testcase[0] |
---|
71 | if os.path.exists(outputdir)==False: |
---|
72 | os.makedirs(outputdir) |
---|
73 | if os.path.exists(messagedir)==False: |
---|
74 | os.makedirs(messagedir) |
---|
75 | out_f = open(output_files + testcase[0] + testcase[1], 'w') |
---|
76 | mes_f = open(output_messages + testcase[0] + testcase[1], 'w') |
---|
77 | call([parabix_home + '/' + testcase[2], xmlconf_home + testcase[0] + testcase[1]], stderr=mes_f, stdout=out_f, cwd = xmlconf_home + testcase[0]) |
---|
78 | out_f.close() |
---|
79 | mes_f.close() |
---|
80 | |
---|
81 | |
---|
82 | if __name__ == "__main__": |
---|
83 | if os.path.exists(output_home + ".bak" ): |
---|
84 | shutil.rmtree(output_home + ".bak") |
---|
85 | if os.path.exists( output_home ): |
---|
86 | shutil.move(output_home, output_home + ".bak") |
---|
87 | os.mkdir(output_home) |
---|
88 | os.mkdir(output_files) |
---|
89 | os.mkdir(output_messages) |
---|
90 | |
---|
91 | doc = load(xmlconf_home+'/xmlconf.xml') |
---|
92 | parser(str(doc)) |
---|
93 | run_test() |
---|
94 | |
---|
95 | |
---|
96 | |
---|
97 | |
---|
98 | |
---|
99 | |
---|
100 | |
---|
101 | |
---|
102 | |
---|
103 | |
---|
104 | |
---|
105 | |
---|
106 | |
---|
107 | |
---|
108 | |
---|