"""Tests for the M8 alert monitor (edge-triggered; notify mocked).""" import unittest from unittest import mock from rigdoctor.core import alerts from rigdoctor.core.sample import Reading, Sample def _gpu(temp): return Sample(readings=[Reading("gpu", "temp", temp, "°C")]) class AlertTests(unittest.TestCase): @mock.patch.object(alerts, "notify") def test_edge_triggered_no_repeat(self, m): mon = alerts.AlertMonitor(gpu_temp=90.0, cooldown=0.0) mon.check(_gpu(95)) # fires mon.check(_gpu(96)) # still hot — no repeat while active self.assertEqual(m.call_count, 1) mon.check(_gpu(50)) # clears mon.check(_gpu(95)) # hot again — fires self.assertEqual(m.call_count, 2) @mock.patch.object(alerts, "notify") def test_no_alert_below_threshold(self, m): alerts.AlertMonitor(gpu_temp=90.0).check(_gpu(70)) m.assert_not_called() @mock.patch.object(alerts, "notify") def test_gpu_lost(self, m): mon = alerts.AlertMonitor() mon.check(Sample(readings=[Reading("gpu", "status", None, "", "query-timeout")])) m.assert_called_once() if __name__ == "__main__": unittest.main()