CallOptions

This commit is contained in:
lda
2026-08-30 03:39:26 +07:00 Verified
parent 2587b07b4a
commit 282dc5b4e8
8 changed files with 59 additions and 65 deletions
+11 -8
View File
@@ -9,7 +9,7 @@ import unittest
from unittest.mock import Mock, patch
from ipython_demo.app import App
from ipython_demo.models import CallResponse
from ipython_demo.models import CallOptions, CallResponse
class AppTests(unittest.TestCase):
@@ -41,7 +41,7 @@ class AppTests(unittest.TestCase):
payload = json.loads(completed.stdout)
self.assertEqual(len(payload), 2)
self.assertEqual(payload[0]["events"][0]["kind"], "stdout")
self.assertTrue(payload[1]["collapsed"])
self.assertTrue(payload[1]["options"]["collapsed"])
def test_run_code_returns_frontend_facing_call_response(self):
app = App()
@@ -50,17 +50,20 @@ class AppTests(unittest.TestCase):
call = app.run_code(
"print('hello'); 2 + 2",
shell_name="new",
collapsed=True,
options=CallOptions(collapsed=True),
)
self.assertIsInstance(call, CallResponse)
self.assertEqual(call.code, "print('hello'); 2 + 2")
self.assertTrue(call.collapsed)
self.assertTrue(call.options.collapsed)
self.assertEqual(call.result.result, 4)
self.assertEqual([event.kind for event in call.events], [
"stdout",
"execute_result",
])
self.assertEqual(
[event.kind for event in call.events],
[
"stdout",
"execute_result",
],
)
def test_last_reuses_shell_but_each_call_has_new_id(self):
app = App()
+12 -5
View File
@@ -39,7 +39,9 @@ class ShellTests(unittest.TestCase):
def test_init_shell_has_no_seed_escape_hatch(self):
import inspect
self.assertNotIn("seed", inspect.signature(shell_module.Shell.init_shell).parameters)
self.assertNotIn(
"seed", inspect.signature(shell_module.Shell.init_shell).parameters
)
def test_package_import_has_no_experiment_side_effects(self):
env = os.environ.copy()
@@ -66,9 +68,12 @@ class ShellTests(unittest.TestCase):
sequence=4,
)
self.assertEqual(stdout, models_module.CallEvent(
call_id="call-1", sequence=3, kind="stdout", text="hello\n"
))
self.assertEqual(
stdout,
models_module.CallEvent(
call_id="call-1", sequence=3, kind="stdout", text="hello\n"
),
)
self.assertEqual(result.data, {"text/plain": "42"})
def test_run_cell_and_collect_returns_execution_and_events(self):
@@ -159,7 +164,9 @@ class ShellTests(unittest.TestCase):
wrapper.init_shell()
def fail_capture_output(*args, **kwargs):
raise AssertionError("Shell.run_cell must use the shell-local output records")
raise AssertionError(
"Shell.run_cell must use the shell-local output records"
)
with patch.object(
capture,