Skip to content

Commit

Permalink
Test and fix RegionSelector doctest fail
Browse files Browse the repository at this point in the history
  • Loading branch information
Cadair committed Oct 3, 2024
1 parent beb24d3 commit ea5d3e0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
15 changes: 14 additions & 1 deletion gwcs/selector.py
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,20 @@ def __init__(self, inputs, outputs, selector, label_mapper, undefined_transform_
raise ValueError('"0" and " " are not allowed as keys.')
self._input_units_strict = {key: False for key in self._inputs}
self._input_units_allow_dimensionless = {key: False for key in self._inputs}
super(RegionsSelector, self).__init__(n_models=1, name=name, **kwargs)
super().__init__(n_models=1, name=name, **kwargs)
# Validate uses_quantity at init time for nicer error message
self.uses_quantity # noqa

@property
def uses_quantity(self):
all_uses_quantity = [t.uses_quantity for t in self._selector.values()]
not_all_uses_quantity = [not uq for uq in all_uses_quantity]
if all(all_uses_quantity):
return True

Check warning on line 543 in gwcs/selector.py

View check run for this annotation

Codecov / codecov/patch

gwcs/selector.py#L543

Added line #L543 was not covered by tests
elif not_all_uses_quantity:
return False
else:
raise ValueError("You can not mix models which use quantity and do not use quantity inside a RegionSelector")

Check warning on line 547 in gwcs/selector.py

View check run for this annotation

Codecov / codecov/patch

gwcs/selector.py#L547

Added line #L547 was not covered by tests

def set_input(self, rid):
"""
Expand Down
9 changes: 7 additions & 2 deletions gwcs/tests/test_region.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
from numpy.testing import assert_equal, assert_allclose
from astropy.modeling import models
import pytest
from .. import region, selector
from .. import utils as gwutils
from gwcs import region, selector, WCS
from gwcs import utils as gwutils
from gwcs import coordinate_frames as cf


def test_LabelMapperArray_from_vertices_int():
Expand Down Expand Up @@ -237,6 +238,10 @@ def test_RegionsSelector():
reg_selector.undefined_transform_value = -100
assert_equal(reg_selector(0, 0), [-100, -100])

wcs = WCS(forward_transform=reg_selector, output_frame=cf.Frame2D())
out = wcs(1, 1)
assert out == (-100, -100)


def test_overalpping_ranges():
"""
Expand Down

0 comments on commit ea5d3e0

Please sign in to comment.