summaryrefslogtreecommitdiff
path: root/tests/micropython/import_mpy_invalid.py
diff options
context:
space:
mode:
authorDamien George <damien@micropython.org>2020-07-26 14:43:13 +1000
committerDamien George <damien@micropython.org>2020-07-26 22:44:59 +1000
commit8da40baa47ee9fe7aac228af2c0addd1f4ce3646 (patch)
tree5ab14a02a0fddb61f863ed49403d47d4e9df9840 /tests/micropython/import_mpy_invalid.py
parent0c0cef9870e8215d67c79fefa6582849842001f9 (diff)
tests/micropython: Improve .mpy import tests to run on more targets.
All imports are now tested to see if the test should be skipped, UserFile.read is removed, and UserFile.readinto is made more efficient. Signed-off-by: Damien George <damien@micropython.org>
Diffstat (limited to 'tests/micropython/import_mpy_invalid.py')
-rw-r--r--tests/micropython/import_mpy_invalid.py19
1 files changed, 6 insertions, 13 deletions
diff --git a/tests/micropython/import_mpy_invalid.py b/tests/micropython/import_mpy_invalid.py
index d6d01e7f1..00973fe3f 100644
--- a/tests/micropython/import_mpy_invalid.py
+++ b/tests/micropython/import_mpy_invalid.py
@@ -1,11 +1,9 @@
# test importing of invalid .mpy files
-import sys, uio
-
try:
- uio.IOBase
- import uos
+ import sys, uio, uos
+ uio.IOBase
uos.mount
except (ImportError, AttributeError):
print("SKIP")
@@ -14,18 +12,13 @@ except (ImportError, AttributeError):
class UserFile(uio.IOBase):
def __init__(self, data):
- self.data = data
+ self.data = memoryview(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):
- buf[n] = self.data[self.pos]
- n += 1
- self.pos += 1
+ n = min(len(buf), len(self.data) - self.pos)
+ buf[:n] = self.data[self.pos : self.pos + n]
+ self.pos += n
return n
def ioctl(self, req, arg):