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

Skip to content

Commit f52efc1

Browse files
committed
Finish rectangle handle tests and add ellipse test with key modifiers
1 parent 600c0c7 commit f52efc1

File tree

1 file changed

+57
-6
lines changed

1 file changed

+57
-6
lines changed

lib/matplotlib/tests/test_widgets.py

Lines changed: 57 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
def get_ax():
1717
fig, ax = plt.subplots(1, 1)
1818
ax.plot([0, 200], [0, 200])
19+
ax.set_aspect(1.0)
1920
ax.figure.canvas.draw()
2021
return ax
2122

@@ -105,9 +106,54 @@ def test_rectangle_selector():
105106
check_rectangle(rectprops=dict(fill=True))
106107

107108

108-
def test_rectangle_modifiers():
109-
# TODO: add tests for center, square, center, shift+drag
110-
pass
109+
def test_ellipse():
110+
"""For ellipse, test out the key modifiers"""
111+
ax = get_ax()
112+
113+
def onselect(epress, erelease):
114+
pass
115+
116+
tool = widgets.EllipseSelector(ax, onselect=onselect,
117+
maxdist=10)
118+
tool.extents = (100, 150, 100, 150)
119+
120+
# drag the rectangle
121+
event = get_event(ax, xdata=10, ydata=10, button=1,
122+
key='alt')
123+
tool.press(event)
124+
event = get_event(ax, xdata=30, ydata=30, button=1)
125+
tool.onmove(event)
126+
tool.release(event)
127+
assert tool.extents == (120, 170, 120, 170)
128+
129+
# create from center
130+
event = get_event(ax, xdata=100, ydata=100, button=1,
131+
key='control')
132+
tool.press(event)
133+
event = get_event(ax, xdata=125, ydata=125, button=1)
134+
tool.onmove(event)
135+
tool.release(event)
136+
assert tool.extents == (75, 125, 75, 125)
137+
138+
# create a square
139+
event = get_event(ax, xdata=10, ydata=10, button=1,
140+
key='shift')
141+
tool.press(event)
142+
event = get_event(ax, xdata=35, ydata=30, button=1)
143+
tool.onmove(event)
144+
tool.release(event)
145+
extents = [int(e) for e in tool.extents]
146+
assert extents == [10, 35, 10, 35]
147+
148+
# create a square from center
149+
event = get_event(ax, xdata=100, ydata=100, button=1,
150+
key='ctrl+shift')
151+
tool.press(event)
152+
event = get_event(ax, xdata=125, ydata=130, button=1)
153+
tool.onmove(event)
154+
tool.release(event)
155+
extents = [int(e) for e in tool.extents]
156+
assert extents == [70, 130, 70, 130], extents
111157

112158

113159
def test_rectangle_handles():
@@ -118,9 +164,6 @@ def onselect(epress, erelease):
118164

119165
tool = widgets.RectangleSelector(ax, onselect=onselect,
120166
maxdist=10)
121-
event = get_event(ax, xdata=100, ydata=100, button=1)
122-
tool.press(event)
123-
124167
tool.extents = (100, 150, 100, 150)
125168

126169
assert tool.corners == (
@@ -138,6 +181,14 @@ def onselect(epress, erelease):
138181
tool.release(event)
139182
assert tool.extents == (120, 150, 120, 150)
140183

184+
# grab the center and move it
185+
event = get_event(ax, xdata=132, ydata=132)
186+
tool.press(event)
187+
event = get_event(ax, xdata=120, ydata=120)
188+
tool.onmove(event)
189+
tool.release(event)
190+
assert tool.extents == (108, 138, 108, 138)
191+
141192
# create a new rectangle
142193
event = get_event(ax, xdata=10, ydata=10)
143194
tool.press(event)

0 commit comments

Comments
 (0)