File tree Expand file tree Collapse file tree 1 file changed +18
-8
lines changed Expand file tree Collapse file tree 1 file changed +18
-8
lines changed Original file line number Diff line number Diff line change 2
2
# -*- coding: utf-8 -*-
3
3
4
4
import os
5
-
5
+ from os . path import lexists
6
6
7
7
class MoveFileCommand (object ):
8
8
@@ -28,13 +28,23 @@ def main():
28
28
command_stack .append (MoveFileCommand ('foo.txt' , 'bar.txt' ))
29
29
command_stack .append (MoveFileCommand ('bar.txt' , 'baz.txt' ))
30
30
31
- # they can be executed later on
32
- for cmd in command_stack :
33
- cmd .execute ()
34
-
35
- # and can also be undone at will
36
- for cmd in reversed (command_stack ):
37
- cmd .undo ()
31
+ # verify that none of the target files exist
32
+ assert (not lexists ("foo.txt" ))
33
+ assert (not lexists ("bar.txt" ))
34
+ assert (not lexists ("baz.txt" ))
35
+ try :
36
+ with open ("foo.txt" , "w" ): # Creating the file
37
+ pass
38
+
39
+ # they can be executed later on
40
+ for cmd in command_stack :
41
+ cmd .execute ()
42
+
43
+ # and can also be undone at will
44
+ for cmd in reversed (command_stack ):
45
+ cmd .undo ()
46
+ finally :
47
+ os .unlink ("foo.txt" )
38
48
39
49
if __name__ == "__main__" :
40
50
main ()
You can’t perform that action at this time.
0 commit comments