Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update backup file #58

Merged
merged 3 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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