test_thermal.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. from __future__ import annotations
  2. import pytest
  3. from hth_sdk.thermal import ThermalHTH, decode_snapshot
  4. class Backend:
  5. def __init__(self):
  6. self.targets = []
  7. self.stimuli = []
  8. def set_target(self, temperature_c):
  9. self.targets.append(temperature_c)
  10. def get_snapshot_payload(self):
  11. return bytes(193)
  12. def run_stimulus(self, duration_seconds, ptc, front, rear):
  13. self.stimuli.append((duration_seconds, list(ptc), list(front), list(rear)))
  14. def test_target_stop_and_snapshot() -> None:
  15. backend = Backend()
  16. hth = ThermalHTH(backend)
  17. hth.set_target(70)
  18. hth.stop()
  19. assert backend.targets == [70, 0]
  20. assert hth.get_snapshot().decoded["bmc_raw"] == [0] * 24
  21. def test_production_rejects_stimulus() -> None:
  22. with pytest.raises(NotImplementedError):
  23. ThermalHTH(Backend()).run_stimulus(1, [0] * 24, [0] * 4, [0] * 4)
  24. def test_identification_validates_and_runs_stimulus() -> None:
  25. backend = Backend()
  26. hth = ThermalHTH(backend, identification=True)
  27. hth.run_stimulus(2, [1] * 24, [20] * 4, [30] * 4)
  28. assert backend.stimuli[0][0] == 2
  29. def test_snapshot_length_is_exact() -> None:
  30. with pytest.raises(ValueError):
  31. decode_snapshot(bytes(192))