summaryrefslogtreecommitdiffstatshomepage
path: root/tests/extmod/vfs_fat_fileio.py
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2017-01-27 15:34:36 +1100
committerDamien George <damien.p.george@gmail.com>2017-01-27 17:21:45 +1100
commitb9bfaa349aaba4462522fd9330dbc5b21f47d906 (patch)
tree424cfabb37df485b71c4779e8b9082f50c40be51 /tests/extmod/vfs_fat_fileio.py
parentf9ecd484bbd698c0f85a3f40f391afeb01940052 (diff)
downloadmicropython-b9bfaa349aaba4462522fd9330dbc5b21f47d906.tar.gz
micropython-b9bfaa349aaba4462522fd9330dbc5b21f47d906.zip
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.
Diffstat (limited to 'tests/extmod/vfs_fat_fileio.py')
-rw-r--r--tests/extmod/vfs_fat_fileio.py37
1 files changed, 22 insertions, 15 deletions
diff --git a/tests/extmod/vfs_fat_fileio.py b/tests/extmod/vfs_fat_fileio.py
index fd84cdca8f..6fdac07102 100644
--- a/tests/extmod/vfs_fat_fileio.py
+++ b/tests/extmod/vfs_fat_fileio.py
@@ -1,7 +1,11 @@
import sys
-import uos
import uerrno
try:
+ import uos_vfs as uos
+ open = uos.vfs_open
+except ImportError:
+ import uos
+try:
uos.VfsFat
except AttributeError:
print("SKIP")
@@ -40,10 +44,12 @@ except MemoryError:
sys.exit()
uos.VfsFat.mkfs(bdev)
-vfs = uos.VfsFat(bdev, "/ramdisk")
+vfs = uos.VfsFat(bdev)
+uos.mount(vfs, '/ramdisk')
+uos.chdir('/ramdisk')
# file IO
-f = vfs.open("foo_file.txt", "w")
+f = open("foo_file.txt", "w")
print(str(f)[:17], str(f)[-1:])
f.write("hello!")
f.flush()
@@ -65,14 +71,14 @@ except OSError as e:
print(e.args[0] == uerrno.EINVAL)
try:
- vfs.open("foo_file.txt", "x")
+ open("foo_file.txt", "x")
except OSError as e:
print(e.args[0] == uerrno.EEXIST)
-with vfs.open("foo_file.txt", "a") as f:
+with open("foo_file.txt", "a") as f:
f.write("world!")
-with vfs.open("foo_file.txt") as f2:
+with open("foo_file.txt") as f2:
print(f2.read())
print(f2.tell())
@@ -90,9 +96,10 @@ with vfs.open("foo_file.txt") as f2:
print(f2.read(1))
# using constructor of FileIO type to open a file
-FileIO = type(f)
-with FileIO("/ramdisk/foo_file.txt") as f:
- print(f.read())
+# no longer working with new VFS sub-system
+#FileIO = type(f)
+#with FileIO("/ramdisk/foo_file.txt") as f:
+# print(f.read())
# dirs
vfs.mkdir("foo_dir")
@@ -123,13 +130,13 @@ except OSError as e:
print(e.args[0] == uerrno.ENOENT)
# file in dir
-with vfs.open("foo_dir/file-in-dir.txt", "w+t") as f:
+with open("foo_dir/file-in-dir.txt", "w+t") as f:
f.write("data in file")
-with vfs.open("foo_dir/file-in-dir.txt", "r+b") as f:
+with open("foo_dir/file-in-dir.txt", "r+b") as f:
print(f.read())
-with vfs.open("foo_dir/sub_file.txt", "w") as f:
+with open("foo_dir/sub_file.txt", "w") as f:
f.write("subdir file")
# directory not empty
@@ -146,11 +153,11 @@ vfs.rename("foo_dir/file.txt", "moved-to-root.txt")
print(vfs.listdir())
# check that renaming to existing file will overwrite it
-with vfs.open("temp", "w") as f:
+with open("temp", "w") as f:
f.write("new text")
vfs.rename("temp", "moved-to-root.txt")
print(vfs.listdir())
-with vfs.open("moved-to-root.txt") as f:
+with open("moved-to-root.txt") as f:
print(f.read())
# valid removes
@@ -163,7 +170,7 @@ print(vfs.listdir())
try:
bsize = vfs.statvfs("/ramdisk")[0]
free = vfs.statvfs("/ramdisk")[2] + 1
- f = vfs.open("large_file.txt", "wb")
+ f = open("large_file.txt", "wb")
f.write(bytearray(bsize * free))
except OSError as e:
print("ENOSPC:", e.args[0] == 28) # uerrno.ENOSPC