mirror of
https://github.com/micropython/micropython.git
synced 2025-07-21 13:01:10 +02:00
tests/run-natmodtests.py: Allow injected code customisation.
This commit introduces a mechanism to customise the code that is injected to the board when performing a native module import. A new argument, "-b"/"--begin", is added so regular Python code can be inserted in the injected fragment between the module file creation and the effective module import. This is needed for running natmod tests on ESP8266 as that board does not have enough memory to fit certain modules unless additional configuration is performed. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
This commit is contained in:
committed by
Damien George
parent
bf2005de9e
commit
9ef7322a5d
@@ -73,6 +73,7 @@ class __FS:
|
||||
return __File()
|
||||
vfs.mount(__FS(), '/__remote')
|
||||
sys.path.insert(0, '/__remote')
|
||||
{import_prelude}
|
||||
sys.modules['{}'] = __import__('__injected')
|
||||
"""
|
||||
|
||||
@@ -133,6 +134,13 @@ def detect_architecture(target):
|
||||
|
||||
|
||||
def run_tests(target_truth, target, args, stats, resolved_arch):
|
||||
global injected_import_hook_code
|
||||
|
||||
prelude = ""
|
||||
if args.begin:
|
||||
prelude = args.begin.read()
|
||||
injected_import_hook_code = injected_import_hook_code.replace("{import_prelude}", prelude)
|
||||
|
||||
for test_file in args.files:
|
||||
# Find supported test
|
||||
test_file_basename = os.path.basename(test_file)
|
||||
@@ -212,6 +220,13 @@ def main():
|
||||
cmd_parser.add_argument(
|
||||
"-a", "--arch", choices=AVAILABLE_ARCHS, help="override native architecture of the target"
|
||||
)
|
||||
cmd_parser.add_argument(
|
||||
"-b",
|
||||
"--begin",
|
||||
type=argparse.FileType("rt"),
|
||||
default=None,
|
||||
help="prologue python file to execute before module import",
|
||||
)
|
||||
cmd_parser.add_argument("files", nargs="*", help="input test files")
|
||||
args = cmd_parser.parse_args()
|
||||
|
||||
|
Reference in New Issue
Block a user