Skip to content

Commit 73419ee

Browse files
committed
extmod/vfs_posix: Add more tests for relative paths, currently failing.
VfsPosix objects with a non-empty root path do not handle relative paths correctly, to be fixed in the following commits. Signed-off-by: Christian Walther <cwalther@gmx.ch>
1 parent 37520af commit 73419ee

File tree

2 files changed

+86
-0
lines changed

2 files changed

+86
-0
lines changed

tests/extmod/vfs_posix.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,70 @@ def write_files_without_closing():
130130
except OSError:
131131
print("remove OSError")
132132

133+
# construct new VfsPosix with absolute path argument
134+
temp_dir_abs = os.getcwd() + os.sep + temp_dir
135+
vfs = os.VfsPosix(temp_dir_abs)
136+
# when VfsPosix is used the intended way via os.mount(), it can only be called
137+
# with relative paths when the CWD is inside or at its root, so simulate that
138+
os.chdir(temp_dir_abs)
139+
vfs.mkdir("subdir")
140+
vfs.mkdir("subdir/one")
141+
print('listdir("/"):', sorted(i[0] for i in vfs.ilistdir("/")))
142+
print('listdir("."):', sorted(i[0] for i in vfs.ilistdir(".")))
143+
print('getcwd() in {"", "/"}:', vfs.getcwd() in {"", "/"})
144+
print('chdir("subdir"):', vfs.chdir("subdir"))
145+
print("getcwd():", vfs.getcwd())
146+
print('mkdir("two"):', vfs.mkdir("two"))
147+
f = vfs.open("file.py", "w")
148+
f.write("print('hello')")
149+
f.close()
150+
print('listdir("/"):', sorted(i[0] for i in vfs.ilistdir("/")))
151+
print('listdir("/subdir"):', sorted(i[0] for i in vfs.ilistdir("/subdir")))
152+
print('listdir("."):', sorted(i[0] for i in vfs.ilistdir(".")))
153+
try:
154+
f = vfs.open("/subdir/file.py", "r")
155+
print(f.read())
156+
f.close()
157+
except Exception as e:
158+
print(e)
159+
import sys
160+
161+
sys.path.insert(0, "")
162+
try:
163+
import file
164+
165+
print(file)
166+
except Exception as e:
167+
print(e)
168+
del sys.path[0]
169+
vfs.remove("file.py")
170+
vfs.rmdir("two")
171+
vfs.rmdir("/subdir/one")
172+
vfs.chdir("/")
173+
vfs.rmdir("/subdir")
174+
175+
# done with vfs, restore CWD
176+
os.chdir(curdir)
177+
178+
# some integration tests with a mounted VFS
179+
os.mount(os.VfsPosix(temp_dir_abs), "/mnt")
180+
os.mkdir("/mnt/dir")
181+
print('chdir("/mnt/dir"):', os.chdir("/mnt/dir"))
182+
print("getcwd():", os.getcwd())
183+
print('chdir("/mnt"):', os.chdir("/mnt"))
184+
print("getcwd():", os.getcwd())
185+
print('chdir("/"):', os.chdir("/"))
186+
print("getcwd():", os.getcwd())
187+
print('chdir("/mnt/dir"):', os.chdir("/mnt/dir"))
188+
print("getcwd():", os.getcwd())
189+
print('chdir(".."):', os.chdir(".."))
190+
print("getcwd():", os.getcwd())
191+
os.rmdir("/mnt/dir")
192+
os.umount("/mnt")
193+
194+
# restore CWD
195+
os.chdir(curdir)
196+
133197
# rmdir
134198
os.rmdir(temp_dir)
135199
print(temp_dir in os.listdir())

tests/extmod/vfs_posix.py.exp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,27 @@ next_file_no <= base_file_no True
1313
hello
1414
[]
1515
remove OSError
16+
listdir("/"): ['subdir']
17+
listdir("."): ['subdir']
18+
getcwd() in {"", "/"}: True
19+
chdir("subdir"): None
20+
getcwd(): /subdir
21+
mkdir("two"): None
22+
listdir("/"): ['subdir']
23+
listdir("/subdir"): ['file.py', 'one', 'two']
24+
listdir("."): ['file.py', 'one', 'two']
25+
print('hello')
26+
hello
27+
<module 'file' from 'file.py'>
28+
chdir("/mnt/dir"): None
29+
getcwd(): /mnt/dir
30+
chdir("/mnt"): None
31+
getcwd(): /mnt
32+
chdir("/"): None
33+
getcwd(): /
34+
chdir("/mnt/dir"): None
35+
getcwd(): /mnt/dir
36+
chdir(".."): None
37+
getcwd(): /mnt
1638
False
1739
rmdir OSError

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy