Skip to content

Commit

Permalink
Update backup file (#58)
Browse files Browse the repository at this point in the history
* unlink backup path if exists

* update gitignore

* remove unnecessary star files

---------

Co-authored-by: Hanjin Liu <[email protected]>
  • Loading branch information
hanjinliu and Hanjin Liu authored Apr 29, 2024
1 parent 4f99ec6 commit 0606cf4
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@
/m2relion/
package.sh
MANIFEST

__pycache__/
/tests/data/*.star~
2 changes: 2 additions & 0 deletions src/starfile/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ def backup_if_file_exists(self):
if self.filename.exists():
new_name = self.filename.name + '~'
backup_path = self.filename.resolve().parent / new_name
if backup_path.exists():
backup_path.unlink()
self.filename.rename(backup_path)


Expand Down
2 changes: 2 additions & 0 deletions tests/test_functional_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ def test_write_overwrites_with_backup():
starfile.write(test_df, output_file)
backup = test_data_directory / 'test_overwrite_backup.star~'
assert backup.exists()
starfile.write(test_df, output_file)
assert backup.exists()


def test_read_non_existent_file():
Expand Down

0 comments on commit 0606cf4

Please sign in to comment.