Skip to content

Commit 9ee1ad9

Browse files
committed
Test os.rename
1 parent 2f408f2 commit 9ee1ad9

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

tests/snippets/stdlib_os.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
assert_raises(OSError, lambda: os.read(fd, 10))
1212
assert_raises(FileNotFoundError, lambda: os.open('DOES_NOT_EXIST', os.O_RDONLY))
1313
assert_raises(FileNotFoundError, lambda: os.open('DOES_NOT_EXIST', os.O_WRONLY))
14+
assert_raises(FileNotFoundError, lambda: os.rename('DOES_NOT_EXIST', 'DOES_NOT_EXIST 2'))
1415

1516

1617
assert os.O_RDONLY == 0
@@ -80,6 +81,7 @@ def __exit__(self, exc_type, exc_val, exc_tb):
8081

8182
FILE_NAME = "test1"
8283
FILE_NAME2 = "test2"
84+
FILE_NAME3 = "test3"
8385
SYMLINK_FILE = "symlink"
8486
SYMLINK_FOLDER = "symlink1"
8587
FOLDER = "dir1"
@@ -104,6 +106,19 @@ def __exit__(self, exc_type, exc_val, exc_tb):
104106
assert os.read(fd, len(CONTENT3)) == CONTENT3
105107
os.close(fd)
106108

109+
fname3 = os.path.join(tmpdir, FILE_NAME3)
110+
os.rename(fname, fname3)
111+
assert os.path.exists(fname) == False
112+
assert os.path.exists(fname3) == True
113+
114+
fd = os.open(fname3, 0)
115+
assert os.read(fd, len(CONTENT2) + len(CONTENT3)) == CONTENT2 + CONTENT3
116+
os.close(fd)
117+
118+
os.rename(fname3, fname)
119+
assert os.path.exists(fname3) == False
120+
assert os.path.exists(fname) == True
121+
107122
# wait a little bit to ensure that the file times aren't the same
108123
time.sleep(0.1)
109124

0 commit comments

Comments
 (0)