Skip to content

Commit 7980261

Browse files
committed
extmod/vfs_posix: Additional tests for coverage of error cases.
Signed-off-by: Christian Walther <cwalther@gmx.ch>
1 parent 6c6523b commit 7980261

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

tests/extmod/vfs_posix.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,49 @@ def write_files_without_closing():
194194
# restore CWD
195195
os.chdir(curdir)
196196

197+
# test error cases with long paths
198+
if sys.platform == "win32":
199+
# Windows doesn't let you change into a directory whose full path is too
200+
# long, so this cannot be tested.
201+
def testlongpath():
202+
return True
203+
204+
else:
205+
206+
def testlongpath():
207+
longname = 62 * "long"
208+
for n in range(300):
209+
os.mkdir(longname)
210+
os.chdir(longname)
211+
try:
212+
os.getcwd()
213+
except OSError as e:
214+
# expecting ERANGE from getcwd() after a few iterations, then we
215+
# are in the situation to be tested
216+
if e.errno == 34:
217+
break
218+
else:
219+
print("getcwd():", repr(e))
220+
return False
221+
222+
try:
223+
print(os.VfsPosix("something"))
224+
except OSError as e:
225+
# expecting ERANGE
226+
if e.errno != 34:
227+
print("VfsPosix():", repr(e))
228+
return False
229+
230+
# clean up
231+
for i in range(n + 1):
232+
os.chdir("..")
233+
os.rmdir(longname)
234+
235+
return True
236+
237+
238+
print("testlongpath():", testlongpath())
239+
197240
# rmdir
198241
os.rmdir(temp_dir)
199242
print(temp_dir in os.listdir())

tests/extmod/vfs_posix.py.exp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,6 @@ chdir("/mnt/dir"): None
3535
getcwd(): /mnt/dir
3636
chdir(".."): None
3737
getcwd(): /mnt
38+
testlongpath(): True
3839
False
3940
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