|
7 | 7 | from astropy.coordinates import SkyCoord |
8 | 8 | from astropy.io import fits |
9 | 9 | from astropy.nddata import CCDData, NDData |
10 | | -from astropy.table import Table, vstack |
| 10 | +from astropy.table import Table |
11 | 11 | from astropy import units as u |
12 | 12 | from astropy.wcs import WCS |
13 | 13 | from astropy.visualization import AsymmetricPercentileInterval, BaseInterval, BaseStretch, LogStretch, ManualInterval |
14 | 14 |
|
| 15 | +from .interface_definition import ImageViewerInterface |
| 16 | + |
15 | 17 | __all__ = ['ImageWidgetAPITest'] |
16 | 18 |
|
17 | 19 |
|
@@ -716,15 +718,48 @@ def test_stretch_cuts_errors(self, data): |
716 | 718 | with pytest.raises(ValueError, match='[Ii]mage label.*not found'): |
717 | 719 | self.image.set_cuts((10, 100), image_label='not a valid label') |
718 | 720 |
|
719 | | - @pytest.mark.skip(reason="Not clear whether colormap is part of the API") |
720 | | - def test_colormap(self): |
721 | | - cmap_desired = 'gray' |
| 721 | + def test_colormap_options(self): |
722 | 722 | cmap_list = self.image.colormap_options |
723 | | - assert len(cmap_list) > 0 and cmap_desired in cmap_list |
| 723 | + assert set(ImageViewerInterface.MINIMUM_REQUIRED_COLORMAPS) <= set(cmap_list) |
| 724 | + assert set(self.image.MINIMUM_REQUIRED_COLORMAPS) == set(ImageViewerInterface.MINIMUM_REQUIRED_COLORMAPS) |
| 725 | + |
| 726 | + def test_set_get_colormap(self, data): |
| 727 | + # Check setting and getting with a single image label. |
| 728 | + self.image.load_image(data, image_label='test') |
| 729 | + cmap_desired = 'gray' |
724 | 730 | self.image.set_colormap(cmap_desired) |
| 731 | + assert self.image.get_colormap() == cmap_desired |
| 732 | + |
| 733 | + # Check that the colormap can be set with an image label |
| 734 | + new_cmap = "viridis" |
| 735 | + self.image.set_colormap(new_cmap, image_label='test') |
| 736 | + assert self.image.get_colormap(image_label='test') == new_cmap |
| 737 | + |
| 738 | + def test_set_colormap_errors(self, data): |
| 739 | + # Check that setting a colormap raises an error if the colormap |
| 740 | + # is not in the list of allowed colormaps. |
| 741 | + self.image.load_image(data, image_label='test') |
| 742 | + |
| 743 | + with pytest.raises(ValueError, match='[Ii]nvalid colormap'): |
| 744 | + self.image.set_colormap('not a valid colormap') |
| 745 | + |
| 746 | + # Check that getting a colormap for an image label that does not exist |
| 747 | + with pytest.raises(ValueError, match='[Ii]mage label.*not found'): |
| 748 | + self.image.get_colormap(image_label='not a valid label') |
| 749 | + |
| 750 | + # Check that setting a colormap without an image label fails |
| 751 | + # when there is more than one image label |
| 752 | + self.image.load_image(data, image_label='another test') |
| 753 | + with pytest.raises(ValueError, match='Multiple image labels defined'): |
| 754 | + self.image.set_colormap('gray') |
| 755 | + |
| 756 | + # Same for getting the colormap without an image label |
| 757 | + with pytest.raises(ValueError, match='Multiple image labels defined'): |
| 758 | + self.image.get_colormap() |
725 | 759 |
|
726 | 760 | def test_cursor(self): |
727 | 761 | assert self.image.cursor in self.image.ALLOWED_CURSOR_LOCATIONS |
| 762 | + assert set(ImageViewerInterface.ALLOWED_CURSOR_LOCATIONS) == set(self.image.ALLOWED_CURSOR_LOCATIONS) |
728 | 763 | with pytest.raises(self.cursor_error_classes): |
729 | 764 | self.image.cursor = 'not a valid option' |
730 | 765 | self.image.cursor = 'bottom' |
|
0 commit comments