carefully setup shell + rename

This commit is contained in:
lda
2026-08-30 10:25:06 +07:00 Verified
parent 16553b82c7
commit ad716bfb7f
15 changed files with 368 additions and 211 deletions
+3 -3
View File
@@ -4,9 +4,9 @@ import re
import unittest
from unittest.mock import Mock, patch
from ipython_demo import utils
from ipython_demo.app import App
from ipython_demo.models import CallOptions, CallResponse
from ipython_shell import utils
from ipython_shell.app import App
from ipython_shell.models import CallOptions, CallResponse
class AppTests(unittest.TestCase):
+1 -1
View File
@@ -2,7 +2,7 @@ import unittest
from fastapi.testclient import TestClient
from ipython_demo import App, AppInfo
from ipython_shell 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
+1 -1
View File
@@ -4,7 +4,7 @@ from typing import Any
from IPython.core.interactiveshell import InteractiveShell
from ipython_demo.shell import Shell
from ipython_shell.shell import Shell
class TestMyIdeas(unittest.TestCase):
+1 -1
View File
@@ -5,7 +5,7 @@ import unittest
from fastapi.encoders import jsonable_encoder
from fastapi.testclient import TestClient
from ipython_demo import App, Shell
from ipython_shell import App, Shell
from ipython_webapp.app import app as web_app
+34 -3
View File
@@ -8,9 +8,9 @@ from IPython.core.history import HistoryOutput
from IPython.core.interactiveshell import InteractiveShell
from IPython.utils import capture
import ipython_demo.events as events_module
import ipython_demo.models as models_module
import ipython_demo.shell as shell_module
import ipython_shell.events as events_module
import ipython_shell.models as models_module
import ipython_shell.shell as shell_module
PACKAGE_ROOT = Path(__file__).parents[1] / "src" / "ipython_demo"
@@ -123,6 +123,37 @@ class ShellTests(unittest.TestCase):
shell.magics_manager.registry["ExecutionMagics"].default_runner
)
def test_carefully_setup_shell_preserves_formats_and_is_idempotent(self):
from matplotlib.figure import Figure
from matplotlib_inline.backend_inline import flush_figures
shell = InteractiveShell()
shell_module.carefully_setup_shell(shell, formats={"svg"})
shell_module.carefully_setup_shell(shell, formats={"png"})
callbacks = shell.events.callbacks["post_execute"]
self.assertEqual(callbacks.count(flush_figures), 1)
self.assertIn(
Figure,
shell.display_formatter.formatters["image/svg+xml"].type_printers,
)
self.assertIn(
Figure,
shell.display_formatter.formatters["image/png"].type_printers,
)
def test_enable_pylab_lite_reports_clobbered_names(self):
shell = InteractiveShell()
original_np = object()
shell.user_ns["np"] = original_np
clobbered = shell_module.enable_pylab_lite(shell, import_all=False)
self.assertIn("np", clobbered)
self.assertIsNot(shell.user_ns["np"], original_np)
self.assertIs(shell.user_ns["np"], shell.user_ns_hidden["np"])
def test_run_cell_does_not_use_global_capture_output(self):
wrapper = shell_module.Shell("test")
wrapper.init_shell()