- add /api/gps/status for thread/fix-age visibility - surface GPS status in Pi health and live GPS cards - add tests for app_gps status snapshots Co-authored-by: Copilot <[email protected]>
60 lines
2.0 KiB
Python
60 lines
2.0 KiB
Python
import types
|
|
import unittest
|
|
from unittest.mock import patch
|
|
|
|
from modules import app_gps
|
|
|
|
|
|
class GpsStatusTest(unittest.TestCase):
|
|
def test_get_status_without_fix(self):
|
|
original_thread = app_gps._gps_thread
|
|
original_lat = app_gps.LocationX
|
|
original_lon = app_gps.LocationY
|
|
original_last_fix = app_gps.last_fix_at
|
|
try:
|
|
app_gps._gps_thread = None
|
|
app_gps.LocationX = None
|
|
app_gps.LocationY = None
|
|
app_gps.last_fix_at = None
|
|
|
|
status = app_gps.get_status()
|
|
|
|
self.assertFalse(status["thread_alive"])
|
|
self.assertFalse(status["has_fix"])
|
|
self.assertIsNone(status["fix_age_seconds"])
|
|
finally:
|
|
app_gps._gps_thread = original_thread
|
|
app_gps.LocationX = original_lat
|
|
app_gps.LocationY = original_lon
|
|
app_gps.last_fix_at = original_last_fix
|
|
|
|
@patch("modules.app_gps.get_fix_age", return_value=12.5)
|
|
def test_get_status_with_fix(self, get_fix_age):
|
|
original_thread = app_gps._gps_thread
|
|
original_lat = app_gps.LocationX
|
|
original_lon = app_gps.LocationY
|
|
original_last_fix = app_gps.last_fix_at
|
|
try:
|
|
app_gps._gps_thread = types.SimpleNamespace(is_alive=lambda: True)
|
|
app_gps.LocationX = "45.5017"
|
|
app_gps.LocationY = "-73.5673"
|
|
app_gps.last_fix_at = 1.0
|
|
|
|
status = app_gps.get_status()
|
|
|
|
self.assertTrue(status["thread_alive"])
|
|
self.assertTrue(status["has_fix"])
|
|
self.assertEqual(status["latitude"], "45.5017")
|
|
self.assertEqual(status["longitude"], "-73.5673")
|
|
self.assertEqual(status["fix_age_seconds"], 12.5)
|
|
get_fix_age.assert_called_once_with()
|
|
finally:
|
|
app_gps._gps_thread = original_thread
|
|
app_gps.LocationX = original_lat
|
|
app_gps.LocationY = original_lon
|
|
app_gps.last_fix_at = original_last_fix
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|