1
0
mirror of https://github.com/deadc0de6/dotdrop.git synced 2026-02-10 03:59:17 +00:00

test launcher

This commit is contained in:
deadc0de6
2023-08-07 23:03:00 +02:00
committed by deadc0de
parent d813a080f5
commit 578611d30f
2 changed files with 44 additions and 17 deletions

View File

@@ -15,12 +15,12 @@ workdir_tmp_exists="no"
# run bash tests # run bash tests
if [ -z "${GITHUB_WORKFLOW}" ]; then if [ -z "${GITHUB_WORKFLOW}" ]; then
## local ## local
tests-ng/tests_launcher.py tests-ng/tests_launcher.py -s
else else
## CI/CD ## CI/CD
# running multiple jobs in parallel sometimes # running multiple jobs in parallel sometimes
# messes with the results on remote servers # messes with the results on remote servers
tests-ng/tests_launcher.py 1 tests-ng/tests_launcher.py -p 1 -n -s
fi fi
# clear workdir # clear workdir

View File

@@ -10,6 +10,7 @@ tests launcher
import os import os
import sys import sys
import subprocess import subprocess
import argparse
from concurrent import futures from concurrent import futures
from halo import Halo from halo import Halo
@@ -61,15 +62,15 @@ def get_tests():
continue continue
tests.append(path) tests.append(path)
break break
tests.sort()
return tests return tests
def main(): def run_tests(max_jobs=None, stop_on_first_err=True, spinner=True):
"""entry point""" """run the tests"""
max_jobs = None # number of processor print(f'max parallel jobs: {max_jobs}')
if len(sys.argv) > 1: print(f'stop on first error: {stop_on_first_err}')
max_jobs = int(sys.argv[1]) print(f'use spinner: {spinner}')
tests = get_tests() tests = get_tests()
logfd = sys.stdout logfd = sys.stdout
@@ -83,7 +84,7 @@ def main():
print() print()
spinner = None spinner = None
if not is_cicd(): if not is_cicd() and spinner:
# no spinner on github actions # no spinner on github actions
spinner = Halo(text='Testing', spinner='bouncingBall') spinner = Halo(text='Testing', spinner='bouncingBall')
spinner.start() spinner.start()
@@ -99,19 +100,30 @@ def main():
ret, reason, name, log = test.result() ret, reason, name, log = test.result()
# pylint: disable=W0703 # pylint: disable=W0703
except Exception as exc: except Exception as exc:
if stop_on_first_err:
ex.shutdown(wait=False)
for job in wait_for:
job.cancel()
print() print()
print(f'test \"{wait_for[test]}\" failed: {exc}') print(f'test \"{wait_for[test]}\" failed: {exc}')
logfd.close() if stop_on_first_err:
return False logfd.close()
return False
if not ret: if not ret:
ex.shutdown(wait=False) if stop_on_first_err:
for job in wait_for: ex.shutdown(wait=False)
job.cancel() for job in wait_for:
job.cancel()
print() print()
print(log) if stop_on_first_err:
print(log)
print(f'test \"{name}\" failed: {reason}') print(f'test \"{name}\" failed: {reason}')
logfd.close() if stop_on_first_err:
return False logfd.close()
return False
else:
if not spinner:
print(f'OK - test \"{name}\" succeeded!')
sys.stdout.write('\n') sys.stdout.write('\n')
if spinner: if spinner:
spinner.stop() spinner.stop()
@@ -121,6 +133,21 @@ def main():
return True return True
def main():
"""entry point"""
parser = argparse.ArgumentParser()
parser.add_argument('-p', '--proc',
type=int)
parser.add_argument('-s', '--stoponerr',
action='store_true')
parser.add_argument('-n', '--nospinner',
action='store_true')
args = parser.parse_args()
return run_tests(max_jobs=args.proc,
stop_on_first_err=args.stoponerr,
spinner=not args.nospinner)
if __name__ == '__main__': if __name__ == '__main__':
if not main(): if not main():
sys.exit(1) sys.exit(1)