Skip to content

Commit

Permalink
TST: Update test_as_mpl_selector to accept rotated regions
Browse files Browse the repository at this point in the history
  • Loading branch information
dhomeier committed Jul 29, 2021
1 parent 0cc6e71 commit f9545ad
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 14 deletions.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ New Features

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

- Support rotation of the ``as_mpl_selector`` widgets for rectangular
and ellipse regions. [#390]

Bug Fixes
---------

Expand Down
18 changes: 11 additions & 7 deletions regions/shapes/tests/test_ellipse.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from ...tests.helpers import make_simple_wcs
from ..ellipse import EllipsePixelRegion, EllipseSkyRegion
from .test_common import BaseTestPixelRegion, BaseTestSkyRegion
from .utils import HAS_MATPLOTLIB # noqa
from .utils import HAS_MATPLOTLIB, MATPLOTLIB_HAS_ROTATING_SELECTORS # noqa


@pytest.fixture(scope='session', name='wcs')
Expand Down Expand Up @@ -115,12 +115,16 @@ def update_mask(reg):
# works with rotated ellipses, the following exception check can
# be removed as well as the ``angle=0 * u.deg`` in the call to
# copy() below.
with pytest.raises(NotImplementedError,
match=('Cannot create matplotlib selector for '
'rotated ellipse.')):
self.reg.as_mpl_selector(ax)
if not MATPLOTLIB_HAS_ROTATING_SELECTORS:
with pytest.raises(NotImplementedError,
match=('Cannot create matplotlib selector for rotated ellipse.')):
self.reg.as_mpl_selector(ax)

region = self.reg.copy(angle=0 * u.deg)
angle = 0 * u.deg
else:
angle = self.reg.angle

region = self.reg.copy(angle=angle)

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

Expand Down Expand Up @@ -162,7 +166,7 @@ def update_mask(reg):
assert_allclose(region.center.y, 4)
assert_allclose(region.width, 4)
assert_allclose(region.height, 3)
assert_quantity_allclose(region.angle, 0 * u.deg)
assert_quantity_allclose(region.angle, angle)

assert_equal(mask, 0)

Expand Down
18 changes: 11 additions & 7 deletions regions/shapes/tests/test_rectangle.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from ...tests.helpers import make_simple_wcs
from ..rectangle import RectanglePixelRegion, RectangleSkyRegion
from .test_common import BaseTestPixelRegion, BaseTestSkyRegion
from .utils import HAS_MATPLOTLIB # noqa
from .utils import HAS_MATPLOTLIB, MATPLOTLIB_HAS_ROTATING_SELECTORS # noqa


@pytest.fixture(scope='session', name='wcs')
Expand Down Expand Up @@ -118,12 +118,16 @@ def update_mask(reg):
# this works with rotated rectangles, the following exception
# check can be removed as well as the ``angle=0 * u.deg`` in the
# call to copy() below.
with pytest.raises(NotImplementedError,
match=('Cannot create matplotlib selector for '
'rotated rectangle.')):
self.reg.as_mpl_selector(ax)
if not MATPLOTLIB_HAS_ROTATING_SELECTORS:
with pytest.raises(NotImplementedError,
match=('Cannot create matplotlib selector for rotated rectangle.')):
self.reg.as_mpl_selector(ax)

region = self.reg.copy(angle=0 * u.deg)
angle = 0 * u.deg
else:
angle = self.reg.angle

region = self.reg.copy(angle=angle)

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

Expand Down Expand Up @@ -162,7 +166,7 @@ def update_mask(reg):
assert_allclose(region.center.y, 4)
assert_allclose(region.width, 4)
assert_allclose(region.height, 3)
assert_quantity_allclose(region.angle, 0 * u.deg)
assert_quantity_allclose(region.angle, angle)

assert_equal(mask, 0)

Expand Down
4 changes: 4 additions & 0 deletions regions/shapes/tests/utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
# Licensed under a 3-clause BSD style license - see LICENSE.rst

MATPLOTLIB_HAS_ROTATING_SELECTORS = False
try:
import matplotlib # noqa
HAS_MATPLOTLIB = True
import matplotlib.widgets
if hasattr(matplotlib.widgets.EllipseSelector, '_rotation'):
MATPLOTLIB_HAS_ROTATING_SELECTORS = True
except ImportError:
HAS_MATPLOTLIB = False

0 comments on commit f9545ad

Please sign in to comment.