summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJim Mussared <jim.mussared@gmail.com>2023-06-02 17:58:27 +1000
committerJim Mussared <jim.mussared@gmail.com>2023-06-08 17:54:24 +1000
commit9d7eac07138b6e02f4c0775dc70f36fdd69432a2 (patch)
tree9f041f4a10d8acc62b7c622027bcf34aa9dea9d9
parent339f02a5947e79347014b4d34adbf8a120b184bc (diff)
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: Jim Mussared <jim.mussared@gmail.com>
-rwxr-xr-xtests/run-natmodtests.py7
1 files changed, 4 insertions, 3 deletions
diff --git a/tests/run-natmodtests.py b/tests/run-natmodtests.py
index 9fe970a6d..16f8fde96 100755
--- a/tests/run-natmodtests.py
+++ b/tests/run-natmodtests.py
@@ -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