"""Unit tests for :func:`fiwi.fiwi_relay.host.parse_remote_readiness_stdout`."""

from __future__ import annotations

import unittest

from fiwi.fiwi_relay.host import parse_remote_readiness_stdout


class ParseRemoteReadinessStdoutTests(unittest.TestCase):
    def test_typical(self) -> None:
        text = """
noise
__FIWI_CD__=ok
__FIWI_HOSTNAME__=rpi5
__FIWI_UNAME__=Linux aarch64
__FIWI_SCRIPT__=ok
__FIWI_VENV__=yes
__FIWI_BRAINSTEM__=ok
__FIWI_BRAINSTEM_VENV__=ok
__FIWI_PY__=/home/u/Code/FiWiManager/env/bin/python3
""".strip()
        d = parse_remote_readiness_stdout(text)
        self.assertEqual(d["__FIWI_CD__"], "ok")
        self.assertEqual(d["__FIWI_SCRIPT__"], "ok")
        self.assertEqual(d["__FIWI_VENV__"], "yes")
        self.assertEqual(d["__FIWI_BRAINSTEM__"], "ok")
        self.assertEqual(d["__FIWI_HOSTNAME__"], "rpi5")
        self.assertIn("Linux", d["__FIWI_UNAME__"])

    def test_last_wins(self) -> None:
        text = "__FIWI_BRAINSTEM__=fail\n__FIWI_BRAINSTEM__=ok\n"
        d = parse_remote_readiness_stdout(text)
        self.assertEqual(d["__FIWI_BRAINSTEM__"], "ok")


if __name__ == "__main__":
    unittest.main()
