-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathe2e_runner.py
108 lines (89 loc) · 2.64 KB
/
e2e_runner.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/usr/bin/env python3.8
"""
E2E/Snapshot testing tool
Test frame3dd binary against all examples
Checks output, files count and content with reference files
"""
import difflib
import os
import shutil
import subprocess
import sys
from contextlib import contextmanager
from pathlib import Path
EXECUTABLE_PATH = "build/frame3dd"
WORKDIR_PATH = ".e2e_workdir"
WORKDIR = Path(WORKDIR_PATH)
@contextmanager
def use_chdir(path):
old_path = os.getcwd()
try:
yield os.chdir(path)
finally:
os.chdir(old_path)
def check_executable():
"""Check if the code is built"""
try:
os.stat(EXECUTABLE_PATH)
except FileNotFoundError:
print(
f"Executable not found at {EXECUTABLE_PATH}. Did you forget to build the code?",
file=sys.stderr,
)
sys.exit(1)
def set_up():
"""Pre-test routines"""
try:
os.mkdir(WORKDIR)
except FileExistsError:
print(
f"Warning! Workdir was not removed from previous run. Cleaning it up now",
file=sys.stderr,
)
tear_down()
os.mkdir(WORKDIR)
os.symlink("../" + EXECUTABLE_PATH, WORKDIR / "frame3dd")
def tear_down():
"""Post-test routines"""
shutil.rmtree(WORKDIR)
def test_case(example_name):
examples = Path("../examples")
process = subprocess.run(
["./frame3dd", "-i", examples / f"{example_name}.3dd", "-o", "out"]
)
assert process.returncode == 0, f"Exit code is non-zero! {process.returncode}"
with open(examples / f"{example_name}.out") as fd:
original_lines = fd.readlines()
with open("out") as fd:
produced_lines = fd.readlines()
diff = difflib.unified_diff(original_lines, produced_lines, n=0)
try:
# Skip junk
next(diff)
next(diff)
while True:
header = next(diff)
orig = next(diff)
actual = next(diff)
# Ignore data changes
if header == "@@ -9 +9 @@\n":
continue
# FIXME Actually check RMS error
if orig.startswith("-R M S"):
continue
# FIXME Actually check Total Mass deviation
if orig.startswith("- Total Mass"):
continue
# FIXME Actually check Mode frequency deviation
if orig.startswith("- MODE"):
continue
raise AssertionError("Regression error:\n" + header + orig + actual)
except StopIteration:
pass
check_executable()
for example_name in ("exA", "exB", "exE"):
set_up()
with use_chdir(WORKDIR):
test_case(example_name)
tear_down()
print("All done")