Skip to content

Commit de37303

Browse files
committed
TST: Update test_as_mpl_selector to accept rotated regions
1 parent 142f080 commit de37303

File tree

3 files changed

+25
-12
lines changed

3 files changed

+25
-12
lines changed

CHANGES.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ New Features
99

1010
- Added the DS9 'boxcircle' point symbol. [#387]
1111

12+
- Support rotation of the ``as_mpl_selector`` widgets for rectangular
13+
and ellipse regions. [#390]
14+
1215
Bug Fixes
1316
---------
1417

regions/shapes/tests/test_ellipse.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,17 @@ def update_mask(reg):
115115
# works with rotated ellipses, the following exception check can
116116
# be removed as well as the ``angle=0 * u.deg`` in the call to
117117
# copy() below.
118-
with pytest.raises(NotImplementedError,
119-
match=('Cannot create matplotlib selector for '
120-
'rotated ellipse.')):
121-
self.reg.as_mpl_selector(ax)
118+
import matplotlib.widgets
119+
if not hasattr(matplotlib.widgets.EllipseSelector, '_rotation'):
120+
with pytest.raises(NotImplementedError,
121+
match=('Cannot create matplotlib selector for rotated ellipse.')):
122+
self.reg.as_mpl_selector(ax)
122123

123-
region = self.reg.copy(angle=0 * u.deg)
124+
angle = 0 * u.deg
125+
else:
126+
angle = self.reg.angle
127+
128+
region = self.reg.copy(angle=angle)
124129

125130
selector = region.as_mpl_selector(ax, callback=update_mask, sync=sync) # noqa
126131

@@ -162,7 +167,7 @@ def update_mask(reg):
162167
assert_allclose(region.center.y, 4)
163168
assert_allclose(region.width, 4)
164169
assert_allclose(region.height, 3)
165-
assert_quantity_allclose(region.angle, 0 * u.deg)
170+
assert_quantity_allclose(region.angle, angle)
166171

167172
assert_equal(mask, 0)
168173

regions/shapes/tests/test_rectangle.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,17 @@ def update_mask(reg):
118118
# this works with rotated rectangles, the following exception
119119
# check can be removed as well as the ``angle=0 * u.deg`` in the
120120
# call to copy() below.
121-
with pytest.raises(NotImplementedError,
122-
match=('Cannot create matplotlib selector for '
123-
'rotated rectangle.')):
124-
self.reg.as_mpl_selector(ax)
121+
import matplotlib.widgets
122+
if not hasattr(matplotlib.widgets.RectangleSelector, '_rotation'):
123+
with pytest.raises(NotImplementedError,
124+
match=('Cannot create matplotlib selector for rotated rectangle.')):
125+
self.reg.as_mpl_selector(ax)
125126

126-
region = self.reg.copy(angle=0 * u.deg)
127+
angle = 0 * u.deg
128+
else:
129+
angle = self.reg.angle
130+
131+
region = self.reg.copy(angle=angle)
127132

128133
selector = region.as_mpl_selector(ax, callback=update_mask, sync=sync) # noqa
129134

@@ -162,7 +167,7 @@ def update_mask(reg):
162167
assert_allclose(region.center.y, 4)
163168
assert_allclose(region.width, 4)
164169
assert_allclose(region.height, 3)
165-
assert_quantity_allclose(region.angle, 0 * u.deg)
170+
assert_quantity_allclose(region.angle, angle)
166171

167172
assert_equal(mask, 0)
168173

0 commit comments

Comments
 (0)