mirror of
https://github.com/micropython/micropython.git
synced 2025-12-16 09:50:15 +01:00
tests/run-tests.py: Raise OSError on invalid file open for injected FS.
This makes sure that `open()` raises `OSError(ENOENT)` if the test script attempts to open a file that does not exist. For example, the test `tests/ports/esp32/check_err_str.py` attempts to do this and this test currently fails when run with `--via-mpy` because the injected filesystem lets a file by any name be opened. The fix here tries to be as minimal as possible, so includes a size optimisation for `stat()` to use a fixed 10-tuple. It also fixes the `OSError` argument, which should be positive. Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
@@ -88,10 +88,11 @@ class __FS:
|
|||||||
return ""
|
return ""
|
||||||
def stat(self, path):
|
def stat(self, path):
|
||||||
if path == '__injected_test.mpy':
|
if path == '__injected_test.mpy':
|
||||||
return tuple(0 for _ in range(10))
|
return (0,0,0,0,0,0,0,0,0,0)
|
||||||
else:
|
else:
|
||||||
raise OSError(-2) # ENOENT
|
raise OSError(2) # ENOENT
|
||||||
def open(self, path, mode):
|
def open(self, path, mode):
|
||||||
|
self.stat(path)
|
||||||
return __File()
|
return __File()
|
||||||
vfs.mount(__FS(), '/__vfstest')
|
vfs.mount(__FS(), '/__vfstest')
|
||||||
os.chdir('/__vfstest')
|
os.chdir('/__vfstest')
|
||||||
|
|||||||
Reference in New Issue
Block a user