Skip to content

Commit e7fec85

Browse files
committed
Add test for case of map_name
1 parent 9eadeba commit e7fec85

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/astro_image_display_api/dummy_viewer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,13 +160,13 @@ def colormap_options(self) -> list[str]:
160160
colormap_options.__doc__ = ImageViewerInterface.colormap_options.__doc__
161161

162162
def set_colormap(self, map_name: str, image_label: str | None = None) -> None:
163-
if map_name not in self.colormap_options:
163+
if map_name.lower() not in self.colormap_options:
164164
raise ValueError(f"Invalid colormap '{map_name}'. Must be one of {self.colormap_options}.")
165165

166166
image_label = self._resolve_image_label(image_label)
167167
if image_label not in self._images:
168168
raise ValueError(f"Image label '{image_label}' not found. Please load an image first.")
169-
self._images[image_label].colormap = map_name
169+
self._images[image_label].colormap = map_name.lower()
170170

171171
set_colormap.__doc__ = ImageViewerInterface.set_colormap.__doc__
172172

src/astro_image_display_api/widget_api_test.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -735,6 +735,19 @@ def test_set_get_colormap(self, data):
735735
self.image.set_colormap(new_cmap, image_label='test')
736736
assert self.image.get_colormap(image_label='test') == new_cmap
737737

738+
def test_set_get_colormap_map_name_case_insensitive(self, data):
739+
# Check that the colormap can be set with a name that is not
740+
# case-sensitive.
741+
self.image.load_image(data, image_label='test')
742+
cmap_desired = 'GrAy'
743+
self.image.set_colormap(cmap_desired)
744+
assert self.image.get_colormap() == cmap_desired.lower()
745+
746+
# Set the colormap with a different case
747+
new_cmap = "Viridis"
748+
self.image.set_colormap(new_cmap, image_label='test')
749+
assert self.image.get_colormap(image_label='test') == 'viridis'
750+
738751
def test_set_colormap_errors(self, data):
739752
# Check that setting a colormap raises an error if the colormap
740753
# is not in the list of allowed colormaps.

0 commit comments

Comments
 (0)