@@ -41,30 +41,34 @@ def _run_transaction_test(self, fail: bool):
4141 self .assertFalse (test_folder .exists ())
4242 self .assertFalse (test_file_3 .exists ())
4343
44- lock_file = test_root .parent / (test_root .filename + LOCK_EXT )
44+ temp_dir = FileObj ("memory://temp" )
45+ transaction = Transaction (test_root , temp_dir )
46+
47+ self .assertEqual (test_root , transaction .target_dir )
48+
49+ lock_file = transaction .lock_file
4550 self .assertFalse (lock_file .exists ())
4651
47- rollback_dir = FileObj ( "memory://rollback" )
52+ rollback_dir = transaction . rollback_dir
4853 rollback_file = rollback_dir / ROLLBACK_FILE
4954 self .assertFalse (rollback_file .exists ())
5055
5156 def change_test_file_1 (rollback_cb : Callable ):
5257 original_data = test_file_1 .read ()
5358 test_file_1 .write ("D-E-F" )
54- rollback_cb ("replace_file" , test_file_1 .path , original_data )
59+ rollback_cb ("replace_file" , test_file_1 .filename , original_data )
5560
5661 def create_test_file_2 (rollback_cb : Callable ):
5762 test_file_2 .write ("1-2-3" )
58- rollback_cb ("delete_file" , test_file_2 .path , None )
63+ rollback_cb ("delete_file" , test_file_2 .filename , None )
5964
6065 def create_test_folder (rollback_cb : Callable ):
6166 test_folder .mkdir ()
6267 test_file_3 .write ("4-5-6" )
63- rollback_cb ("delete_dir" , test_folder .path , None )
68+ rollback_cb ("delete_dir" , test_folder .filename , None )
6469
6570 try :
66- with Transaction (test_root , rollback_dir ,
67- create_rollback_subdir = False ) as rollback_cb :
71+ with transaction as rollback_cb :
6872 self .assertTrue (rollback_file .exists ())
6973 self .assertTrue (lock_file .exists ())
7074
@@ -77,9 +81,9 @@ def create_test_folder(rollback_cb: Callable):
7781 for line in rollback_data .split ("\n " )]
7882 self .assertEqual (
7983 [
80- ["replace_file" , "/test/ file-1.txt" ],
81- ["delete_file" , "/test/ file-2.txt" ],
82- ["delete_dir" , "/test/ folder" ],
84+ ["replace_file" , "file-1.txt" ],
85+ ["delete_file" , "file-2.txt" ],
86+ ["delete_dir" , "folder" ],
8387 []
8488 ],
8589 rollback_records
@@ -152,35 +156,33 @@ def test_it_raises_if_not_used_with_with(self):
152156 def test_deletes_lock (self ):
153157 test_root = FileObj ("memory://test" )
154158 test_root .mkdir ()
155- rollback_dir = FileObj ("memory://rollback" )
156- rollback_dir .mkdir ()
157- transaction = Transaction (test_root , rollback_dir ,
158- create_rollback_subdir = False )
159- self .assertFalse (transaction ._lock_file .exists ())
159+ temp_dir = FileObj ("memory://temp" )
160+ temp_dir .mkdir ()
161+ transaction = Transaction (test_root , temp_dir )
162+ self .assertFalse (transaction .lock_file .exists ())
160163 with transaction :
161- self .assertTrue (transaction ._lock_file .exists ())
162- self .assertFalse (transaction ._lock_file .exists ())
164+ self .assertTrue (transaction .lock_file .exists ())
165+ self .assertFalse (transaction .lock_file .exists ())
163166
164167 def test_leaves_lock_behind_when_it_cannot_be_deleted (self ):
165168 test_root = FileObj ("memory://test" )
166169 test_root .mkdir ()
167- rollback_dir = FileObj ("memory://rollback" )
168- rollback_dir .mkdir ()
169- transaction = Transaction (test_root , rollback_dir ,
170- create_rollback_subdir = False )
170+ temp_dir = FileObj ("memory://temp" )
171+ temp_dir .mkdir ()
172+ transaction = Transaction (test_root , temp_dir )
171173 delete_called = False
172174
173175 def _delete ():
174176 nonlocal delete_called
175177 delete_called = True
176178 raise OSError ("Bam!" )
177179
178- transaction ._lock_file .delete = _delete
179- self .assertFalse (transaction ._lock_file .exists ())
180+ transaction .lock_file .delete = _delete
181+ self .assertFalse (transaction .lock_file .exists ())
180182 with transaction :
181- self .assertTrue (transaction ._lock_file .exists ())
183+ self .assertTrue (transaction .lock_file .exists ())
182184 self .assertEqual (True , delete_called )
183- self .assertTrue (transaction ._lock_file .exists ())
185+ self .assertTrue (transaction .lock_file .exists ())
184186
185187 # noinspection PyMethodMayBeStatic
186188 def test_it_raises_on_illegal_callback_calls (self ):
0 commit comments