Skip to content

Commit b9bfaa3

Browse files
committed
tests/extmod/vfs_fat: Update tests to work with new VFS sub-system.
The vfs_fat_fsusermount test is no longer relevant so has been removed.
1 parent f9ecd48 commit b9bfaa3

7 files changed

Lines changed: 40 additions & 137 deletions

tests/extmod/vfs_fat_fileio.py

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import sys
2-
import uos
32
import uerrno
3+
try:
4+
import uos_vfs as uos
5+
open = uos.vfs_open
6+
except ImportError:
7+
import uos
48
try:
59
uos.VfsFat
610
except AttributeError:
@@ -40,10 +44,12 @@ def ioctl(self, op, arg):
4044
sys.exit()
4145

4246
uos.VfsFat.mkfs(bdev)
43-
vfs = uos.VfsFat(bdev, "/ramdisk")
47+
vfs = uos.VfsFat(bdev)
48+
uos.mount(vfs, '/ramdisk')
49+
uos.chdir('/ramdisk')
4450

4551
# file IO
46-
f = vfs.open("foo_file.txt", "w")
52+
f = open("foo_file.txt", "w")
4753
print(str(f)[:17], str(f)[-1:])
4854
f.write("hello!")
4955
f.flush()
@@ -65,14 +71,14 @@ def ioctl(self, op, arg):
6571
print(e.args[0] == uerrno.EINVAL)
6672

6773
try:
68-
vfs.open("foo_file.txt", "x")
74+
open("foo_file.txt", "x")
6975
except OSError as e:
7076
print(e.args[0] == uerrno.EEXIST)
7177

72-
with vfs.open("foo_file.txt", "a") as f:
78+
with open("foo_file.txt", "a") as f:
7379
f.write("world!")
7480

75-
with vfs.open("foo_file.txt") as f2:
81+
with open("foo_file.txt") as f2:
7682
print(f2.read())
7783
print(f2.tell())
7884

@@ -90,9 +96,10 @@ def ioctl(self, op, arg):
9096
print(f2.read(1))
9197

9298
# using constructor of FileIO type to open a file
93-
FileIO = type(f)
94-
with FileIO("/ramdisk/foo_file.txt") as f:
95-
print(f.read())
99+
# no longer working with new VFS sub-system
100+
#FileIO = type(f)
101+
#with FileIO("/ramdisk/foo_file.txt") as f:
102+
# print(f.read())
96103

97104
# dirs
98105
vfs.mkdir("foo_dir")
@@ -123,13 +130,13 @@ def ioctl(self, op, arg):
123130
print(e.args[0] == uerrno.ENOENT)
124131

125132
# file in dir
126-
with vfs.open("foo_dir/file-in-dir.txt", "w+t") as f:
133+
with open("foo_dir/file-in-dir.txt", "w+t") as f:
127134
f.write("data in file")
128135

129-
with vfs.open("foo_dir/file-in-dir.txt", "r+b") as f:
136+
with open("foo_dir/file-in-dir.txt", "r+b") as f:
130137
print(f.read())
131138

132-
with vfs.open("foo_dir/sub_file.txt", "w") as f:
139+
with open("foo_dir/sub_file.txt", "w") as f:
133140
f.write("subdir file")
134141

135142
# directory not empty
@@ -146,11 +153,11 @@ def ioctl(self, op, arg):
146153
print(vfs.listdir())
147154

148155
# check that renaming to existing file will overwrite it
149-
with vfs.open("temp", "w") as f:
156+
with open("temp", "w") as f:
150157
f.write("new text")
151158
vfs.rename("temp", "moved-to-root.txt")
152159
print(vfs.listdir())
153-
with vfs.open("moved-to-root.txt") as f:
160+
with open("moved-to-root.txt") as f:
154161
print(f.read())
155162

156163
# valid removes
@@ -163,7 +170,7 @@ def ioctl(self, op, arg):
163170
try:
164171
bsize = vfs.statvfs("/ramdisk")[0]
165172
free = vfs.statvfs("/ramdisk")[2] + 1
166-
f = vfs.open("large_file.txt", "wb")
173+
f = open("large_file.txt", "wb")
167174
f.write(bytearray(bsize * free))
168175
except OSError as e:
169176
print("ENOSPC:", e.args[0] == 28) # uerrno.ENOSPC

tests/extmod/vfs_fat_fileio.py.exp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ h
99
e
1010
True
1111
d
12-
hello!world!
1312
True
1413
True
1514
True

tests/extmod/vfs_fat_fsusermount.py

Lines changed: 0 additions & 97 deletions
This file was deleted.

tests/extmod/vfs_fat_fsusermount.py.exp

Lines changed: 0 additions & 6 deletions
This file was deleted.

tests/extmod/vfs_fat_oldproto.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import sys
2-
import uos
32
import uerrno
3+
try:
4+
import uos_vfs as uos
5+
except ImportError:
6+
import uos
47
try:
58
uos.VfsFat
6-
uos.vfs_mkfs
7-
uos.vfs_mount
89
except AttributeError:
910
print("SKIP")
1011
sys.exit()
@@ -39,11 +40,11 @@ def count(self):
3940
print("SKIP")
4041
sys.exit()
4142

42-
uos.vfs_mkfs(bdev, "/ramdisk")
43-
uos.vfs_mount(bdev, "/ramdisk")
43+
uos.VfsFat.mkfs(bdev)
44+
vfs = uos.VfsFat(bdev)
45+
uos.mount(vfs, "/ramdisk")
4446

4547
# file io
46-
vfs = uos.VfsFat(bdev, "/ramdisk")
4748
with vfs.open("file.txt", "w") as f:
4849
f.write("hello!")
4950

@@ -54,6 +55,3 @@ def count(self):
5455

5556
vfs.remove("file.txt")
5657
print(vfs.listdir())
57-
58-
# umount by device
59-
uos.vfs_umount(bdev)

tests/extmod/vfs_fat_ramdisk.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import sys
2-
import uos
32
import uerrno
3+
try:
4+
import uos_vfs as uos
5+
except ImportError:
6+
import uos
47
try:
58
uos.VfsFat
69
except AttributeError:
@@ -44,7 +47,8 @@ def ioctl(self, op, arg):
4447
print(b"FOO_FILETXT" not in bdev.data)
4548
print(b"hello!" not in bdev.data)
4649

47-
vfs = uos.VfsFat(bdev, "/ramdisk")
50+
vfs = uos.VfsFat(bdev)
51+
uos.mount(vfs, "/ramdisk")
4852

4953
print("statvfs:", vfs.statvfs("/ramdisk"))
5054
print("getcwd:", vfs.getcwd())
@@ -59,7 +63,6 @@ def ioctl(self, op, arg):
5963
print(vfs.listdir())
6064

6165
print("stat root:", vfs.stat("/"))
62-
print("stat disk:", vfs.stat("/ramdisk/"))
6366
print("stat file:", vfs.stat("foo_file.txt"))
6467

6568
print(b"FOO_FILETXT" in bdev.data)
@@ -81,7 +84,7 @@ def ioctl(self, op, arg):
8184
vfs.chdir("..")
8285
print("getcwd:", vfs.getcwd())
8386

84-
vfs.umount()
87+
uos.umount(vfs)
8588

86-
vfs = uos.VfsFat(bdev, "/ramdisk")
89+
vfs = uos.VfsFat(bdev)
8790
print(vfs.listdir(b""))
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
True
22
True
33
statvfs: (512, 512, 16, 16, 16, 0, 0, 0, 0, 255)
4-
getcwd: /ramdisk
4+
getcwd: /
55
True
66
['foo_file.txt']
77
stat root: (16384, 0, 0, 0, 0, 0, 0, 0, 0, 0)
8-
stat disk: (16384, 0, 0, 0, 0, 0, 0, 0, 0, 0)
98
stat file: (32768, 0, 0, 0, 0, 0, 6, -631238400, -631238400, -631238400)
109
True
1110
True
12-
getcwd: /ramdisk/foo_dir
11+
getcwd: /foo_dir
1312
[]
1413
True
15-
getcwd: /ramdisk
14+
getcwd: /
1615
[b'foo_file.txt', b'foo_dir']

0 commit comments

Comments
 (0)