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
import os
5-
5+
from os.path import lexists
66

77
class 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

3949
if __name__ == "__main__":
4050
main()

0 commit comments

Comments
 (0)