fix: patch RNS.log in BLEInterface module's namespace

The previous patch changed RNS.log in the test's namespace, but
BLEInterface.py imports RNS at module load time. To capture log
calls from _address_changed_callback(), we need to patch RNS.log
where it's used: ble_reticulum.BLEInterface.RNS.log

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
torlando-tech 2025-12-30 14:59:28 -05:00
commit e30a73fd1b

View file

@ -339,11 +339,15 @@ class TestAddressChangedCallback:
assert old_mac not in ble_interface.address_to_identity
assert old_mac not in ble_interface._identity_cache
# Patch RNS.log at module level to capture calls
import RNS
original_log = RNS.log
# Patch RNS.log in the BLEInterface module's namespace
from ble_reticulum import BLEInterface as ble_module
log_calls = []
RNS.log = lambda msg, level=4: log_calls.append((msg, level))
def capture_log(msg, level=4):
log_calls.append((msg, level))
original_log = ble_module.RNS.log
ble_module.RNS.log = capture_log
try:
# Call address changed callback - should not crash
@ -354,7 +358,7 @@ class TestAddressChangedCallback:
assert any("no identity found" in str(msg).lower() for msg, level in log_calls), \
f"Expected 'no identity found' warning, got: {log_calls}"
finally:
RNS.log = original_log
ble_module.RNS.log = original_log
class TestCacheTTL: