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

Skip to content
Open
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
1 change: 1 addition & 0 deletions lib/matplotlib/backends/backend_gtk3.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
# :raises ValueError: If module/version is already loaded, already
# required, or unavailable.
gi.require_version("Gtk", "3.0")
gi.require_version("Gdk", "3.0")
except ValueError as e:
# in this case we want to re-raise as ImportError so the
# auto-backend selection logic correctly skips.
Expand Down
2 changes: 2 additions & 0 deletions lib/matplotlib/backends/backend_gtk4.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
# :raises ValueError: If module/version is already loaded, already
# required, or unavailable.
gi.require_version("Gtk", "4.0")
gi.require_version("Gdk", "4.0")
gi.require_version("GdkPixbuf", "2.0")
except ValueError as e:
# in this case we want to re-raise as ImportError so the
# auto-backend selection logic correctly skips.
Expand Down
45 changes: 0 additions & 45 deletions lib/matplotlib/tests/test_backend_gtk3.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,51 +5,6 @@
from unittest import mock


@pytest.mark.backend("gtk3agg", skip_on_importerror=True)
def test_correct_key():
pytest.xfail("test_widget_send_event is not triggering key_press_event")

from gi.repository import Gdk, Gtk # type: ignore[import]
fig = plt.figure()
buf = []

def send(event):
for key, mod in [
(Gdk.KEY_a, Gdk.ModifierType.SHIFT_MASK),
(Gdk.KEY_a, 0),
(Gdk.KEY_a, Gdk.ModifierType.CONTROL_MASK),
(Gdk.KEY_agrave, 0),
(Gdk.KEY_Control_L, Gdk.ModifierType.MOD1_MASK),
(Gdk.KEY_Alt_L, Gdk.ModifierType.CONTROL_MASK),
(Gdk.KEY_agrave,
Gdk.ModifierType.CONTROL_MASK
| Gdk.ModifierType.MOD1_MASK
| Gdk.ModifierType.MOD4_MASK),
(0xfd16, 0), # KEY_3270_Play.
(Gdk.KEY_BackSpace, 0),
(Gdk.KEY_BackSpace, Gdk.ModifierType.CONTROL_MASK),
]:
# This is not actually really the right API: it depends on the
# actual keymap (e.g. on Azerty, shift+agrave -> 0).
Gtk.test_widget_send_key(fig.canvas, key, mod)

def receive(event):
buf.append(event.key)
if buf == [
"A", "a", "ctrl+a",
"\N{LATIN SMALL LETTER A WITH GRAVE}",
"alt+control", "ctrl+alt",
"ctrl+alt+super+\N{LATIN SMALL LETTER A WITH GRAVE}",
# (No entry for KEY_3270_Play.)
"backspace", "ctrl+backspace",
]:
plt.close(fig)

fig.canvas.mpl_connect("draw_event", send)
fig.canvas.mpl_connect("key_press_event", receive)
plt.show()


@pytest.mark.backend("gtk3agg", skip_on_importerror=True)
def test_save_figure_return():
from gi.repository import Gtk
Expand Down
59 changes: 45 additions & 14 deletions lib/matplotlib/tests/test_getattr.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
from importlib import import_module
from pkgutil import walk_packages
import sys
import warnings

import matplotlib
import pytest

import matplotlib
from matplotlib.testing import is_ci_environment, subprocess_run_helper

# Get the names of all matplotlib submodules,
# except for the unit tests and private modules.
module_names = [
m.name
for m in walk_packages(
path=matplotlib.__path__, prefix=f'{matplotlib.__name__}.'
)
if not m.name.startswith(__package__)
and not any(x.startswith('_') for x in m.name.split('.'))
]
module_names = []
backend_module_names = []
for m in walk_packages(path=matplotlib.__path__, prefix=f'{matplotlib.__name__}.'):
if m.name.startswith(__package__):
continue
if any(x.startswith('_') for x in m.name.split('.')):
continue
if 'backends.backend_' in m.name:
backend_module_names.append(m.name)
else:
module_names.append(m.name)


@pytest.mark.parametrize('module_name', module_names)
@pytest.mark.filterwarnings('ignore::DeprecationWarning')
@pytest.mark.filterwarnings('ignore::ImportWarning')
def test_getattr(module_name):
def _test_getattr(module_name, use_pytest=True):
"""
Test that __getattr__ methods raise AttributeError for unknown keys.
See #20822, #20855.
Expand All @@ -28,8 +32,35 @@ def test_getattr(module_name):
module = import_module(module_name)
except (ImportError, RuntimeError, OSError) as e:
# Skip modules that cannot be imported due to missing dependencies
pytest.skip(f'Cannot import {module_name} due to {e}')
if use_pytest:
pytest.skip(f'Cannot import {module_name} due to {e}')
else:
print(f'SKIP: Cannot import {module_name} due to {e}')
return

key = 'THIS_SYMBOL_SHOULD_NOT_EXIST'
if hasattr(module, key):
delattr(module, key)


@pytest.mark.parametrize('module_name', module_names)
@pytest.mark.filterwarnings('ignore::DeprecationWarning')
@pytest.mark.filterwarnings('ignore::ImportWarning')
def test_getattr(module_name):
_test_getattr(module_name)


def _test_module_getattr():
warnings.filterwarnings('ignore', category=DeprecationWarning)
warnings.filterwarnings('ignore', category=ImportWarning)
module_name = sys.argv[1]
_test_getattr(module_name, use_pytest=False)


@pytest.mark.parametrize('module_name', backend_module_names)
def test_backend_getattr(module_name):
proc = subprocess_run_helper(_test_module_getattr, module_name,
timeout=120 if is_ci_environment() else 20)
if 'SKIP: ' in proc.stdout:
pytest.skip(proc.stdout.removeprefix('SKIP: '))
print(proc.stdout)
Loading