tests/extmod/vfs: Update tests to reflect new ilistdir() method.
This commit is contained in:
parent
d4cd4831b0
commit
852c215d76
@ -20,9 +20,9 @@ class Filesystem:
|
||||
print(self.id, 'mount', readonly, mkfs)
|
||||
def umount(self):
|
||||
print(self.id, 'umount')
|
||||
def listdir(self, dir):
|
||||
print(self.id, 'listdir', dir)
|
||||
return ['a%d' % self.id]
|
||||
def ilistdir(self, dir):
|
||||
print(self.id, 'ilistdir', dir)
|
||||
return iter([('a%d' % self.id, 0, 0)])
|
||||
def chdir(self, dir):
|
||||
print(self.id, 'chdir', dir)
|
||||
def getcwd(self):
|
||||
@ -64,6 +64,18 @@ print(uos.getcwd())
|
||||
uos.mount(Filesystem(1), '/test_mnt')
|
||||
print(uos.listdir())
|
||||
|
||||
# ilistdir
|
||||
i = uos.ilistdir()
|
||||
print(next(i))
|
||||
try:
|
||||
next(i)
|
||||
except StopIteration:
|
||||
print('StopIteration')
|
||||
try:
|
||||
next(i)
|
||||
except StopIteration:
|
||||
print('StopIteration')
|
||||
|
||||
# referencing the mount point in different ways
|
||||
print(uos.listdir('test_mnt'))
|
||||
print(uos.listdir('/test_mnt'))
|
||||
|
@ -2,20 +2,23 @@
|
||||
/
|
||||
1 mount False False
|
||||
['test_mnt']
|
||||
1 listdir /
|
||||
('test_mnt', 16384, 0)
|
||||
StopIteration
|
||||
StopIteration
|
||||
1 ilistdir /
|
||||
['a1']
|
||||
1 listdir /
|
||||
1 ilistdir /
|
||||
['a1']
|
||||
2 mount True False
|
||||
['test_mnt', 'test_mnt2']
|
||||
2 listdir /
|
||||
2 ilistdir /
|
||||
['a2']
|
||||
3 mount False False
|
||||
OSError
|
||||
OSError
|
||||
OSError
|
||||
1 chdir /
|
||||
1 listdir
|
||||
1 ilistdir
|
||||
['a1']
|
||||
1 getcwd
|
||||
/test_mntdir1
|
||||
@ -33,19 +36,19 @@ OSError
|
||||
2 umount
|
||||
OSError
|
||||
3 mount False False
|
||||
3 listdir /
|
||||
3 ilistdir /
|
||||
['a3']
|
||||
3 open test r
|
||||
4 mount False False
|
||||
3 listdir /
|
||||
3 ilistdir /
|
||||
['mnt', 'a3']
|
||||
4 listdir /
|
||||
4 ilistdir /
|
||||
['a4']
|
||||
4 chdir /
|
||||
4 listdir
|
||||
4 ilistdir
|
||||
['a4']
|
||||
3 chdir /subdir
|
||||
3 listdir
|
||||
3 ilistdir
|
||||
['a3']
|
||||
3 chdir /
|
||||
3 umount
|
||||
|
@ -115,4 +115,4 @@ except OSError as e:
|
||||
print(e.args[0] == 20) # uerrno.ENOTDIR
|
||||
|
||||
vfs.remove("foo_file.txt")
|
||||
print(vfs.listdir())
|
||||
print(list(vfs.ilistdir()))
|
||||
|
@ -10,4 +10,4 @@ e
|
||||
True
|
||||
d
|
||||
True
|
||||
['foo_dir']
|
||||
[('foo_dir', 16384, 0)]
|
||||
|
@ -91,23 +91,23 @@ except OSError as e:
|
||||
|
||||
# trim full path
|
||||
vfs.rename("foo_dir/file-in-dir.txt", "foo_dir/file.txt")
|
||||
print(vfs.listdir("foo_dir"))
|
||||
print(list(vfs.ilistdir("foo_dir")))
|
||||
|
||||
vfs.rename("foo_dir/file.txt", "moved-to-root.txt")
|
||||
print(vfs.listdir())
|
||||
print(list(vfs.ilistdir()))
|
||||
|
||||
# check that renaming to existing file will overwrite it
|
||||
with open("temp", "w") as f:
|
||||
f.write("new text")
|
||||
vfs.rename("temp", "moved-to-root.txt")
|
||||
print(vfs.listdir())
|
||||
print(list(vfs.ilistdir()))
|
||||
with open("moved-to-root.txt") as f:
|
||||
print(f.read())
|
||||
|
||||
# valid removes
|
||||
vfs.remove("foo_dir/sub_file.txt")
|
||||
vfs.rmdir("foo_dir")
|
||||
print(vfs.listdir())
|
||||
print(list(vfs.ilistdir()))
|
||||
|
||||
# disk full
|
||||
try:
|
||||
|
@ -3,9 +3,9 @@ True
|
||||
True
|
||||
b'data in file'
|
||||
True
|
||||
['sub_file.txt', 'file.txt']
|
||||
['foo_dir', 'moved-to-root.txt']
|
||||
['foo_dir', 'moved-to-root.txt']
|
||||
[('sub_file.txt', 32768, 0), ('file.txt', 32768, 0)]
|
||||
[('foo_dir', 16384, 0), ('moved-to-root.txt', 32768, 0)]
|
||||
[('foo_dir', 16384, 0), ('moved-to-root.txt', 32768, 0)]
|
||||
new text
|
||||
['moved-to-root.txt']
|
||||
[('moved-to-root.txt', 32768, 0)]
|
||||
ENOSPC: True
|
||||
|
@ -53,10 +53,10 @@ uos.mount(vfs, "/ramdisk")
|
||||
with vfs.open("file.txt", "w") as f:
|
||||
f.write("hello!")
|
||||
|
||||
print(vfs.listdir())
|
||||
print(list(vfs.ilistdir()))
|
||||
|
||||
with vfs.open("file.txt", "r") as f:
|
||||
print(f.read())
|
||||
|
||||
vfs.remove("file.txt")
|
||||
print(vfs.listdir())
|
||||
print(list(vfs.ilistdir()))
|
||||
|
@ -1,3 +1,3 @@
|
||||
['file.txt']
|
||||
[('file.txt', 32768, 0)]
|
||||
hello!
|
||||
[]
|
||||
|
@ -65,7 +65,7 @@ except OSError as e:
|
||||
|
||||
with vfs.open("foo_file.txt", "w") as f:
|
||||
f.write("hello!")
|
||||
print(vfs.listdir())
|
||||
print(list(vfs.ilistdir()))
|
||||
|
||||
print("stat root:", vfs.stat("/"))
|
||||
print("stat file:", vfs.stat("foo_file.txt")[:-3]) # timestamps differ across runs
|
||||
@ -76,7 +76,7 @@ print(b"hello!" in bdev.data)
|
||||
vfs.mkdir("foo_dir")
|
||||
vfs.chdir("foo_dir")
|
||||
print("getcwd:", vfs.getcwd())
|
||||
print(vfs.listdir())
|
||||
print(list(vfs.ilistdir()))
|
||||
|
||||
with vfs.open("sub_file.txt", "w") as f:
|
||||
f.write("subdir file")
|
||||
@ -92,4 +92,4 @@ print("getcwd:", vfs.getcwd())
|
||||
uos.umount(vfs)
|
||||
|
||||
vfs = uos.VfsFat(bdev)
|
||||
print(vfs.listdir(b""))
|
||||
print(list(vfs.ilistdir(b"")))
|
||||
|
@ -3,7 +3,7 @@ True
|
||||
statvfs: (512, 512, 16, 16, 16, 0, 0, 0, 0, 255)
|
||||
getcwd: /
|
||||
True
|
||||
['foo_file.txt']
|
||||
[('foo_file.txt', 32768, 0)]
|
||||
stat root: (16384, 0, 0, 0, 0, 0, 0, 0, 0, 0)
|
||||
stat file: (32768, 0, 0, 0, 0, 0, 6)
|
||||
True
|
||||
@ -12,4 +12,4 @@ getcwd: /foo_dir
|
||||
[]
|
||||
True
|
||||
getcwd: /
|
||||
[b'foo_file.txt', b'foo_dir']
|
||||
[(b'foo_file.txt', 32768, 0), (b'foo_dir', 16384, 0)]
|
||||
|
Loading…
Reference in New Issue
Block a user