提交 9d7eac07 编写于 作者: J Jim Mussared

tests/run-natmodtests.py: Don't allow imports from the cwd.

Make tests run in an isolated environment (i.e. `import io` would
otherwise get the `tests/io` directory).

This work was funded through GitHub Sponsors.
Signed-off-by: NJim Mussared <jim.mussared@gmail.com>
上级 339f02a5
......@@ -46,14 +46,14 @@ class __FS:
def chdir(self, path):
pass
def stat(self, path):
if path == '__injected.mpy':
if path == '/__injected.mpy':
return tuple(0 for _ in range(10))
else:
raise OSError(-2) # ENOENT
def open(self, path, mode):
return __File()
os.mount(__FS(), '/__remote')
os.chdir('/__remote')
sys.path.insert(0, '/__remote')
sys.modules['{}'] = __import__('__injected')
"""
......@@ -111,9 +111,10 @@ def run_tests(target_truth, target, args, stats):
test_file_data = f.read()
# Create full test with embedded .mpy
test_script = b"import sys\nsys.path.remove('')\n\n"
try:
with open(NATMOD_EXAMPLE_DIR + test_mpy, "rb") as f:
test_script = b"__buf=" + bytes(repr(f.read()), "ascii") + b"\n"
test_script += b"__buf=" + bytes(repr(f.read()), "ascii") + b"\n"
except OSError:
print("---- {} - mpy file not compiled".format(test_file))
continue
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册