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 142f080 commit de37303
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 12 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
17 changes: 11 additions & 6 deletions regions/shapes/tests/test_ellipse.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,17 @@ 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)
import matplotlib.widgets
if not hasattr(matplotlib.widgets.EllipseSelector, '_rotation'):
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 +167,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
17 changes: 11 additions & 6 deletions regions/shapes/tests/test_rectangle.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,17 @@ 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)
import matplotlib.widgets
if not hasattr(matplotlib.widgets.RectangleSelector, '_rotation'):
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 +167,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

0 comments on commit de37303

Please sign in to comment.