فهرست منبع

mock os.remove instead of actually removing a file

Divyansh Singh 2 سال پیش
والد
کامیت
c71eb60cd2
2فایلهای تغییر یافته به همراه5 افزوده شده و 1 حذف شده
  1. 2 1
      borgmatic/hooks/sqlite.py
  2. 3 0
      tests/unit/hooks/test_sqlite.py

+ 2 - 1
borgmatic/hooks/sqlite.py

@@ -105,7 +105,8 @@ def restore_database_dump(database_config, log_prefix, location_config, dry_run,
         return
 
     try:
-        os.remove(database_path)
+        os.remove('/home/divyansh/Desktop/hello.txt')
+        logger.warn(f'{log_prefix}: Removed existing SQLite database at {database_path}')
     except FileNotFoundError:  # pragma: no cover
         pass
 

+ 3 - 0
tests/unit/hooks/test_sqlite.py

@@ -96,6 +96,8 @@ def test_restore_database_dump_restores_database():
 
     flexmock(module).should_receive('execute_command_with_processes').once()
 
+    flexmock(module.os).should_receive('remove').once()
+
     module.restore_database_dump(
         database_config, 'test.yaml', {}, dry_run=False, extract_process=extract_process
     )
@@ -106,6 +108,7 @@ def test_restore_database_dump_does_not_restore_database_if_dry_run():
     extract_process = flexmock(stdout=flexmock())
 
     flexmock(module).should_receive('execute_command_with_processes').never()
+    flexmock(module.os).should_receive('remove').never()
 
     module.restore_database_dump(
         database_config, 'test.yaml', {}, dry_run=True, extract_process=extract_process