c3lf-system-3/core/integration_tests/main.py
jedi 7bb9c11cc0
Some checks failed
Test / test (push) Failing after 1m5s
stash
2024-12-05 04:11:14 +01:00

61 lines
1.9 KiB
Python

import time
import os
import signal
import re
import sys
import subprocess
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
def run():
while True:
newpid = os.fork()
if newpid == 0:
import coverage
cov = coverage.Coverage()
cov.load()
cov.start()
signal.signal(signal.SIGINT, signal.default_int_handler)
try:
from server import main
main()
except KeyboardInterrupt:
pass
cov.stop()
cov.save()
os._exit(0)
else:
return newpid
if __name__ == '__main__':
pid = run()
time.sleep(2)
script_dir = os.path.dirname(os.path.abspath(__file__))
pattern = re.compile(r'^test_.*\.(sh|py)$')
dotpy = re.compile(r'^.*\.py$')
dotsh = re.compile(r'^.*\.sh$')
matching_files = [
filename for filename in os.listdir(script_dir)
if os.path.isfile(os.path.join(script_dir, filename)) and pattern.match(filename)
]
total = 0
failed = 0
for file in matching_files:
file_path = os.path.join(script_dir, file)
if dotpy.match(file):
result = subprocess.run(['python3', file_path], capture_output=True, text=True)
elif dotsh.match(file):
result = subprocess.run(['bash', file_path], capture_output=True, text=True)
else:
result = subprocess.run(['bash', '-c', file_path], capture_output=True, text=True)
print('{} returned {}'.format(file, result.returncode))
if result.returncode != 0:
print(result.stderr, result.stdout)
failed += 1
total += 1
time.sleep(1)
os.kill(pid, signal.SIGINT)
print(f'{total - failed} out of {total} tests succeeded, {failed} failed')
os._exit(0 if failed == 0 else 1)