mirror of
https://github.com/deadc0de6/dotdrop.git
synced 2026-02-14 18:12:26 +00:00
linting
This commit is contained in:
@@ -15,7 +15,6 @@ from concurrent import futures
|
|||||||
from halo import Halo
|
from halo import Halo
|
||||||
|
|
||||||
|
|
||||||
LOG_FILE = '/tmp/dotdrop-tests_launcher.log'
|
|
||||||
GITHUB_ENV = 'GITHUB_WORKFLOW'
|
GITHUB_ENV = 'GITHUB_WORKFLOW'
|
||||||
|
|
||||||
|
|
||||||
@@ -66,37 +65,28 @@ def get_tests():
|
|||||||
return tests
|
return tests
|
||||||
|
|
||||||
|
|
||||||
def run_tests(max_jobs=None, stop_on_first_err=True, spinner=True):
|
def run_tests(max_jobs=None, stop_on_first_err=True, with_spinner=True):
|
||||||
"""run the tests"""
|
"""run the tests"""
|
||||||
|
# pylint: disable=R0914,R0912
|
||||||
print(f'max parallel jobs: {max_jobs}')
|
print(f'max parallel jobs: {max_jobs}')
|
||||||
print(f'stop on first error: {stop_on_first_err}')
|
print(f'stop on first error: {stop_on_first_err}')
|
||||||
print(f'use spinner: {spinner}')
|
print(f'use spinner: {with_spinner}')
|
||||||
print(f'log file {LOG_FILE}')
|
|
||||||
tests = get_tests()
|
tests = get_tests()
|
||||||
|
print(f'running {len(tests)} test(s)\n')
|
||||||
logfd = sys.stdout
|
|
||||||
if not is_cicd():
|
|
||||||
# pylint: disable=R1732
|
|
||||||
logfd = open(LOG_FILE, 'w', encoding='utf-8')
|
|
||||||
if max_jobs:
|
|
||||||
logfd.write(f'run tests with {max_jobs} parallel job(s)\n')
|
|
||||||
logfd.write(f'running {len(tests)} test(s)\n')
|
|
||||||
logfd.flush()
|
|
||||||
|
|
||||||
print()
|
print()
|
||||||
|
|
||||||
failed = 0
|
failed = 0
|
||||||
success = 0
|
success = 0
|
||||||
spinner = None
|
spinner = None
|
||||||
if not is_cicd() and spinner:
|
if not is_cicd() and with_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()
|
||||||
with futures.ThreadPoolExecutor(max_workers=max_jobs) as ex:
|
with futures.ThreadPoolExecutor(max_workers=max_jobs) as ex:
|
||||||
wait_for = {}
|
wait_for = {}
|
||||||
for test in tests:
|
for test in tests:
|
||||||
j = ex.submit(run_test, logfd, test)
|
j = ex.submit(run_test, sys.stdout, test)
|
||||||
wait_for[j] = test
|
wait_for[j] = test
|
||||||
logfd.flush()
|
|
||||||
|
|
||||||
for test in futures.as_completed(wait_for.keys()):
|
for test in futures.as_completed(wait_for.keys()):
|
||||||
try:
|
try:
|
||||||
@@ -111,7 +101,6 @@ def run_tests(max_jobs=None, stop_on_first_err=True, spinner=True):
|
|||||||
for job in wait_for:
|
for job in wait_for:
|
||||||
job.cancel()
|
job.cancel()
|
||||||
if stop_on_first_err:
|
if stop_on_first_err:
|
||||||
logfd.close()
|
|
||||||
return False
|
return False
|
||||||
if not ret:
|
if not ret:
|
||||||
failed += 1
|
failed += 1
|
||||||
@@ -123,7 +112,6 @@ def run_tests(max_jobs=None, stop_on_first_err=True, spinner=True):
|
|||||||
ex.shutdown(wait=False)
|
ex.shutdown(wait=False)
|
||||||
for job in wait_for:
|
for job in wait_for:
|
||||||
job.cancel()
|
job.cancel()
|
||||||
logfd.close()
|
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
success += 1
|
success += 1
|
||||||
@@ -133,12 +121,9 @@ def run_tests(max_jobs=None, stop_on_first_err=True, spinner=True):
|
|||||||
if spinner:
|
if spinner:
|
||||||
spinner.stop()
|
spinner.stop()
|
||||||
print()
|
print()
|
||||||
logfd.write(f'done - ran {len(tests)} test(s)\n')
|
print(f'done - ran {len(tests)} test(s)\n')
|
||||||
if not stop_on_first_err:
|
if not stop_on_first_err:
|
||||||
print(f'{failed}/{failed+success} failed tests')
|
print(f'{failed}/{failed+success} failed tests')
|
||||||
logfd.write(f'{failed}/{failed+success} failed tests\n')
|
|
||||||
logfd.close()
|
|
||||||
print(f'log file {LOG_FILE}')
|
|
||||||
return failed < 1
|
return failed < 1
|
||||||
|
|
||||||
|
|
||||||
@@ -154,7 +139,7 @@ def main():
|
|||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
return run_tests(max_jobs=args.proc,
|
return run_tests(max_jobs=args.proc,
|
||||||
stop_on_first_err=args.stoponerr,
|
stop_on_first_err=args.stoponerr,
|
||||||
spinner=not args.nospinner)
|
with_spinner=not args.nospinner)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|||||||
Reference in New Issue
Block a user