diff --git a/spyder/plugins/ipythonconsole/tests/conftest.py b/spyder/plugins/ipythonconsole/tests/conftest.py index d2842845edc..9ae6f8ba94c 100644 --- a/spyder/plugins/ipythonconsole/tests/conftest.py +++ b/spyder/plugins/ipythonconsole/tests/conftest.py @@ -207,6 +207,7 @@ def get_plugin(name): debugger.on_ipython_console_available() console.on_initialize() console._register() + console.get_widget().matplotlib_status.register_ipythonconsole(console) console.create_new_client( special=special, given_name=given_name, diff --git a/spyder/plugins/ipythonconsole/tests/test_ipythonconsole.py b/spyder/plugins/ipythonconsole/tests/test_ipythonconsole.py index 27c412a3337..801fcc07f41 100644 --- a/spyder/plugins/ipythonconsole/tests/test_ipythonconsole.py +++ b/spyder/plugins/ipythonconsole/tests/test_ipythonconsole.py @@ -21,7 +21,6 @@ # Third party imports from ipykernel._version import __version__ as ipykernel_version -import IPython from IPython.core import release as ipy_release from IPython.core.application import get_ipython_dir from flaky import flaky @@ -1909,18 +1908,61 @@ def test_pdb_comprehension_namespace(ipyconsole, qtbot, tmpdir): assert "_spyderpdb" not in key -@flaky(max_runs=3) +@flaky(max_runs=10) @pytest.mark.auto_backend -def test_restart_intertactive_backend(ipyconsole, qtbot): +def test_restart_interactive_backend(ipyconsole, qtbot): """ - Test that we ask for a restart after switching to a different interactive - backend in preferences. + Test that we ask for a restart or not after switching to different + interactive backends. + + Also, check that we show the right backend in the Matplotlib status widget. """ - main_widget = ipyconsole.get_widget() - qtbot.wait(1000) - main_widget.change_possible_restart_and_mpl_conf('pylab/backend', 'tk') + shell = ipyconsole.get_current_shellwidget() + matplotlib_status = ipyconsole.get_widget().matplotlib_status + + # This is necessary to test no spurious messages are printed to the console + shell.clear_console() + qtbot.waitUntil(lambda: '\nIn [2]: ' == shell._control.toPlainText()) + + # Switch to the tk backend + ipyconsole.set_conf('pylab/backend', 'tk') + assert bool(os.environ.get('BACKEND_REQUIRE_RESTART')) + assert shell.get_matplotlib_backend() == "qt" + assert matplotlib_status.value == "Qt" + + # Switch to the inline backend + os.environ.pop('BACKEND_REQUIRE_RESTART') + ipyconsole.set_conf('pylab/backend', 'inline') + assert not bool(os.environ.get('BACKEND_REQUIRE_RESTART')) + qtbot.waitUntil(lambda: shell.get_matplotlib_backend() == "inline") + assert matplotlib_status.value == "Inline" + + # Switch to the auto backend + ipyconsole.set_conf('pylab/backend', 'auto') + assert not bool(os.environ.get('BACKEND_REQUIRE_RESTART')) + qtbot.waitUntil(lambda: shell.get_matplotlib_backend() == "qt") + assert matplotlib_status.value == "Qt" + + # Switch to the qt backend + ipyconsole.set_conf('pylab/backend', 'qt') + assert not bool(os.environ.get('BACKEND_REQUIRE_RESTART')) + assert matplotlib_status.value == "Qt" + + # Switch to the tk backend again + ipyconsole.set_conf('pylab/backend', 'tk') assert bool(os.environ.get('BACKEND_REQUIRE_RESTART')) + # Check we no spurious messages are shown before the restart below + assert "\nIn [2]: " == shell._control.toPlainText() + + # Restart kernel to check if the new interactive backend is set + ipyconsole.restart_kernel() + qtbot.waitUntil(lambda: shell.spyder_kernel_ready, timeout=SHELL_TIMEOUT) + qtbot.wait(SHELL_TIMEOUT) + qtbot.waitUntil(lambda: shell.get_matplotlib_backend() == "tk") + assert shell.get_mpl_interactive_backend() == "tk" + assert matplotlib_status.value == "Tk" + def test_mpl_conf(ipyconsole, qtbot): """