Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0828170

Browse filesBrowse files
authored
Merge pull request #16887 from anntzer/simpler-event-mock
Shorter event mocking in tests.
2 parents 920266f + 299f335 commit 0828170
Copy full SHA for 0828170

File tree

Expand file treeCollapse file tree

2 files changed

+7
-20
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+7
-20
lines changed

‎lib/matplotlib/tests/test_axes.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_axes.py
+3-7Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import io
55
from itertools import product
66
import platform
7+
from types import SimpleNamespace
78
try:
89
from contextlib import nullcontext
910
except ImportError:
@@ -925,17 +926,12 @@ def test_hexbin_empty():
925926

926927
def test_hexbin_pickable():
927928
# From #1973: Test that picking a hexbin collection works
928-
class FauxMouseEvent:
929-
def __init__(self, x, y):
930-
self.x = x
931-
self.y = y
932-
933929
fig, ax = plt.subplots()
934930
data = (np.arange(200) / 200).reshape((2, 100))
935931
x, y = data
936932
hb = ax.hexbin(x, y, extent=[.1, .3, .6, .7], picker=-1)
937-
938-
assert hb.contains(FauxMouseEvent(400, 300))[0]
933+
mouse_event = SimpleNamespace(x=400, y=300)
934+
assert hb.contains(mouse_event)[0]
939935

940936

941937
@image_comparison(['hexbin_log.png'], style='mpl20')

‎lib/matplotlib/tests/test_collections.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_collections.py
+4-13Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
"""
2-
Tests specific to the collections module.
3-
"""
41
import io
52
import platform
3+
from types import SimpleNamespace
64

75
import numpy as np
86
from numpy.testing import assert_array_equal, assert_array_almost_equal
@@ -430,8 +428,7 @@ def get_transform(self):
430428
fig, ax = plt.subplots()
431429

432430
xy = [(0, 0)]
433-
# Unit square has a half-diagonal of `1 / sqrt(2)`, so `pi * r**2`
434-
# equals...
431+
# Unit square has a half-diagonal of `1/sqrt(2)`, so `pi * r**2` equals...
435432
circle_areas = [np.pi / 2]
436433
squares = SquareCollection(sizes=circle_areas, offsets=xy,
437434
transOffset=ax.transData)
@@ -443,14 +440,8 @@ def test_picking():
443440
fig, ax = plt.subplots()
444441
col = ax.scatter([0], [0], [1000], picker=True)
445442
fig.savefig(io.BytesIO(), dpi=fig.dpi)
446-
447-
class MouseEvent:
448-
pass
449-
event = MouseEvent()
450-
event.x = 325
451-
event.y = 240
452-
453-
found, indices = col.contains(event)
443+
mouse_event = SimpleNamespace(x=325, y=240)
444+
found, indices = col.contains(mouse_event)
454445
assert found
455446
assert_array_equal(indices['ind'], [0])
456447

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.