|
1 | 1 | import tempfile
|
2 | 2 | import subprocess
|
3 |
| -import os |
4 | 3 | import xml.etree.ElementTree as xmlElementTree
|
5 | 4 | from typing import Optional
|
6 |
| - |
7 |
| -STDOUT_DEV = "con" if os.name == "nt" else "/dev/stdout" |
| 5 | +from os.path import join as path_join |
8 | 6 |
|
9 | 7 | __all__ = ["TestlibChecker"]
|
10 | 8 |
|
@@ -32,27 +30,31 @@ def __init__(self, checker_path: str):
|
32 | 30 | self.checker_path = checker_path
|
33 | 31 |
|
34 | 32 | def __call__(self, outs: str, ans: str, ins: str):
|
35 |
| - with tempfile.NamedTemporaryFile( |
36 |
| - 'w') as inf, tempfile.NamedTemporaryFile( |
37 |
| - 'w') as outf, tempfile.NamedTemporaryFile('w') as ansf: |
| 33 | + with tempfile.NamedTemporaryFile('w') as inf, \ |
| 34 | + tempfile.NamedTemporaryFile('w') as outf, \ |
| 35 | + tempfile.NamedTemporaryFile('w') as ansf, \ |
| 36 | + tempfile.TemporaryDirectory() as checker_output_dir: |
38 | 37 | inf.write(ins)
|
39 | 38 | outf.write(outs)
|
40 | 39 | ansf.write(ans)
|
41 | 40 | inf.flush()
|
42 | 41 | outf.flush()
|
43 | 42 | ansf.flush()
|
| 43 | + checker_output_file = path_join(checker_output_dir, |
| 44 | + 'checker_output.xml') |
| 45 | + |
44 | 46 | result = subprocess.run((self.checker_path, inf.name, outf.name,
|
45 |
| - ansf.name, STDOUT_DEV, '-appes'), |
| 47 | + ansf.name, checker_output_file, '-appes'), |
46 | 48 | stdout=subprocess.PIPE,
|
47 | 49 | stderr=subprocess.PIPE,
|
48 | 50 | text=True,
|
49 | 51 | check=False)
|
50 | 52 | if result.stderr.strip() != 'See file to check exit message':
|
51 | 53 | raise ValueError("Invalid output from checker: " +
|
52 | 54 | result.stderr)
|
53 |
| - checker_output = result.stdout |
54 | 55 |
|
55 |
| - result_element = xmlElementTree.fromstring(checker_output) |
| 56 | + result_element = xmlElementTree.parse( |
| 57 | + checker_output_file).getroot() |
56 | 58 | if result_element.tag != 'result':
|
57 | 59 | raise ValueError("Invalid output from checker")
|
58 | 60 | result_text = result_element.text
|
|
0 commit comments