Skip to content

Commit 2b888b9

Browse files
committed
Execute reference implementation if reference output doens't exist
1 parent 5f50320 commit 2b888b9

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

test_partdiff.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,37 @@
22
import subprocess
33
import re
44
import util
5+
from pathlib import Path
6+
import os
7+
8+
REFERENCE_IMPLEMENTATION_DIR = Path.cwd() / "reference_implementation"
9+
REFERENCE_IMPLEMENTATION_EXEC = REFERENCE_IMPLEMENTATION_DIR / "partdiff"
10+
11+
12+
def ensure_reference_implementation_exists():
13+
def is_executable():
14+
executable = REFERENCE_IMPLEMENTATION_EXEC
15+
return executable.exists() and os.access(executable, os.X_OK)
16+
17+
if is_executable():
18+
return
19+
subprocess.check_output(["make", "-C", REFERENCE_IMPLEMENTATION_DIR])
20+
assert is_executable()
521

622

723
def get_reference_output(partdiff_params, reference_output_data):
8-
return reference_output_data[partdiff_params]
24+
if partdiff_params in reference_output_data:
25+
return reference_output_data[partdiff_params]
26+
ensure_reference_implementation_exists()
27+
command_line = [REFERENCE_IMPLEMENTATION_EXEC] + list(partdiff_params)
28+
return subprocess.check_output(command_line).decode("utf-8")
929

1030

1131
def get_actual_output(partdiff_params, partdiff_executable, use_valgrind):
1232
command_line = partdiff_executable + list(partdiff_params)
1333
if use_valgrind:
1434
command_line = ["valgrind", "--leak-check=full"] + command_line
15-
actual_output = subprocess.check_output(command_line).decode("utf-8")
16-
return actual_output
35+
return subprocess.check_output(command_line).decode("utf-8")
1736

1837

1938
def test_partdiff_parametrized(pytestconfig, reference_output_data, test_id):

0 commit comments

Comments
 (0)