tests/extmod/vfs_posix.py: Add more tests for VfsPosix class.
Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
parent
26b4ef4c46
commit
df85e48813
@ -8,11 +8,11 @@ except (ImportError, AttributeError):
|
|||||||
print("SKIP")
|
print("SKIP")
|
||||||
raise SystemExit
|
raise SystemExit
|
||||||
|
|
||||||
# We need a file for testing that doesn't already exist.
|
# We need a directory for testing that doesn't already exist.
|
||||||
# Skip the test if it does exist.
|
# Skip the test if it does exist.
|
||||||
temp_file = "micropy_test_file.txt"
|
temp_dir = "micropy_test_dir"
|
||||||
try:
|
try:
|
||||||
uos.stat(temp_file)
|
uos.stat(temp_dir)
|
||||||
print("SKIP")
|
print("SKIP")
|
||||||
raise SystemExit
|
raise SystemExit
|
||||||
except OSError:
|
except OSError:
|
||||||
@ -31,18 +31,58 @@ print(type(uos.stat("/")))
|
|||||||
# listdir and ilistdir
|
# listdir and ilistdir
|
||||||
print(type(uos.listdir("/")))
|
print(type(uos.listdir("/")))
|
||||||
|
|
||||||
|
# mkdir
|
||||||
|
uos.mkdir(temp_dir)
|
||||||
|
|
||||||
# file create
|
# file create
|
||||||
f = open(temp_file, "w")
|
f = open(temp_dir + "/test", "w")
|
||||||
f.write("hello")
|
f.write("hello")
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
# close on a closed file should succeed
|
# close on a closed file should succeed
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
|
# construct a file object using the type constructor, with a raw fileno
|
||||||
|
f = type(f)(2)
|
||||||
|
print(f)
|
||||||
|
|
||||||
# file read
|
# file read
|
||||||
f = open(temp_file, "r")
|
f = open(temp_dir + "/test", "r")
|
||||||
print(f.read())
|
print(f.read())
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
|
# rename
|
||||||
|
uos.rename(temp_dir + "/test", temp_dir + "/test2")
|
||||||
|
print(uos.listdir(temp_dir))
|
||||||
|
|
||||||
|
# construct new VfsPosix with path argument
|
||||||
|
vfs = uos.VfsPosix(temp_dir)
|
||||||
|
print(list(i[0] for i in vfs.ilistdir(".")))
|
||||||
|
|
||||||
|
# stat, statvfs
|
||||||
|
print(type(vfs.stat(".")))
|
||||||
|
print(type(vfs.statvfs(".")))
|
||||||
|
|
||||||
|
# check types of ilistdir with str/bytes arguments
|
||||||
|
print(type(list(vfs.ilistdir("."))[0][0]))
|
||||||
|
print(type(list(vfs.ilistdir(b"."))[0][0]))
|
||||||
|
|
||||||
# remove
|
# remove
|
||||||
uos.remove(temp_file)
|
uos.remove(temp_dir + "/test2")
|
||||||
|
print(uos.listdir(temp_dir))
|
||||||
|
|
||||||
|
# remove with error
|
||||||
|
try:
|
||||||
|
uos.remove(temp_dir + "/test2")
|
||||||
|
except OSError:
|
||||||
|
print("remove OSError")
|
||||||
|
|
||||||
|
# rmdir
|
||||||
|
uos.rmdir(temp_dir)
|
||||||
|
print(temp_dir in uos.listdir())
|
||||||
|
|
||||||
|
# rmdir with error
|
||||||
|
try:
|
||||||
|
uos.rmdir(temp_dir)
|
||||||
|
except OSError:
|
||||||
|
print("rmdir OSError")
|
||||||
|
@ -2,4 +2,15 @@
|
|||||||
True
|
True
|
||||||
<class 'tuple'>
|
<class 'tuple'>
|
||||||
<class 'list'>
|
<class 'list'>
|
||||||
|
<io.TextIOWrapper 2>
|
||||||
hello
|
hello
|
||||||
|
['test2']
|
||||||
|
['test2']
|
||||||
|
<class 'tuple'>
|
||||||
|
<class 'tuple'>
|
||||||
|
<class 'str'>
|
||||||
|
<class 'bytes'>
|
||||||
|
[]
|
||||||
|
remove OSError
|
||||||
|
False
|
||||||
|
rmdir OSError
|
||||||
|
Loading…
Reference in New Issue
Block a user