test: add unit tests for APRSDClient._checks initialisation (#238 follow-up) (#257)

- test_checks_initialised_to_false: asserts _checks is False right after
  __init__, catching any regression that removes the initialisation
- test_keepalive_check_first_call_no_reset: verifies no AttributeError and
  no spurious reset on the very first keepalive_check() call even when the
  driver is already dead
- test_keepalive_check: remove the manual _checks = False setup that masked
  the original bug; rely on the __init__ value instead
This commit is contained in:
2026-08-28 12:28:42 -04:00
committed by GitHub
parent f9d27208f0
commit 3f505b6043
2 changed files with 23 additions and 2 deletions
+2
View File
@@ -8,6 +8,8 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
##### Bug Fixes
- Add tests for APRSDClient._checks initialisation and first-call keepalive behaviour [`20da2ad`](https://github.com/craigerl/aprsd/commit/20da2ad)
- Fix APRSDClient._checks AttributeError on first keepalive_check() call — initialise to False in __init__ [`52e1346`](https://github.com/craigerl/aprsd/commit/52e1346)
- Fix APRSISDriver.is_configured() always returning True when driver is disabled [`a9ef65f`](https://github.com/craigerl/aprsd/commit/a9ef65f)
+21 -2
View File
@@ -347,13 +347,32 @@ class TestAPRSDClient(unittest.TestCase):
result = client.decode_packet(frame='test')
self.assertIsNone(result)
def test_checks_initialised_to_false(self):
"""_checks must be False right after __init__ — no AttributeError on first keepalive."""
client = APRSDClient(auto_connect=False)
self.assertFalse(
client._checks,
'_checks should be initialised to False in __init__',
)
def test_keepalive_check_first_call_no_reset(self):
"""First keepalive_check() call must never reset regardless of driver state."""
client = APRSDClient(auto_connect=False)
self.mock_driver._alive = False # driver is dead, but _checks is False
with mock.patch.object(client, 'reset') as mock_reset:
# Should not raise AttributeError, and should not reset on first call
client.keepalive_check()
mock_reset.assert_not_called()
self.assertTrue(client._checks)
def test_keepalive_check(self):
"""Test keepalive_check() method."""
client = APRSDClient(auto_connect=False)
client._checks = False
self.mock_driver._alive = True
# First check should not reset
# First check should not reset (driver alive, _checks False → no reset)
with mock.patch.object(client, 'reset') as mock_reset:
client.keepalive_check()
self.assertTrue(client._checks)