Skip to content

Commit

Permalink
overwrite support and basic test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
kecnry committed Mar 19, 2024
1 parent d5d12a4 commit dabcf5f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 8 additions & 4 deletions jdaviz/core/template_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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

Expand Down Expand Up @@ -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.
Expand All @@ -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):
Expand Down

0 comments on commit dabcf5f

Please sign in to comment.