Skip to content

Commit fa373c9

Browse files
authored
Merge pull request #170 from mwcraig/add-overwrite
Add overwrite argument to save method
2 parents e0ddfc8 + 4c9162a commit fa373c9

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

astrowidgets/interface_definition.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def load_nddata(self, data: NDData) -> None:
9090

9191
# Saving contents of the view and accessing the view
9292
@abstractmethod
93-
def save(self, filename: str | os.PathLike) -> None:
93+
def save(self, filename: str | os.PathLike, overwrite: bool = False) -> None:
9494
"""
9595
Save the current view to a file.
9696
@@ -99,6 +99,10 @@ def save(self, filename: str | os.PathLike) -> None:
9999
filename : str
100100
The file to save to. The format is determined by the
101101
extension.
102+
103+
overwrite : bool, optional
104+
If `True`, overwrite the file if it exists. Default is
105+
`False`.
102106
"""
103107
raise NotImplementedError
104108

astrowidgets/tests/widget_api_test.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,3 +359,16 @@ def test_scroll_pan(self):
359359
def test_save(self, tmp_path):
360360
filename = tmp_path / 'woot.png'
361361
self.image.save(filename)
362+
363+
def test_save_overwrite(self, tmp_path):
364+
filename = tmp_path / 'woot.png'
365+
366+
# First write should be fine
367+
self.image.save(filename)
368+
369+
# Second write should raise an error because file exists
370+
with pytest.raises(FileExistsError):
371+
self.image.save(filename)
372+
373+
# Using overwrite should save successfully
374+
self.image.save(filename, overwrite=True)

0 commit comments

Comments
 (0)