diff options
Diffstat (limited to 'tests/import/mpy_native.py')
-rw-r--r-- | tests/import/mpy_native.py | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/tests/import/mpy_native.py b/tests/import/mpy_native.py index 4ee537f4a..5d7bdab4a 100644 --- a/tests/import/mpy_native.py +++ b/tests/import/mpy_native.py @@ -5,12 +5,13 @@ import sys, uio try: uio.IOBase import uos + uos.mount except (ImportError, AttributeError): print("SKIP") raise SystemExit -if not (sys.platform == 'linux' and sys.maxsize > 2 ** 32): +if not (sys.platform == "linux" and sys.maxsize > 2 ** 32): print("SKIP") raise SystemExit @@ -19,8 +20,10 @@ class UserFile(uio.IOBase): def __init__(self, data): self.data = data self.pos = 0 + def read(self): return self.data + def readinto(self, buf): n = 0 while n < len(buf) and self.pos < len(self.data): @@ -28,6 +31,7 @@ class UserFile(uio.IOBase): n += 1 self.pos += 1 return n + def ioctl(self, req, arg): return 0 @@ -35,19 +39,24 @@ class UserFile(uio.IOBase): class UserFS: def __init__(self, files): self.files = files + def mount(self, readonly, mksfs): pass + def umount(self): pass + def stat(self, path): if path in self.files: return (32768, 0, 0, 0, 0, 0, 0, 0, 0, 0) raise OSError + def open(self, path, mode): return UserFile(self.files[path]) # these are the test .mpy files +# fmt: off user_files = { # bad architecture '/mod0.mpy': b'M\x05\xff\x00\x10', @@ -95,20 +104,21 @@ user_files = { b'\x03\x01\x00' # dummy relocation of rodata ), } +# fmt: on # create and mount a user filesystem -uos.mount(UserFS(user_files), '/userfs') -sys.path.append('/userfs') +uos.mount(UserFS(user_files), "/userfs") +sys.path.append("/userfs") # import .mpy files from the user filesystem for i in range(len(user_files)): - mod = 'mod%u' % i + mod = "mod%u" % i try: __import__(mod) - print(mod, 'OK') + print(mod, "OK") except ValueError as er: - print(mod, 'ValueError', er) + print(mod, "ValueError", er) # unmount and undo path addition -uos.umount('/userfs') +uos.umount("/userfs") sys.path.pop() |