Skip to content

Commit 1191170

Browse files
authored
Update CI test runner for v3 (#2284)
* - Check for exemplar.py (>=v3), then example.py (<v3) - Use pathlib instead of os.path * remove f-strings for 3.5 compat * Revert "remove f-strings for 3.5 compat" This reverts commit c72e129. * Remove 3.5 from test matrix, add 3.9 * run workflow on main branch too
1 parent 8608b55 commit 1191170

File tree

2 files changed

+21
-16
lines changed

2 files changed

+21
-16
lines changed

.github/workflows/ci-workflow.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ name: Exercises check
55

66
on:
77
push:
8-
branches:
8+
branches:
99
- master
10+
- main
1011
pull_request:
1112

1213
jobs:
@@ -67,7 +68,7 @@ jobs:
6768
needs: housekeeping
6869
strategy:
6970
matrix:
70-
python-version: [3.5, 3.6, 3.7, 3.8]
71+
python-version: [3.6, 3.7, 3.8, 3.9]
7172
steps:
7273
- uses: actions/checkout@v2
7374

test/check-exercises.py

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,54 @@
11
#!/usr/bin/env python3
22

3-
import os
4-
import glob
53
import shutil
64
import subprocess
75
import sys
86
import tempfile
97
import json
8+
from pathlib import Path
109

1110
# Allow high-performance tests to be skipped
1211
ALLOW_SKIP = ['alphametics', 'largest-series-product']
1312

1413

15-
def check_assignment(name, test_file):
14+
def check_assignment(name: str, test_file: Path) -> int:
1615
# Returns the exit code of the tests
17-
workdir = tempfile.mkdtemp(name)
16+
workdir = Path(tempfile.mkdtemp(name))
1817
example_name = name.replace("-", "_")
1918
try:
20-
test_file_out = os.path.join(workdir, os.path.basename(test_file))
19+
test_file_out = workdir / test_file.name
2120
if name in ALLOW_SKIP:
2221
shutil.copyfile(test_file, test_file_out)
2322
else:
24-
with open(test_file, 'r') as src_file:
23+
with test_file.open('r') as src_file:
2524
lines = [line for line in src_file.readlines()
2625
if not line.strip().startswith('@unittest.skip')]
27-
with open(test_file_out, 'w') as dst_file:
26+
with test_file_out.open('w') as dst_file:
2827
dst_file.writelines(lines)
29-
shutil.copyfile(os.path.join(os.path.dirname(test_file), 'example.py'),
30-
os.path.join(workdir, '{}.py'.format(example_name)))
28+
exemplar_file = test_file.with_name('exemplar.py')
29+
if not exemplar_file.is_file():
30+
exemplar_file = exemplar_file.with_name('example.py')
31+
print(exemplar_file)
32+
shutil.copyfile(exemplar_file, workdir / f'{example_name}.py')
3133
return subprocess.call([sys.executable, test_file_out])
3234
finally:
3335
shutil.rmtree(workdir)
3436

3537

3638
def load_config():
39+
config_file = Path('config.json')
3740
try:
38-
with open('./config.json') as json_file:
41+
with config_file.open() as json_file:
3942
data = json.load(json_file)
4043
except IOError:
41-
print('FAIL: config.json file not found')
44+
print(f'FAIL: {config_file} file not found')
4245
raise SystemExit(1)
4346

4447
try:
4548
problems = [entry['slug'] for entry in data['exercises']
4649
if "deprecated" not in entry]
4750
except KeyError:
48-
print('FAIL: config.json has an incorrect format')
51+
print(f'FAIL: {config_file} has an incorrect format')
4952
raise SystemExit(1)
5053

5154
return problems
@@ -60,14 +63,15 @@ def main():
6063
exercises = load_config()
6164

6265
failures = []
66+
exercises_dir = Path('exercises')
6367
for exercise in exercises:
64-
test_file = glob.glob('./exercises/{}/*_test.py'.format(exercise))
68+
test_file = next((exercises_dir / exercise).glob('*_test.py'), None)
6569
print('# ', exercise)
6670
if not test_file:
6771
print('FAIL: File with test cases not found')
6872
failures.append('{} (FileNotFound)'.format(exercise))
6973
else:
70-
if check_assignment(exercise, test_file[0]):
74+
if check_assignment(exercise, test_file):
7175
failures.append('{} (TestFailed)'.format(exercise))
7276
print('')
7377

0 commit comments

Comments
 (0)