summaryrefslogtreecommitdiff
path: root/test.py
blob: d0c4a852a6f8d74889db5710d4b4225a02b74248 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
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()