mirror of
https://github.com/micropython/micropython.git
synced 2026-01-08 13:10:21 +01:00
tests/run-natmodtests.py: Explicitly open prelude file.
This change lets the natmod test runner report status information on session end if a prelude script file is chosen. The script serialises its input data as part of the end of session reporting data, but since the prelude file is not a serialisable object serialisation would fail (it's a file handle as far as the argument container structure is aware). Now the file is explicitly open by the script rather than relying on argparse's file handle argument class wrapper. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
This commit is contained in:
@@ -133,13 +133,6 @@ def detect_architecture(target):
|
||||
|
||||
|
||||
def run_tests(target_truth, target, args, 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)
|
||||
|
||||
test_results = []
|
||||
for test_file in args.files:
|
||||
# Find supported test
|
||||
@@ -223,6 +216,8 @@ def run_tests(target_truth, target, args, resolved_arch):
|
||||
|
||||
|
||||
def main():
|
||||
global injected_import_hook_code
|
||||
|
||||
cmd_parser = argparse.ArgumentParser(
|
||||
description="Run dynamic-native-module tests under MicroPython",
|
||||
epilog=run_tests_module.test_instance_epilog,
|
||||
@@ -240,7 +235,7 @@ def main():
|
||||
cmd_parser.add_argument(
|
||||
"-b",
|
||||
"--begin",
|
||||
type=argparse.FileType("rt"),
|
||||
metavar="PROLOGUE",
|
||||
default=None,
|
||||
help="prologue python file to execute before module import",
|
||||
)
|
||||
@@ -253,6 +248,12 @@ def main():
|
||||
cmd_parser.add_argument("files", nargs="*", help="input test files")
|
||||
args = cmd_parser.parse_args()
|
||||
|
||||
prologue = ""
|
||||
if args.begin:
|
||||
with open(args.begin, "rt") as source:
|
||||
prologue = source.read()
|
||||
injected_import_hook_code = injected_import_hook_code.replace("{import_prelude}", prologue)
|
||||
|
||||
target_truth = TargetSubprocess([CPYTHON3])
|
||||
|
||||
target = run_tests_module.get_test_instance(
|
||||
|
||||
Reference in New Issue
Block a user