Skip to content

Commit 3ec9078

Browse files
authored
Merge pull request #73 from mwcraig/fix-viewer-logic-bug
Add test for and fix bug in viewer logic
2 parents 6e8e66b + 558befb commit 3ec9078

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/astro_image_display_api/api_test.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,21 @@ def test_set_get_catalog_style_preserves_extra_keywords(self, catalog):
438438
del retrieved_style["catalog_label"] # Remove the label
439439
assert retrieved_style == style
440440

441+
def test_catalog_has_style_after_loading(self, catalog):
442+
# Check that loading a catalog sets a default style for that catalog.
443+
self.image.load_catalog(catalog, catalog_label="test1")
444+
445+
retrieved_style = self.image.get_catalog_style(catalog_label="test1")
446+
assert isinstance(retrieved_style, dict)
447+
assert "color" in retrieved_style
448+
assert "shape" in retrieved_style
449+
assert "size" in retrieved_style
450+
451+
# Loading again should have the same style
452+
self.image.load_catalog(catalog, catalog_label="test1")
453+
retrieved_style2 = self.image.get_catalog_style(catalog_label="test1")
454+
assert retrieved_style2 == retrieved_style
455+
441456
@pytest.mark.parametrize("catalog_label", ["test1", None])
442457
def test_load_get_single_catalog_with_without_label(self, catalog, catalog_label):
443458
# Make sure we can get a single catalog with or without a label.

src/astro_image_display_api/image_viewer_logic.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
__all__ = ["ImageViewerLogic"]
2828

29+
2930
@dataclass
3031
class CatalogInfo:
3132
"""
@@ -523,7 +524,11 @@ def load_catalog(
523524
# Ensure a catalog always has a style
524525
if catalog_style is None:
525526
if not self._catalogs[catalog_label].style:
527+
# No style has been set, so use the default style
526528
catalog_style = self._default_catalog_style.copy()
529+
else:
530+
# Use the existing style
531+
catalog_style = self._catalogs[catalog_label].style.copy()
527532

528533
self._catalogs[catalog_label].style = catalog_style
529534

0 commit comments

Comments
 (0)