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