Files
laya/tests/test_context_manager.py
Kartik ChilkotiandGitHub 1fd60b937a feat(runtime): add context manager support to Agent and Router for deterministic resource cleanup (#150)
* feat(agent): add context manager support for automatic memory release

* feat(router): add context manager support for resource cleanup

* test(runtime): add unit tests for agent and router context managers
2026-09-23 12:36:05 +05:30

20 lines
578 B
Python

import unittest
from laya.router import Router
class MockAgent:
def __init__(self, name):
self.name = name
class ContextManagerTests(unittest.TestCase):
def test_router_context_manager_cleanup(self):
with Router(max_loaded=2) as r:
r.attach("english", MockAgent("en"))
r.attach("multilingual", MockAgent("multi"))
self.assertEqual(len(r.loaded), 2)
# After exiting context block, all models must be unloaded
self.assertEqual(len(r.loaded), 0)
if __name__ == "__main__":
unittest.main()