Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR: Add a test for the Tkinter backend (IPython console) #16370

Merged
merged 4 commits into from
Oct 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions external-deps/spyder-kernels/.gitrepo
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
[subrepo]
remote = https://github.com/spyder-ide/spyder-kernels.git
branch = 2.x
commit = d151e3b4f01a1284487b6183def17161307f8bb5
parent = eb1cd5b7fe9ddb77a1869512c129d89c93484a46
commit = f7888cff5f6280e48076fb8ff1948d335464b6f8
parent = 02498d20fc2731a6f52f110c50d5b07cfc3ede22
method = merge
cmdver = 0.4.3
14 changes: 13 additions & 1 deletion external-deps/spyder-kernels/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
# History of changes

## Version 2.1.1 (2021-09-01)
## Version 2.1.2 (2021-09-28)

### Pull Requests Merged

* [PR 323](https://github.com/spyder-ide/spyder-kernels/pull/323) - PR: Add `ipython_genutils` dependency for testing, by [@ccordoba12](https://github.com/ccordoba12)
* [PR 322](https://github.com/spyder-ide/spyder-kernels/pull/322) - PR: Prevent other libraries to change the breakpoint builtin, by [@ccordoba12](https://github.com/ccordoba12)

In this release 2 pull requests were closed.


----


## Version 2.1.1 (2021-09-01)

### Pull Requests Merged

* [PR 318](https://github.com/spyder-ide/spyder-kernels/pull/318) - PR: Avoid runfile to be shadowed by other packages, by [@ccordoba12](https://github.com/ccordoba12)
Expand Down
2 changes: 2 additions & 0 deletions external-deps/spyder-kernels/requirements/tests.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ pytest-cov
scipy
xarray
pillow
# Remove when Anaconda updates to a newer ipykernel
ipython_genutils
8 changes: 6 additions & 2 deletions external-deps/spyder-kernels/spyder_kernels/console/kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,7 @@ def _set_mpl_backend(self, backend, pylab=False):
"""
import traceback
from IPython.core.getipython import get_ipython
import matplotlib

generic_error = (
"\n" + "="*73 + "\n"
Expand All @@ -730,12 +731,16 @@ def _set_mpl_backend(self, backend, pylab=False):

error = None
try:
# This prevents Matplotlib to automatically set the backend, which
# overrides our own mechanism.
matplotlib.rcParams['backend'] = 'Agg'

# Set the backend
get_ipython().run_line_magic(magic, backend)
except RuntimeError as err:
# This catches errors generated by ipykernel when
# trying to set a backend. See issue 5541
if "GUI eventloops" in str(err):
import matplotlib
previous_backend = matplotlib.get_backend()
if not backend in previous_backend.lower():
# Only inform about an error if the user selected backend
Expand All @@ -748,7 +753,6 @@ def _set_mpl_backend(self, backend, pylab=False):
"in use.\n\n"
"Your backend will be {0}".format(previous_backend)
)
del matplotlib
# This covers other RuntimeError's
else:
error = generic_error.format(traceback.format_exc())
Expand Down
9 changes: 8 additions & 1 deletion external-deps/spyder-kernels/spyder_kernels/utils/mpl.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,16 @@
}


# Inline backend
if is_module_installed('matplotlib_inline'):
inline_backend = 'module://matplotlib_inline.backend_inline'
else:
inline_backend = 'module://ipykernel.pylab.backend_inline'


# Mapping of matlotlib backends options to Spyder
MPL_BACKENDS_TO_SPYDER = {
'module://ipykernel.pylab.backend_inline': 0,
inline_backend: 0,
'Qt5Agg': 2,
'Qt4Agg': 3,
'MacOSX': 4,
Expand Down
1 change: 1 addition & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ markers =
no_xvfb
external_interpreter
test_environment_interpreter
tk_backend: Test the Tkinter Matplotlib backend
29 changes: 26 additions & 3 deletions spyder/plugins/ipythonconsole/tests/test_ipythonconsole.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,11 @@ def __getattr__(self, attr):
if auto_backend:
CONF.set('ipython_console', 'pylab/backend', 1)

# Use the Tkinter backend if requested
tk_backend = request.node.get_closest_marker('tk_backend')
if tk_backend:
CONF.set('ipython_console', 'pylab/backend', 8)

# Start a Pylab client if requested
pylab_client = request.node.get_closest_marker('pylab_client')
is_pylab = True if pylab_client else False
Expand Down Expand Up @@ -296,21 +301,39 @@ def test_get_calltips(ipyconsole, qtbot, function, signature, documentation):
@flaky(max_runs=3)
@pytest.mark.auto_backend
def test_auto_backend(ipyconsole, qtbot):
"""Test that the automatic backend is working correctly."""
"""Test that the automatic backend was set correctly."""
# Wait until the window is fully up
shell = ipyconsole.get_current_shellwidget()
qtbot.waitUntil(lambda: shell._prompt_html is not None,
timeout=SHELL_TIMEOUT)

with qtbot.waitSignal(shell.executed):
shell.execute("import matplotlib; matplotlib.get_backend()")
shell.execute("ip = get_ipython(); ip.kernel.eventloop")

# Assert there are no errors in the console and we set the right
# backend.
control = ipyconsole.get_focus_widget()
assert 'NOTE' not in control.toPlainText()
assert 'Error' not in control.toPlainText()
assert 'Qt5Agg' in control.toPlainText()
assert 'loop_qt5' in control.toPlainText()


@flaky(max_runs=3)
@pytest.mark.tk_backend
@pytest.mark.skipif(os.name == 'nt', reason="Fails on Windows")
def test_tk_backend(ipyconsole, qtbot):
"""Test that the Tkinter backend was set correctly."""
# Wait until the window is fully up
shell = ipyconsole.get_current_shellwidget()
qtbot.waitUntil(lambda: shell._prompt_html is not None,
timeout=SHELL_TIMEOUT)

with qtbot.waitSignal(shell.executed):
shell.execute("ip = get_ipython(); ip.kernel.eventloop")

# Assert we set the right backend in the kernel.
control = ipyconsole.get_focus_widget()
assert 'loop_tk' in control.toPlainText()


@flaky(max_runs=3)
Expand Down