shared shell registry

This commit is contained in:
lda
2026-08-30 22:49:34 +07:00 Verified
parent 0b87620852
commit 6a8546cb0f
8 changed files with 262 additions and 68 deletions
+8
View File
@@ -49,6 +49,14 @@ class AppTests(unittest.TestCase):
],
)
def test_call_ids_are_readable(self):
app = App()
with contextlib.redirect_stdout(io.StringIO()):
call = app.run_code("1 + 1", shell_name="new")
self.assertRegex(call.call_id, r"^[a-z]+-[a-z]+-[a-z]+-[0-9a-f]{4}$")
def test_last_reuses_shell_but_each_call_has_new_id(self):
app = App()
+24 -1
View File
@@ -1,4 +1,5 @@
import asyncio
import re
import unittest
from ipython_shell.jupyter.app import JupyterApp
@@ -48,6 +49,25 @@ class JupyterShellTests(unittest.IsolatedAsyncioTestCase):
class JupyterAppTests(unittest.IsolatedAsyncioTestCase):
async def test_app_exposes_shared_shell_metadata_api(self):
app = JupyterApp()
try:
created = app.create_shell()
listed = app.list_shells()
last = app.get_last_shell()
selected = app.get_shell(created.name)
info = app.info()
finally:
await app.shutdown()
self.assertEqual(len(listed), 1)
self.assertEqual(created.shell_id, listed[0].shell_id)
self.assertEqual(created.shell_id, last.shell_id)
self.assertEqual(created.shell_id, selected.shell_id)
self.assertEqual(created.execution_count, 0)
self.assertEqual(info.shell_count, 1)
self.assertEqual(info.last_shell, created.name)
async def test_named_shells_have_isolated_namespaces(self):
app = JupyterApp()
try:
@@ -110,7 +130,10 @@ class JupyterAppTests(unittest.IsolatedAsyncioTestCase):
self.assertIsInstance(input_request, InputRequest)
assert isinstance(input_request, InputRequest)
self.assertTrue(input_request.call_id)
self.assertRegex(
input_request.call_id,
re.compile(r"^[a-z]+-[a-z]+-[a-z]+-[0-9a-f]{4}$"),
)
self.assertEqual(input_request.prompt, "name? ")
await app.reply_to_input(input_request.call_id, "Ada")