From 82e576c77a6512e402b9e732b8a0503a22a0cfa0 Mon Sep 17 00:00:00 2001 From: xengineering Date: Sat, 2 Aug 2025 14:52:35 +0200 Subject: Add `test.py` script This script simplifies running tests from this repository. --- test.py | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100755 test.py diff --git a/test.py b/test.py new file mode 100755 index 0000000..d0c4a85 --- /dev/null +++ b/test.py @@ -0,0 +1,80 @@ +#!/usr/bin/env python3 + + +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at https://mozilla.org/MPL/2.0/. + + +import argparse +import dataclasses +import os +import pathlib +import subprocess + + +SCRIPT = pathlib.Path(__file__) +IOT_CONTACT_GO = SCRIPT.parent +NATIVE_SIM_FIRMWARE_DEFAULT = ( + IOT_CONTACT_GO.parent + / "iot-contact" + / "build" + / "fw" + / "sim" + / "build" + / "zephyr" + / "zephyr.exe" +) + + +def main() -> None: + args = Arguments.from_cli() + + env = os.environ.copy() + env["IOT_CONTACT_NATIVE_SIM_FIRMWARE"] = str(args.native_sim_firmware) + + subprocess.run( + [ + "go", + "test", + "-v", + "--count=1", + "./...", + ], + shell=False, + check=True, + cwd=str(IOT_CONTACT_GO), + env=env, + ) + + +@dataclasses.dataclass(frozen=True, kw_only=True) +class Arguments: + + native_sim_firmware: pathlib.Path + + def __post_init__(self) -> None: + assert isinstance(self.native_sim_firmware, pathlib.Path) + assert self.native_sim_firmware.is_file() + + @staticmethod + def from_cli() -> "Arguments": + parser = argparse.ArgumentParser() + + parser.add_argument( + "-n", + "--native-sim", + type=pathlib.Path, + default=pathlib.Path(NATIVE_SIM_FIRMWARE_DEFAULT), + help="path to iot-contact native sim firmware", + ) + + args = parser.parse_args() + + return Arguments( + native_sim_firmware=args.native_sim.absolute(), + ) + + +if __name__ == "__main__": + main() -- cgit v1.2.3-70-g09d2