import importlib
import hashlib
import json
from pathlib import Path
import sys
import unittest

root='/opt/contextra/' if 'image' in sys.argv[1] else '/source/'
for name in ['app.metadata_publisher','app.channel_publisher','app.metadata_runtime','app.det_result_path']:
    f=Path(importlib.import_module(name).__file__);assert str(f).startswith(root)
    print(name,str(f),hashlib.sha256(f.read_bytes()).hexdigest())
suite=unittest.TestSuite()
for pattern in ['test_metadata_publisher.py','test_publisher_metrics.py','test_metadata_demo_limits.py','test_tracking_disabled.py','test_channel_publisher.py','test_det_result_path.py']:
    suite.addTests(unittest.defaultTestLoader.discover('/tests',pattern=pattern))
r=unittest.TextTestRunner(verbosity=2).run(suite)
v=dict(success=r.wasSuccessful(),tests=r.testsRun,errors=len(r.errors),failures=len(r.failures))
Path('/evidence',sys.argv[1]+'.json').write_text(json.dumps(v));print(json.dumps(v))
raise SystemExit(0 if r.wasSuccessful() else 1)
