Expose app runtime info across adapters
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
import unittest
|
||||
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
from ipython_demo import App, AppInfo
|
||||
from ipython_mcp.app import app as mcp_app
|
||||
from ipython_webapp.app import app as web_app
|
||||
from langchain_demo.ipython_wrapper import get_app_info
|
||||
|
||||
|
||||
class AppInfoTests(unittest.IsolatedAsyncioTestCase):
|
||||
def test_app_info_describes_runtime_and_updates_after_execution(self):
|
||||
app = App()
|
||||
|
||||
before = app.info()
|
||||
self.assertIsInstance(before, AppInfo)
|
||||
self.assertEqual(before.shell_count, 0)
|
||||
self.assertIsNone(before.last_shell)
|
||||
self.assertEqual(before.total_calls, 0)
|
||||
self.assertGreaterEqual(before.uptime_seconds, 0)
|
||||
|
||||
app.run_code("1 + 1", shell_name="info-test")
|
||||
after = app.info()
|
||||
|
||||
self.assertEqual(after.shell_count, 1)
|
||||
self.assertEqual(after.last_shell, "info-test")
|
||||
self.assertEqual(after.total_calls, 1)
|
||||
self.assertGreaterEqual(after.uptime_seconds, before.uptime_seconds)
|
||||
|
||||
def test_web_app_exposes_info(self):
|
||||
response = TestClient(web_app).get("/info")
|
||||
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertIsInstance(response.json()["shell_count"], int)
|
||||
|
||||
async def test_mcp_app_exposes_info_tool(self):
|
||||
tools = await mcp_app.list_tools()
|
||||
|
||||
self.assertIn("get_app_info", {tool.name for tool in tools})
|
||||
|
||||
def test_langchain_exposes_info_tool(self):
|
||||
result = get_app_info.invoke({})
|
||||
|
||||
self.assertIsInstance(result, AppInfo)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user