From 0606cf4c50b6ab7d68c18abeee20259737b00c40 Mon Sep 17 00:00:00 2001 From: Hanjin Liu <40591297+hanjinliu@users.noreply.github.com> Date: Tue, 30 Apr 2024 00:08:54 +0900 Subject: [PATCH] Update backup file (#58) * unlink backup path if exists * update gitignore * remove unnecessary star files --------- Co-authored-by: Hanjin Liu --- .gitignore | 3 +++ src/starfile/writer.py | 2 ++ tests/test_functional_interface.py | 2 ++ 3 files changed, 7 insertions(+) diff --git a/.gitignore b/.gitignore index d07b744..9c15483 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,6 @@ /m2relion/ package.sh MANIFEST + +__pycache__/ +/tests/data/*.star~ diff --git a/src/starfile/writer.py b/src/starfile/writer.py index 833c689..70843f3 100644 --- a/src/starfile/writer.py +++ b/src/starfile/writer.py @@ -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) diff --git a/tests/test_functional_interface.py b/tests/test_functional_interface.py index 8739cce..a609362 100644 --- a/tests/test_functional_interface.py +++ b/tests/test_functional_interface.py @@ -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():