Synesthesia / tests /test_runtime_core.py
Ashiedu's picture
Sync unified workbench
0490201 verified
import unittest
import os
import json
import time
from runtime.health_check import generate_health_contract, generate_hardware_contract
from runtime.model_manager import ModelManager
from runtime.runtime_loop import RuntimeLoop
class TestRuntimeModules(unittest.TestCase):
def test_health_check(self):
health = generate_health_contract()
self.assertIn("onnx_rocm", health)
self.assertTrue(os.path.exists("runtime/health.json"))
hardware = generate_hardware_contract()
self.assertIn("hardware", hardware)
self.assertTrue(os.path.exists("runtime/hardware.json"))
def test_model_manager(self):
import shutil
if os.path.exists("test_models"):
shutil.rmtree("test_models")
mm = ModelManager(base_path="test_models", quantized_path="test_models/quantized")
# Test empty lists
self.assertEqual(mm.list_models(), [])
self.assertEqual(mm.list_quantized(), [])
# Create a fake model
os.makedirs("test_models/fake_model", exist_ok=True)
with open("test_models/fake_model/model.onnx", "wb") as f:
f.write(os.urandom(2 * 1024 * 1024)) # 2MB
self.assertIn("fake_model", mm.list_models())
self.assertTrue(mm.verify_integrity("fake_model"))
# Test loading
self.assertTrue(mm.load_model("fake_model"))
self.assertTrue(os.path.exists(mm.state_path))
# Cleanup
import shutil
shutil.rmtree("test_models")
def test_runtime_loop(self):
loop = RuntimeLoop()
loop.metrics_path = "runtime/logs/test_metrics.csv"
if os.path.exists(loop.metrics_path):
os.remove(loop.metrics_path)
loop.start_lyria()
time.sleep(0.5)
loop.stop()
self.assertTrue(os.path.exists(loop.metrics_path))
with open(loop.metrics_path, "r") as f:
lines = f.readlines()
self.assertGreater(len(lines), 1) # Header + at least one data line
if __name__ == "__main__":
unittest.main()