Reducing code duplication in bin/run_test.py and bin/run_tests.py

This commit is contained in:
Yannick Jadoul
2017-09-06 15:07:58 +02:00
parent 60ed370002
commit a7c7a58407
2 changed files with 35 additions and 49 deletions
+20 -17
View File
@@ -1,23 +1,10 @@
#!/usr/bin/python
from __future__ import print_function
import os, sys, subprocess, shutil, json, argparse
import os, sys, subprocess, shutil, json
from glob import glob
def main():
parser = argparse.ArgumentParser()
parser.add_argument("test_project_dir")
args = parser.parse_args()
test_project = os.path.abspath(args.test_project_dir)
# move cwd to the project root
os.chdir(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
if not os.path.exists(test_project):
print('No test project not found.', file=sys.stderr)
exit(2)
def single_run(test_project):
# load project settings into environment
env_file = os.path.join(test_project, 'environment.json')
project_env = {}
@@ -40,6 +27,22 @@ def main():
# clean up
shutil.rmtree('wheelhouse')
print('Project built successfully.')
if __name__ == '__main__':
import argparse
main()
parser = argparse.ArgumentParser()
parser.add_argument("test_project_dir")
args = parser.parse_args()
project_path = os.path.abspath(args.test_project_dir)
# move cwd to the project root
os.chdir(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
if not os.path.exists(project_path):
print('No test project not found.', file=sys.stderr)
exit(2)
single_run(project_path)
print('Project built successfully.')
+15 -32
View File
@@ -4,44 +4,27 @@ from __future__ import print_function
import os, sys, subprocess, shutil, json
from glob import glob
# move cwd to the project root
os.chdir(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from . import run_test
### run the unit tests
if __name__ == '__main__':
# move cwd to the project root
os.chdir(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
subprocess.check_call(['python', '-m', 'pytest', 'unit_test'])
### run the unit tests
### run the integration tests
subprocess.check_call(['python', '-m', 'pytest', 'unit_test'])
test_projects = glob('test/??_*')
### run the integration tests
if len(test_projects) == 0:
print('No test projects found. Aborting.', file=sys.stderr)
exit(2)
test_projects = glob('test/??_*')
print('Testing projects:', test_projects)
if len(test_projects) == 0:
print('No test projects found. Aborting.', file=sys.stderr)
exit(2)
for project_path in test_projects:
# load project settings into environment
env_file = os.path.join(project_path, 'environment.json')
project_env = {}
if os.path.exists(env_file):
with open(env_file) as f:
project_env = json.load(f)
print('Testing projects:', test_projects)
# run the build
env = os.environ.copy()
project_env = {str(k): str(v) for k, v in project_env.items()} # unicode not allowed in env
env.update(project_env)
print('Building %s with environment %s' % (project_path, project_env))
subprocess.check_call(['cibuildwheel', project_path], env=env)
wheels = glob('wheelhouse/*.whl')
print('%s built successfully. %i wheels built.' % (project_path, len(wheels)))
for project_path in test_projects:
run_test.single_run(project_path)
# check some wheels were actually built
assert len(wheels) >= 4
# clean up
shutil.rmtree('wheelhouse')
print('%d projects built successfully.' % len(test_projects))
print('%d projects built successfully.' % len(test_projects))