Files
Enelix-EMS/services/netplan-v4/run_tests.py
T

22 lines
1.3 KiB
Python

"""Run against the exact server working tree; no live data or credentials used."""
from pathlib import Path
import hashlib,json,os,sys,unittest
ROOT=Path(__file__).resolve().parent
DEPS=Path('/home/agent/services/qa/netplan-v4-candidate-20261001/python-dependencies')
if DEPS.exists():sys.path.insert(0,str(DEPS))
sys.path.insert(0,str(ROOT))
if __name__=='__main__':
import numpy,scipy,fastapi,httpx
versions={'python':sys.version.split()[0],**{m.__name__:m.__version__ for m in (numpy,scipy,fastapi,httpx)}}
print('Runtime',json.dumps(versions),flush=True)
reports=Path(os.getenv('NETPLAN_V4_TEST_REPORT_DIR',str(ROOT)))
reports.mkdir(parents=True,exist_ok=True)
suite=unittest.defaultTestLoader.discover(str(ROOT/'tests'))
with (reports/'TEST_RESULTS.txt').open('w') as output:
output.write('Actual server/target tests; synthetic data only.\n'+json.dumps(versions)+'\n\n')
result=unittest.TextTestRunner(stream=output,verbosity=2).run(suite)
print((reports/'TEST_RESULTS.txt').read_text())
hashes={str(p.relative_to(ROOT)):hashlib.sha256(p.read_bytes()).hexdigest() for p in sorted(ROOT.rglob('*.py')) if '__pycache__' not in p.parts}
(reports/'TESTED_SOURCE_HASHES.json').write_text(json.dumps(hashes,indent=2)+'\n')
raise SystemExit(0 if result.wasSuccessful() else 1)