carefully setup shell + rename
This commit is contained in:
+34
-3
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user