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 22# -*- coding: utf-8 -*-
33
44import os
5-
5+ from os . path import lexists
66
77class MoveFileCommand (object ):
88
@@ -28,13 +28,23 @@ def main():
2828 command_stack .append (MoveFileCommand ('foo.txt' , 'bar.txt' ))
2929 command_stack .append (MoveFileCommand ('bar.txt' , 'baz.txt' ))
3030
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" )
3848
3949if __name__ == "__main__" :
4050 main ()
You can’t perform that action at this time.
0 commit comments