Skip to content

Commit c5ce565

Browse files
committed
BF/ENH: assure that foo.txt exists and no conflicts for demonstration
1 parent 8cc5924 commit c5ce565

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

‎command.py‎

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# -*- coding: utf-8 -*-
33

44
importos
5-
5+
fromos.pathimportlexists
66

77
classMoveFileCommand(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-
forcmdincommand_stack:
33-
cmd.execute()
34-
35-
# and can also be undone at will
36-
forcmdinreversed(command_stack):
37-
cmd.undo()
31+
# verify that none of the target files exist
32+
assert(notlexists("foo.txt"))
33+
assert(notlexists("bar.txt"))
34+
assert(notlexists("baz.txt"))
35+
try:
36+
withopen("foo.txt", "w"): # Creating the file
37+
pass
38+
39+
# they can be executed later on
40+
forcmdincommand_stack:
41+
cmd.execute()
42+
43+
# and can also be undone at will
44+
forcmdinreversed(command_stack):
45+
cmd.undo()
46+
finally:
47+
os.unlink("foo.txt")
3848

3949
if__name__=="__main__":
4050
main()

0 commit comments

Comments
(0)