diff --git a/lcviz/plugins/ephemeris/ephemeris.py b/lcviz/plugins/ephemeris/ephemeris.py index 3b9f89d7..1defaa20 100644 --- a/lcviz/plugins/ephemeris/ephemeris.py +++ b/lcviz/plugins/ephemeris/ephemeris.py @@ -100,7 +100,8 @@ def __init__(self, *args, **kwargs): manual_options=['default'], on_add=self._on_component_add, on_rename_after_selection=self._on_component_rename, # noqa - on_remove_after_selection=self._on_component_remove) # noqa + on_remove_after_selection=self._on_component_remove, # noqa + validate_choice=self._validate_component) # force the original entry in ephemerides with defaults self._change_component() @@ -311,6 +312,13 @@ def _check_if_phase_viewer_exists(self, *args): viewer_base_refs = [id.split('[')[0] for id in self.app.get_viewer_ids()] self.phase_viewer_exists = self.phase_viewer_id in viewer_base_refs + def _validate_component(self, lbl): + if '[' in lbl or ']' in lbl: + return 'cannot contain square brackets' + if ':' in lbl: + return 'cannot contain colon' + return '' + def _on_component_add(self, lbl): self.hub.broadcast(EphemerisComponentChangedMessage(old_lbl=None, new_lbl=lbl, sender=self)) diff --git a/lcviz/tests/test_plugin_ephemeris.py b/lcviz/tests/test_plugin_ephemeris.py index 9953f2af..d5e6cac9 100644 --- a/lcviz/tests/test_plugin_ephemeris.py +++ b/lcviz/tests/test_plugin_ephemeris.py @@ -1,3 +1,9 @@ +import pytest +from packaging.version import Version + +import jdaviz +JDAVIZ_LT_3_9_0 = Version(jdaviz.__version__) < Version('3.9.0') + def test_docs_snippets(helper, light_curve_like_kepler_quarter): lcviz, lc = helper, light_curve_like_kepler_quarter @@ -43,6 +49,14 @@ def test_plugin_ephemeris(helper, light_curve_like_kepler_quarter): assert len(ephem.ephemerides) == 2 assert 'custom component' in ephem.ephemerides + if not JDAVIZ_LT_3_9_0: + with pytest.raises(ValueError): + # brackets interfere with cloned viewer label logic + ephem.rename_component('custom component', 'custom component[blah]') + with pytest.raises(ValueError): + # colons interfere with viewer ephemeris logic + ephem.rename_component('custom component', 'custom component:blah') + ephem.rename_component('custom component', 'renamed custom component') assert len(ephem.ephemerides) == 2 assert 'renamed custom component' in ephem.ephemerides