Files
python/test/check-exercises.py

85 lines
2.5 KiB
Python
Raw Normal View History

#!/usr/bin/env python3
2014-02-28 01:58:51 -07:00
import os
import glob
import shutil
import subprocess
import sys
2014-02-28 01:58:51 -07:00
import tempfile
import json
2014-02-28 01:58:51 -07:00
# Allow high-performance tests to be skipped
ALLOW_SKIP = ['alphametics', 'largest-series-product']
2014-02-28 01:58:51 -07:00
def check_assignment(name, test_file):
2014-02-28 01:58:51 -07:00
# Returns the exit code of the tests
workdir = tempfile.mkdtemp(name)
example_name = name.replace("-", "_")
2014-02-28 01:58:51 -07:00
try:
test_file_out = os.path.join(workdir, os.path.basename(test_file))
if name in ALLOW_SKIP:
shutil.copyfile(test_file, test_file_out)
else:
with open(test_file, 'r') as src_file:
lines = [line for line in src_file.readlines()
if not line.strip().startswith('@unittest.skip')]
with open(test_file_out, 'w') as dst_file:
dst_file.writelines(lines)
2014-02-28 01:58:51 -07:00
shutil.copyfile(os.path.join(os.path.dirname(test_file), 'example.py'),
os.path.join(workdir, '{}.py'.format(example_name)))
return subprocess.call([sys.executable, test_file_out])
2014-02-28 01:58:51 -07:00
finally:
shutil.rmtree(workdir)
def load_config():
try:
with open('./config.json') as json_file:
data = json.load(json_file)
except IOError:
print('FAIL: config.json file not found')
raise SystemExit(1)
try:
problems = [entry['slug'] for entry in data['exercises']
if "deprecated" not in entry]
except KeyError:
print('FAIL: config.json has an incorrect format')
raise SystemExit(1)
Add configuration defaults for nextercism (#493) We will be moving to a tree-shaped track rather than a linear one, as described in the [progression & learning in Exercism](https://github.com/exercism/docs/blob/master/about/conception/progression.md) design document. In order to support this, we need to expand the metadata that exercises are configured with. Note that 'core' exercises are never unlocked by any other exercises. Core exercises appear in the track in the order that they are listed in the array. Non-core exercises depend on only one exercise (unlocked_by: ). At the moment we are assuming that this is a core exercise, but there is no reason that it needs to be. Until now we have operated with a separate deprecated array. These are now being moved into the exercises array with a deprecated field. With these defaults the track in nextercism will have no core exercises, and all the exercises will be available as 'extras' from the start. If you haven't already, now would be a good time to do the following: * add a rough estimate of difficulty to each exercise (scale: 1-10) * add topics to each exercise * choose *at most 20 exercises* to be core exercises (set core: true, and delete the unlocked_by key) * for each exercise that is not core, decide which exercise is the prerequisite (max 1) If possible, leave 3 or 4 simple exercises as (core: false, unlocked_by: null), as this will provide new participants with some exercises that they can tackle even if they have not finished the first core exercise.
2017-07-22 03:17:24 -06:00
return problems
2014-02-28 01:58:51 -07:00
def main():
if len(sys.argv) >= 2:
# test specific exercises
exercises = [exercise.strip('/') for exercise in sys.argv[1:]]
2014-02-28 01:58:51 -07:00
else:
# load exercises from config-file
Add configuration defaults for nextercism (#493) We will be moving to a tree-shaped track rather than a linear one, as described in the [progression & learning in Exercism](https://github.com/exercism/docs/blob/master/about/conception/progression.md) design document. In order to support this, we need to expand the metadata that exercises are configured with. Note that 'core' exercises are never unlocked by any other exercises. Core exercises appear in the track in the order that they are listed in the array. Non-core exercises depend on only one exercise (unlocked_by: ). At the moment we are assuming that this is a core exercise, but there is no reason that it needs to be. Until now we have operated with a separate deprecated array. These are now being moved into the exercises array with a deprecated field. With these defaults the track in nextercism will have no core exercises, and all the exercises will be available as 'extras' from the start. If you haven't already, now would be a good time to do the following: * add a rough estimate of difficulty to each exercise (scale: 1-10) * add topics to each exercise * choose *at most 20 exercises* to be core exercises (set core: true, and delete the unlocked_by key) * for each exercise that is not core, decide which exercise is the prerequisite (max 1) If possible, leave 3 or 4 simple exercises as (core: false, unlocked_by: null), as this will provide new participants with some exercises that they can tackle even if they have not finished the first core exercise.
2017-07-22 03:17:24 -06:00
exercises = load_config()
failures = []
for exercise in exercises:
test_file = glob.glob('./exercises/{}/*_test.py'.format(exercise))
print('# ', exercise)
if not test_file:
print('FAIL: File with test cases not found')
failures.append('{} (FileNotFound)'.format(exercise))
else:
if check_assignment(exercise, test_file[0]):
failures.append('{} (TestFailed)'.format(exercise))
print('')
print('TestEnvironment:', sys.executable.capitalize(), '\n\n')
if failures:
print('FAILURES: ', ', '.join(failures))
raise SystemExit(1)
else:
print('SUCCESS!')
2014-02-28 01:58:51 -07:00
if __name__ == '__main__':
main()