Add Raspberry Pi health monitoring
Co-authored-by: Copilot <[email protected]>
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
import unittest
|
||||
from types import SimpleNamespace
|
||||
from unittest.mock import patch
|
||||
|
||||
from modules import app_health
|
||||
|
||||
|
||||
class HealthParserTest(unittest.TestCase):
|
||||
def test_parses_memory_usage(self):
|
||||
memory = app_health.parse_meminfo(
|
||||
"MemTotal: 1000 kB\nMemAvailable: 250 kB\n"
|
||||
)
|
||||
|
||||
self.assertEqual(memory["total_bytes"], 1024000)
|
||||
self.assertEqual(memory["used_bytes"], 768000)
|
||||
self.assertEqual(memory["used_percent"], 75.0)
|
||||
|
||||
def test_rejects_incomplete_memory_data(self):
|
||||
with self.assertRaises(ValueError):
|
||||
app_health.parse_meminfo("MemTotal: 1000 kB\n")
|
||||
|
||||
def test_parses_current_and_historical_throttling(self):
|
||||
throttling = app_health.parse_throttled("throttled=0x50005\n")
|
||||
|
||||
self.assertEqual(throttling["raw"], "0x50005")
|
||||
self.assertEqual(
|
||||
throttling["current"], ["under_voltage", "throttled"]
|
||||
)
|
||||
self.assertEqual(
|
||||
throttling["occurred"], ["under_voltage", "throttled"]
|
||||
)
|
||||
|
||||
def test_rejects_unexpected_throttling_response(self):
|
||||
with self.assertRaises(ValueError):
|
||||
app_health.parse_throttled("unknown")
|
||||
|
||||
@patch("modules.app_health.shutil.disk_usage")
|
||||
def test_disk_percent_accounts_for_reserved_blocks(self, disk_usage):
|
||||
disk_usage.return_value = SimpleNamespace(
|
||||
total=100, used=88, free=9
|
||||
)
|
||||
|
||||
disk = app_health._disk()
|
||||
|
||||
self.assertEqual(disk["used_percent"], 90.7)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user