Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit0828170

Browse files
authored
Merge pull request#16887 from anntzer/simpler-event-mock
Shorter event mocking in tests.
2 parents920266f +299f335 commit0828170

File tree

2 files changed

+7
-20
lines changed

2 files changed

+7
-20
lines changed

‎lib/matplotlib/tests/test_axes.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
importio
55
fromitertoolsimportproduct
66
importplatform
7+
fromtypesimportSimpleNamespace
78
try:
89
fromcontextlibimportnullcontext
910
exceptImportError:
@@ -925,17 +926,12 @@ def test_hexbin_empty():
925926

926927
deftest_hexbin_pickable():
927928
# From #1973: Test that picking a hexbin collection works
928-
classFauxMouseEvent:
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-
asserthb.contains(FauxMouseEvent(400,300))[0]
933+
mouse_event=SimpleNamespace(x=400,y=300)
934+
asserthb.contains(mouse_event)[0]
939935

940936

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

‎lib/matplotlib/tests/test_collections.py

Lines 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
importio
52
importplatform
3+
fromtypesimportSimpleNamespace
64

75
importnumpyasnp
86
fromnumpy.testingimportassert_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-
classMouseEvent:
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
assertfound
455446
assert_array_equal(indices['ind'], [0])
456447

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp