diff --git a/lib/matplotlib/backends/backend_webagg_core.py b/lib/matplotlib/backends/backend_webagg_core.py index 93876c999d3c..23ee7a9c9c13 100644 --- a/lib/matplotlib/backends/backend_webagg_core.py +++ b/lib/matplotlib/backends/backend_webagg_core.py @@ -427,6 +427,7 @@ class FigureManagerWebAgg(backend_bases.FigureManagerBase): # This must be None to not break ipympl _toolbar2_class = None ToolbarCls = NavigationToolbar2WebAgg + _window_title = "Matplotlib" def __init__(self, canvas, num): self.web_sockets = set() @@ -444,6 +445,10 @@ def resize(self, w, h, forward=True): def set_window_title(self, title): self._send_event('figure_label', label=title) + self._window_title = title + + def get_window_title(self): + return self._window_title # The following methods are specific to FigureManagerWebAgg diff --git a/lib/matplotlib/tests/test_backend_tk.py b/lib/matplotlib/tests/test_backend_tk.py index 0e753b7041cd..1e6d714b1de9 100644 --- a/lib/matplotlib/tests/test_backend_tk.py +++ b/lib/matplotlib/tests/test_backend_tk.py @@ -158,7 +158,6 @@ def target(): thread.join() -@pytest.mark.backend('TkAgg', skip_on_importerror=True) @pytest.mark.flaky(reruns=3) @_isolated_tk_test(success_count=0) def test_never_update(): @@ -199,7 +198,6 @@ class Toolbar(NavigationToolbar2Tk): print("success") -@pytest.mark.backend('TkAgg', skip_on_importerror=True) @_isolated_tk_test(success_count=1) def test_canvas_focus(): import tkinter as tk diff --git a/lib/matplotlib/tests/test_backends_interactive.py b/lib/matplotlib/tests/test_backends_interactive.py index 325215a807ad..bc0b7c75b922 100644 --- a/lib/matplotlib/tests/test_backends_interactive.py +++ b/lib/matplotlib/tests/test_backends_interactive.py @@ -107,7 +107,8 @@ def _test_interactive_impl(): import io import json import sys - from unittest import TestCase + + import pytest import matplotlib as mpl from matplotlib import pyplot as plt @@ -119,8 +120,6 @@ def _test_interactive_impl(): mpl.rcParams.update(json.loads(sys.argv[1])) backend = plt.rcParams["backend"].lower() - assert_equal = TestCase().assertEqual - assert_raises = TestCase().assertRaises if backend.endswith("agg") and not backend.startswith(("gtk", "web")): # Force interactive framework setup. @@ -135,15 +134,14 @@ def _test_interactive_impl(): # uses no interactive framework). if backend != "tkagg": - with assert_raises(ImportError): + with pytest.raises(ImportError): mpl.use("tkagg", force=True) def check_alt_backend(alt_backend): mpl.use(alt_backend, force=True) fig = plt.figure() - assert_equal( - type(fig.canvas).__module__, - f"matplotlib.backends.backend_{alt_backend}") + assert (type(fig.canvas).__module__ == + f"matplotlib.backends.backend_{alt_backend}") if importlib.util.find_spec("cairocffi"): check_alt_backend(backend[:-3] + "cairo") @@ -151,9 +149,9 @@ def check_alt_backend(alt_backend): mpl.use(backend, force=True) fig, ax = plt.subplots() - assert_equal( - type(fig.canvas).__module__, - f"matplotlib.backends.backend_{backend}") + assert type(fig.canvas).__module__ == f"matplotlib.backends.backend_{backend}" + + assert fig.canvas.manager.get_window_title() == "Figure 1" if mpl.rcParams["toolbar"] == "toolmanager": # test toolbar button icon LA mode see GH issue 25174 @@ -189,7 +187,7 @@ def check_alt_backend(alt_backend): if not backend.startswith('qt5') and sys.platform == 'darwin': # FIXME: This should be enabled everywhere once Qt5 is fixed on macOS # to not resize incorrectly. - assert_equal(result.getvalue(), result_after.getvalue()) + assert result.getvalue() == result_after.getvalue() @pytest.mark.parametrize("env", _get_testable_interactive_backends()) @@ -241,7 +239,7 @@ def _test_thread_impl(): future.result() # Joins the thread; rethrows any exception. plt.close() # backend is responsible for flushing any events here if plt.rcParams["backend"].startswith("WX"): - # TODO: debug why WX needs this only on py3.8 + # TODO: debug why WX needs this only on py >= 3.8 fig.canvas.flush_events()