From 3f505b6043c91d3e234a91cff0f3da8e9eac3b76 Mon Sep 17 00:00:00 2001 From: "Walter A. Boring IV" Date: Fri, 28 Aug 2026 12:28:42 -0400 Subject: [PATCH] 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 --- ChangeLog.md | 2 ++ tests/client/test_client.py | 23 +++++++++++++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index 5dcacee..e5c8ef3 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -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) diff --git a/tests/client/test_client.py b/tests/client/test_client.py index 6f87424..08e169e 100644 --- a/tests/client/test_client.py +++ b/tests/client/test_client.py @@ -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)