OLD | NEW |
| (Empty) |
1 import io | |
2 import os | |
3 import sys | |
4 import difflib | |
5 | |
6 from os import path | |
7 from subprocess import Popen, PIPE | |
8 | |
9 xsltproc = path.join(os.getcwd(), "win32", "bin.msvc", "xsltproc.exe") | |
10 if not path.isfile(xsltproc): | |
11 xsltproc = path.join(os.getcwd(), "win32", "bin.mingw", "xsltproc.exe") | |
12 if not path.isfile(xsltproc): | |
13 raise FileNotFoundError(xsltproc) | |
14 | |
15 def runtests(xsl_dir, xml_dir="."): | |
16 old_dir = os.getcwd() | |
17 os.chdir(xsl_dir) | |
18 | |
19 for xsl_file in os.listdir(): | |
20 if not xsl_file.endswith(".xsl"): | |
21 continue | |
22 xsl_path = "./" + xsl_file | |
23 name = path.splitext(xsl_file)[0] | |
24 | |
25 xml_path = path.join(xml_dir + "/" + name + ".xml") | |
26 if not path.isfile(xml_path): | |
27 continue | |
28 | |
29 args = [ xsltproc, xsl_path, xml_path ] | |
30 p = Popen(args, stdout=PIPE, stderr=PIPE) | |
31 out_path = path.join(xml_dir, name + ".out") | |
32 err_path = path.join(xml_dir, name + ".err") | |
33 out_diff = diff(p.stdout, "<stdout>", name + ".out") | |
34 err_diff = diff(p.stderr, "<stderr>", name + ".err") | |
35 | |
36 if (len(out_diff) or len(err_diff)): | |
37 sys.stdout.writelines(out_diff) | |
38 sys.stdout.writelines(err_diff) | |
39 print() | |
40 | |
41 os.chdir(old_dir) | |
42 | |
43 def diff(got_stream, got_name, expected_path): | |
44 text_stream = io.TextIOWrapper(got_stream, encoding="latin_1") | |
45 got_lines = text_stream.readlines() | |
46 | |
47 if path.isfile(expected_path): | |
48 file = open(expected_path, "r", encoding="latin_1") | |
49 expected_lines = file.readlines() | |
50 else: | |
51 expected_lines = [] | |
52 | |
53 diff = difflib.unified_diff(expected_lines, got_lines, | |
54 fromfile=expected_path, | |
55 tofile=got_name) | |
56 return list(diff) | |
57 | |
58 print("## Running REC tests") | |
59 runtests("tests/REC") | |
60 | |
61 print("## Running general tests") | |
62 runtests("tests/general", "./../docs") | |
63 | |
64 print("## Running exslt common tests") | |
65 runtests("tests/exslt/common") | |
66 | |
67 print("## Running exslt functions tests") | |
68 runtests("tests/exslt/functions") | |
69 | |
70 print("## Running exslt math tests") | |
71 runtests("tests/exslt/math") | |
72 | |
73 print("## Running exslt saxon tests") | |
74 runtests("tests/exslt/saxon") | |
75 | |
76 print("## Running exslt sets tests") | |
77 runtests("tests/exslt/sets") | |
78 | |
79 print("## Running exslt strings tests") | |
80 runtests("tests/exslt/strings") | |
81 | |
82 print("## Running exslt dynamic tests") | |
83 runtests("tests/exslt/dynamic") | |
84 | |
85 print("## Running exslt date tests") | |
86 runtests("tests/exslt/date") | |
87 | |
OLD | NEW |