Skip to content

Commit f9545ad

Browse files
committed
TST: Update test_as_mpl_selector to accept rotated regions
1 parent 0cc6e71 commit f9545ad

File tree

4 files changed

+29
-14
lines changed

4 files changed

+29
-14
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 & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from ...tests.helpers import make_simple_wcs
1616
from ..ellipse import EllipsePixelRegion, EllipseSkyRegion
1717
from .test_common import BaseTestPixelRegion, BaseTestSkyRegion
18-
from .utils import HAS_MATPLOTLIB # noqa
18+
from .utils import HAS_MATPLOTLIB, MATPLOTLIB_HAS_ROTATING_SELECTORS # noqa
1919

2020

2121
@pytest.fixture(scope='session', name='wcs')
@@ -115,12 +115,16 @@ 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+
if not MATPLOTLIB_HAS_ROTATING_SELECTORS:
119+
with pytest.raises(NotImplementedError,
120+
match=('Cannot create matplotlib selector for rotated ellipse.')):
121+
self.reg.as_mpl_selector(ax)
122122

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

125129
selector = region.as_mpl_selector(ax, callback=update_mask, sync=sync) # noqa
126130

@@ -162,7 +166,7 @@ def update_mask(reg):
162166
assert_allclose(region.center.y, 4)
163167
assert_allclose(region.width, 4)
164168
assert_allclose(region.height, 3)
165-
assert_quantity_allclose(region.angle, 0 * u.deg)
169+
assert_quantity_allclose(region.angle, angle)
166170

167171
assert_equal(mask, 0)
168172

regions/shapes/tests/test_rectangle.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from ...tests.helpers import make_simple_wcs
1616
from ..rectangle import RectanglePixelRegion, RectangleSkyRegion
1717
from .test_common import BaseTestPixelRegion, BaseTestSkyRegion
18-
from .utils import HAS_MATPLOTLIB # noqa
18+
from .utils import HAS_MATPLOTLIB, MATPLOTLIB_HAS_ROTATING_SELECTORS # noqa
1919

2020

2121
@pytest.fixture(scope='session', name='wcs')
@@ -118,12 +118,16 @@ 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+
if not MATPLOTLIB_HAS_ROTATING_SELECTORS:
122+
with pytest.raises(NotImplementedError,
123+
match=('Cannot create matplotlib selector for rotated rectangle.')):
124+
self.reg.as_mpl_selector(ax)
125125

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

128132
selector = region.as_mpl_selector(ax, callback=update_mask, sync=sync) # noqa
129133

@@ -162,7 +166,7 @@ def update_mask(reg):
162166
assert_allclose(region.center.y, 4)
163167
assert_allclose(region.width, 4)
164168
assert_allclose(region.height, 3)
165-
assert_quantity_allclose(region.angle, 0 * u.deg)
169+
assert_quantity_allclose(region.angle, angle)
166170

167171
assert_equal(mask, 0)
168172

regions/shapes/tests/utils.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
# Licensed under a 3-clause BSD style license - see LICENSE.rst
22

3+
MATPLOTLIB_HAS_ROTATING_SELECTORS = False
34
try:
45
import matplotlib # noqa
56
HAS_MATPLOTLIB = True
7+
import matplotlib.widgets
8+
if hasattr(matplotlib.widgets.EllipseSelector, '_rotation'):
9+
MATPLOTLIB_HAS_ROTATING_SELECTORS = True
610
except ImportError:
711
HAS_MATPLOTLIB = False

0 commit comments

Comments
 (0)