Skip to content

Commit 2bb2d08

Browse files
cmccandlessBethanyG
authored andcommitted
update bin/test-exercises.py for v3 structure changes
1 parent 513db83 commit 2bb2d08

2 files changed

Lines changed: 66 additions & 1 deletion

File tree

.github/workflows/ci-workflow.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,4 @@ jobs:
7171
# updates needed to tooling
7272
# - name: Check exercises
7373
# run: |
74-
# ./test/check-exercises.py
74+
# ./bin/test-exercises.py

bin/test-exercises.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#!/usr/bin/env python3
2+
3+
import shutil
4+
import subprocess
5+
import sys
6+
import tempfile
7+
from pathlib import Path
8+
9+
from data import Config, ExerciseInfo
10+
11+
# Allow high-performance tests to be skipped
12+
ALLOW_SKIP = ['alphametics', 'largest-series-product']
13+
14+
15+
def check_assignment(exercise: ExerciseInfo) -> int:
16+
# Returns the exit code of the tests
17+
workdir = Path(tempfile.mkdtemp(exercise.slug))
18+
solution_file = exercise.solution_stub.name
19+
try:
20+
test_file_out = workdir / exercise.test_file.name
21+
if exercise.slug in ALLOW_SKIP:
22+
shutil.copyfile(exercise.test_file, test_file_out)
23+
else:
24+
with exercise.test_file.open('r') as src_file:
25+
lines = [line for line in src_file.readlines()
26+
if not line.strip().startswith('@unittest.skip')]
27+
with test_file_out.open('w') as dst_file:
28+
dst_file.writelines(lines)
29+
shutil.copyfile(exercise.exemplar_file, workdir / solution_file)
30+
return subprocess.call([sys.executable, test_file_out])
31+
finally:
32+
shutil.rmtree(workdir)
33+
34+
35+
def main():
36+
config = Config.load()
37+
exercises = config.exercises.all()
38+
if len(sys.argv) >= 2:
39+
# test specific exercises
40+
exercises = [
41+
e for e in exercises if e.slug in sys.argv[1:]
42+
]
43+
44+
failures = []
45+
for exercise in exercises:
46+
print('# ', exercise.slug)
47+
if not exercise.test_file:
48+
print('FAIL: File with test cases not found')
49+
failures.append('{} (FileNotFound)'.format(exercise.slug))
50+
else:
51+
if check_assignment(exercise):
52+
failures.append('{} (TestFailed)'.format(exercise))
53+
print('')
54+
55+
print('TestEnvironment:', sys.executable.capitalize(), '\n\n')
56+
57+
if failures:
58+
print('FAILURES: ', ', '.join(failures))
59+
raise SystemExit(1)
60+
else:
61+
print('SUCCESS!')
62+
63+
64+
if __name__ == '__main__':
65+
main()

0 commit comments

Comments
 (0)