Skip to content

Commit 66b158c

Browse files
committed
Add requirement that load_image sets a viewport
1 parent 2cba5ea commit 66b158c

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

src/astro_image_display_api/interface_definition.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@ def load_image(self, data: Any, image_label: str | None = None) -> None:
5757
data : Any
5858
The data to load. This can be a FITS file, a 2D array,
5959
or an `astropy.nddata.NDData` object.
60+
61+
image_label : str, optional
62+
The label for the image.
63+
64+
Notes
65+
-----
66+
Loading an image should also set the viewport for that image.
6067
"""
6168
raise NotImplementedError
6269

src/astro_image_display_api/widget_api_test.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,20 +157,30 @@ def test_set_get_viewport_errors(self, data, wcs):
157157
with pytest.raises(ValueError, match='[Ii]mage label.*not provided'):
158158
self.image.get_viewport()
159159

160-
def test_set_get_view_port_no_image_label(self, data):
161-
# If there is only one image, the viewport should be able to be set
162-
# and retrieved without an image label.
163-
164-
# Add an image without an image label
160+
def test_viewport_is_defined_aster_loading_image(self, data):
161+
# Check that the viewport is set to a default value when an image
162+
# is loaded, even if no viewport is explicitly set.
165163
self.image.load_image(data)
166164

167165
# Getting the viewport should not fail...
168166
vport = self.image.get_viewport()
167+
169168
assert 'center' in vport
169+
# No world, so center should be a tuple
170+
assert isinstance(vport['center'], tuple)
170171
assert 'fov' in vport
172+
# fov should be a float since no WCS
173+
assert isinstance(vport['fov'], float)
171174
assert 'image_label' in vport
172175
assert vport['image_label'] is None
173176

177+
def test_set_get_view_port_no_image_label(self, data):
178+
# If there is only one image, the viewport should be able to be set
179+
# and retrieved without an image label.
180+
181+
# Add an image without an image label
182+
self.image.load_image(data)
183+
174184
# Set the viewport without an image label
175185
self.image.set_viewport(center=(10, 10), fov=100)
176186

0 commit comments

Comments
 (0)