Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6dcf7cf

Browse files
committed
Add tests for resolving backend name and gui loop
1 parent f9ce8c2 commit 6dcf7cf

File tree

3 files changed

+86
-2
lines changed

3 files changed

+86
-2
lines changed

IPython/core/display_functions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def display(
111111
display_id=None,
112112
raw=False,
113113
clear=False,
114-
**kwargs
114+
**kwargs,
115115
):
116116
"""Display a Python object in all frontends.
117117

IPython/core/tests/test_pylabtools.py

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,3 +268,87 @@ def test_figure_no_canvas():
268268
fig = Figure()
269269
fig.canvas = None
270270
pt.print_figure(fig)
271+
272+
273+
@pytest.mark.parametrize(
274+
"name, expected_gui, expected_backend",
275+
[
276+
# name is gui
277+
("gtk3", "gtk3", "gtk3agg"),
278+
("gtk4", "gtk4", "gtk4agg"),
279+
("headless", "headless", "agg"),
280+
("osx", "osx", "macosx"),
281+
("qt", "qt", "qtagg"),
282+
("qt5", "qt5", "qt5agg"),
283+
("qt6", "qt6", "qt6agg"),
284+
("tk", "tk", "tkagg"),
285+
("wx", "wx", "wxagg"),
286+
# name is backend
287+
("agg", None, "agg"),
288+
("cairo", None, "cairo"),
289+
("pdf", None, "pdf"),
290+
("ps", None, "ps"),
291+
("svg", None, "svg"),
292+
("template", None, "template"),
293+
("gtk3agg", "gtk3", "gtk3agg"),
294+
("gtk3cairo", "gtk3", "gtk3cairo"),
295+
("gtk4agg", "gtk4", "gtk4agg"),
296+
("gtk4cairo", "gtk4", "gtk4cairo"),
297+
("macosx", "osx", "macosx"),
298+
("nbagg", "nbagg", "nbagg"),
299+
("notebook", "nbagg", "notebook"),
300+
("qtagg", "qt", "qtagg"),
301+
("qtcairo", "qt", "qtcairo"),
302+
("qt5agg", "qt5", "qt5agg"),
303+
("qt5cairo", "qt5", "qt5cairo"),
304+
("qt6agg", "qt", "qt6agg"),
305+
("qt6cairo", "qt", "qt6cairo"),
306+
("tkagg", "tk", "tkagg"),
307+
("tkcairo", "tk", "tkcairo"),
308+
("webagg", "webagg", "webagg"),
309+
("wxagg", "wx", "wxagg"),
310+
("wxcairo", "wx", "wxcairo"),
311+
],
312+
)
313+
def test_backend_builtin(name, expected_gui, expected_backend):
314+
# Test correct identification of Matplotlib built-in backends without importing and using them,
315+
# otherwise we would need to ensure all the complex dependencies such as windowing toolkits are
316+
# installed.
317+
318+
mpl_manages_backends = pt._matplotlib_manages_backends()
319+
if not mpl_manages_backends:
320+
# Backends not supported before _matplotlib_manages_backends or supported
321+
# but with different expected_gui or expected_backend.
322+
if (
323+
name.endswith("agg")
324+
or name.endswith("cairo")
325+
or name in ("headless", "macosx", "pdf", "ps", "svg", "template")
326+
):
327+
pytest.skip()
328+
elif name == "qt6":
329+
expected_backend = "qtagg"
330+
elif name == "notebook":
331+
expected_backend, expected_gui = expected_gui, expected_backend
332+
333+
gui, backend = pt.find_gui_and_backend(name)
334+
if not mpl_manages_backends:
335+
gui = gui.lower() if gui else None
336+
backend = backend.lower() if backend else None
337+
assert gui == expected_gui
338+
assert backend == expected_backend
339+
340+
341+
def test_backend_entry_point():
342+
gui, backend = pt.find_gui_and_backend("inline")
343+
assert gui is None
344+
expected_backend = (
345+
"inline"
346+
if pt._matplotlib_manages_backends()
347+
else "module://matplotlib_inline.backend_inline"
348+
)
349+
assert backend == expected_backend
350+
351+
352+
def test_backend_unknown():
353+
with pytest.raises(RuntimeError if pt._matplotlib_manages_backends() else KeyError):
354+
pt.find_gui_and_backend("name-does-not-exist")

IPython/terminal/embed.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ def __call__(
197197
dummy=None,
198198
stack_depth=1,
199199
compile_flags=None,
200-
**kw
200+
**kw,
201201
):
202202
"""Activate the interactive interpreter.
203203

0 commit comments

Comments
 (0)