52 lines
2.7 KiB
Python
52 lines
2.7 KiB
Python
"""Execute regression tests and write a machine-readable result."""
|
|
import argparse
|
|
import contextlib
|
|
import io
|
|
import json
|
|
from pathlib import Path
|
|
import time
|
|
import unittest
|
|
|
|
from .common import BASE, _BUNDLE
|
|
|
|
|
|
def main(argv=None):
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
parser.add_argument('--live', action='store_true', help='Also run fixed arithmetic probes in running WhatsApp Desktop')
|
|
parser.add_argument('--capabilities', action='store_true', help='Also run fixed Desktop capability checks (implies --live)')
|
|
parser.add_argument('--pid', type=int, help='Desktop host PID for live checks')
|
|
parser.add_argument('--output', type=Path, default=BASE / 'analysis/whatsapp-suite/results.json')
|
|
args = parser.parse_args(argv)
|
|
if args.pid is not None and not (args.live or args.capabilities):
|
|
parser.error('--pid requires --live or --capabilities')
|
|
started = time.monotonic()
|
|
if _BUNDLE:
|
|
from . import _regression
|
|
tests = unittest.defaultTestLoader.loadTestsFromModule(_regression)
|
|
else:
|
|
tests = unittest.defaultTestLoader.discover(str(BASE / 'tests'), pattern='test_whatsapp_*.py')
|
|
result = unittest.TextTestRunner(verbosity=2).run(tests)
|
|
report = {
|
|
'passed': result.wasSuccessful() and result.testsRun > 0,
|
|
'offline': {'tests': result.testsRun, 'failures': len(result.failures),
|
|
'errors': len(result.errors), 'skipped': len(result.skipped),
|
|
'failure_details': [{'test': str(test), 'detail': detail} for test, detail in result.failures + result.errors],
|
|
'skip_details': [{'test': str(test), 'reason': reason} for test, reason in result.skipped]},
|
|
'live': {'status': 'not_requested'},
|
|
}
|
|
if args.live or args.capabilities:
|
|
from .live import run_math
|
|
# Keep complete live probe data in the JSON report, with a compact console summary.
|
|
with contextlib.redirect_stdout(io.StringIO()):
|
|
try:
|
|
report['live'] = run_math(args.pid, 'all' if args.capabilities else 'math')
|
|
except Exception as error:
|
|
report['live'] = {'passed': False, 'error': str(error)}
|
|
report['passed'] = report['passed'] and report['live'].get('passed', False)
|
|
report['duration_seconds'] = round(time.monotonic() - started, 3)
|
|
args.output.parent.mkdir(parents=True, exist_ok=True)
|
|
args.output.write_text(json.dumps(report, ensure_ascii=False, indent=2) + '\n', encoding='utf-8')
|
|
print(json.dumps({'passed': report['passed'], 'tests': result.testsRun,
|
|
'skipped': len(result.skipped), 'report': str(args.output)}))
|
|
return 0 if report['passed'] else 1
|