From dabcf5fa2ed553f7fc7f08b17ab9a0764b721bc0 Mon Sep 17 00:00:00 2001 From: Kyle Conroy Date: Tue, 19 Mar 2024 12:54:18 -0400 Subject: [PATCH] overwrite support and basic test coverage --- .../plugins/markers/tests/test_markers_plugin.py | 6 ++++++ .../plugins/plot_options/tests/test_plot_options.py | 2 +- jdaviz/core/template_mixin.py | 12 ++++++++---- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/jdaviz/configs/default/plugins/markers/tests/test_markers_plugin.py b/jdaviz/configs/default/plugins/markers/tests/test_markers_plugin.py index 4021ab7965..d943cd3c33 100644 --- a/jdaviz/configs/default/plugins/markers/tests/test_markers_plugin.py +++ b/jdaviz/configs/default/plugins/markers/tests/test_markers_plugin.py @@ -124,6 +124,12 @@ def test_markers_cubeviz(cubeviz_helper, spectrum1d_cube): assert len(_get_markers_from_viewer(fv).x) == 1 assert len(_get_markers_from_viewer(sv).x) == 2 + # appears as option in export plugin and exports successfully + exp = cubeviz_helper.plugins['Export'] + assert "Markers:table" in exp.table.choices + exp.table = "Markers:table" + exp.export() + # clearing table clears markers mp.clear_table() assert mp.export_table() is None diff --git a/jdaviz/configs/default/plugins/plot_options/tests/test_plot_options.py b/jdaviz/configs/default/plugins/plot_options/tests/test_plot_options.py index 9ded8b3a33..5ee021de6f 100644 --- a/jdaviz/configs/default/plugins/plot_options/tests/test_plot_options.py +++ b/jdaviz/configs/default/plugins/plot_options/tests/test_plot_options.py @@ -144,7 +144,7 @@ def test_user_api(cubeviz_helper, spectrum1d_cube): po = cubeviz_helper.plugins['Plot Options'] assert po.multiselect is False - assert "multiselect" in po.viewer._obj.__repr__() + assert "multiselect" in po.viewer.__repr__() # regression test for https://github.com/spacetelescope/jdaviz/pull/1708 # user calls to select_default should revert even if current entry is valid diff --git a/jdaviz/core/template_mixin.py b/jdaviz/core/template_mixin.py index 82529599c6..d1a81fcc8c 100644 --- a/jdaviz/core/template_mixin.py +++ b/jdaviz/core/template_mixin.py @@ -4196,7 +4196,7 @@ def vue_clear_table(self, data=None): # call that, otherwise call the one defined here getattr(self._plugin, 'clear_table', self.clear_table)() - def export_table(self, filename=None): + def export_table(self, filename=None, overwrite=False): """ Export the QTable representation of the table. @@ -4205,9 +4205,11 @@ def export_table(self, filename=None): filename : str, optional If provided, will write to the file, otherwise will just return the QTable object. + overwrite : bool, optional + If ``filename`` already exists, should it be overwritten. """ if filename is not None: - self._qtable.write(filename) + self._qtable.write(filename, overwrite=overwrite) # TODO: default to only showing selected columns? return self._qtable @@ -4244,7 +4246,7 @@ def vue_clear_table(self, data=None): # (to also clear markers, etc) self.clear_table() - def export_table(self, filename=None): + def export_table(self, filename=None, overwrite=False): """ Export the QTable representation of the table. @@ -4253,8 +4255,10 @@ def export_table(self, filename=None): filename : str, optional If provided, will write to the file, otherwise will just return the QTable object. + overwrite : bool, optional + If ``filename`` already exists, should it be overwritten. """ - return self.table.export_table(filename=filename) + return self.table.export_table(filename=filename, overwrite=overwrite) class Plot(PluginSubcomponent):