Skip to content

Commit

Permalink
Testing: Expand test_restart_interactive_backend with more cases
Browse files Browse the repository at this point in the history
- Now we check if we request a restart by switch between different
backends several times.
- We also check that the Matplotlib status widget displays the right
value.
  • Loading branch information
ccordoba12 committed May 4, 2024
1 parent 460b8a7 commit dfdf54f
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 8 deletions.
1 change: 1 addition & 0 deletions spyder/plugins/ipythonconsole/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
58 changes: 50 additions & 8 deletions spyder/plugins/ipythonconsole/tests/test_ipythonconsole.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
"""
Expand Down

0 comments on commit dfdf54f

Please sign in to comment.