Skip to content

Commit fff9678

Browse files
committed
added a test case for x and y args of LocationEvent
1 parent 8853a3f commit fff9678

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

lib/matplotlib/tests/test_backend_bases.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from matplotlib.backend_bases import FigureCanvasBase
22
from matplotlib.backend_bases import RendererBase
3+
from matplotlib.backend_bases import LocationEvent
34

45
import matplotlib.pyplot as plt
56
import matplotlib.transforms as transforms
@@ -77,3 +78,25 @@ def test_non_gui_warning():
7778
assert len(rec) == 1
7879
assert ('Matplotlib is currently using pdf, which is a non-GUI backend'
7980
in str(rec[0].message))
81+
82+
83+
def test_location_event_position():
84+
# LocationEvent should cast its x and y arguments
85+
# to int unless it is None
86+
fig = plt.figure()
87+
canvas = FigureCanvasBase(fig)
88+
test_positions = [(42, 24), (None, 42), (None, None),
89+
(200, 100.01), (205.75, 2.0)]
90+
for x, y in test_positions:
91+
event = LocationEvent("test_event", canvas, x, y)
92+
if x is None:
93+
assert event.x is None
94+
else:
95+
assert event.x == int(x)
96+
assert isinstance(event.x, int)
97+
if y is None:
98+
assert event.y is None
99+
else:
100+
assert event.y == int(y)
101+
assert isinstance(event.y, int)
102+

0 commit comments

Comments
 (0)