tests: Format all Python code with black, except tests in basics subdir.

This adds the Python files in the tests/ directory to be formatted with
./tools/codeformat.py.  The basics/ subdirectory is excluded for now so we
aren't changing too much at once.

In a few places `# fmt: off`/`# fmt: on` was used where the code had
special formatting for readability or where the test was actually testing
the specific formatting.
This commit is contained in:
David Lechner
2020-03-22 21:26:08 -05:00
committed by Damien George
parent 488613bca6
commit 3dc324d3f1
472 changed files with 4396 additions and 2891 deletions

View File

@@ -2,12 +2,14 @@
try:
import uos
uos.VfsLfs1
uos.VfsLfs2
except (ImportError, AttributeError):
print("SKIP")
raise SystemExit
class RAMBlockDevice:
ERASE_BLOCK_SIZE = 1024
@@ -25,92 +27,94 @@ class RAMBlockDevice:
self.data[addr + i] = buf[i]
def ioctl(self, op, arg):
if op == 4: # block count
if op == 4: # block count
return len(self.data) // self.ERASE_BLOCK_SIZE
if op == 5: # block size
if op == 5: # block size
return self.ERASE_BLOCK_SIZE
if op == 6: # erase block
if op == 6: # erase block
return 0
def test(bdev, vfs_class):
print('test', vfs_class)
print("test", vfs_class)
# mkfs with too-small block device
try:
vfs_class.mkfs(RAMBlockDevice(1))
except OSError:
print('mkfs OSError')
print("mkfs OSError")
# mount with invalid filesystem
try:
vfs_class(bdev)
except OSError:
print('mount OSError')
print("mount OSError")
# set up for following tests
vfs_class.mkfs(bdev)
vfs = vfs_class(bdev)
with vfs.open('testfile', 'w') as f:
f.write('test')
vfs.mkdir('testdir')
with vfs.open("testfile", "w") as f:
f.write("test")
vfs.mkdir("testdir")
# ilistdir
try:
vfs.ilistdir('noexist')
vfs.ilistdir("noexist")
except OSError:
print('ilistdir OSError')
print("ilistdir OSError")
# remove
try:
vfs.remove('noexist')
vfs.remove("noexist")
except OSError:
print('remove OSError')
print("remove OSError")
# rmdir
try:
vfs.rmdir('noexist')
vfs.rmdir("noexist")
except OSError:
print('rmdir OSError')
print("rmdir OSError")
# rename
try:
vfs.rename('noexist', 'somethingelse')
vfs.rename("noexist", "somethingelse")
except OSError:
print('rename OSError')
print("rename OSError")
# mkdir
try:
vfs.mkdir('testdir')
vfs.mkdir("testdir")
except OSError:
print('mkdir OSError')
print("mkdir OSError")
# chdir to nonexistent
try:
vfs.chdir('noexist')
vfs.chdir("noexist")
except OSError:
print('chdir OSError')
print(vfs.getcwd()) # check still at root
print("chdir OSError")
print(vfs.getcwd()) # check still at root
# chdir to file
try:
vfs.chdir('testfile')
vfs.chdir("testfile")
except OSError:
print('chdir OSError')
print(vfs.getcwd()) # check still at root
print("chdir OSError")
print(vfs.getcwd()) # check still at root
# stat
try:
vfs.stat('noexist')
vfs.stat("noexist")
except OSError:
print('stat OSError')
print("stat OSError")
# error during seek
with vfs.open('testfile', 'r') as f:
f.seek(1 << 30) # SEEK_SET
with vfs.open("testfile", "r") as f:
f.seek(1 << 30) # SEEK_SET
try:
f.seek(1 << 30, 1) # SEEK_CUR
f.seek(1 << 30, 1) # SEEK_CUR
except OSError:
print('seek OSError')
print("seek OSError")
bdev = RAMBlockDevice(30)
test(bdev, uos.VfsLfs1)