columba/python/conftest.py
torlando-tech 28cf53db53 test: Add comprehensive unit tests for reticulum_wrapper.py
Add 299 new tests across 10 test files to improve Python code coverage:

- conftest.py: Shared pytest fixtures for RNS/LXMF mocking
- test_wrapper_initialization.py: Constructor, bridges, config, init/shutdown
- test_wrapper_messaging.py: Message send, delivery callbacks, polling
- test_wrapper_identity.py: Identity CRUD, import/export, recovery
- test_wrapper_destination.py: Destination creation, announces
- test_wrapper_peer_identity.py: Peer identity recall/store/restore
- test_wrapper_propagation.py: Propagation node management
- test_wrapper_ble.py: BLE and RNode interface initialization
- test_wrapper_path.py: Path table, has_path, request_path
- test_wrapper_utilities.py: Debug info, echo, utility methods

All tests use pre-import mocking pattern to avoid RNS/LXMF dependencies.

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-12 22:22:10 -05:00

148 lines
3.6 KiB
Python

"""
Shared pytest fixtures for Python tests.
This module provides common test fixtures and mocks used across all Python test files.
CRITICAL: RNS and LXMF modules MUST be mocked BEFORE importing reticulum_wrapper.
"""
import sys
import os
import tempfile
import shutil
from unittest.mock import Mock, MagicMock
import pytest
# Add parent directory to path to import reticulum_wrapper
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
# Mock RNS and LXMF BEFORE importing reticulum_wrapper
# This prevents ImportError when the actual modules are not available
mock_rns = MagicMock()
mock_lxmf = MagicMock()
# Define LXMF message type constants
# These match the values in the actual LXMF library
mock_lxmf.LXMessage.OPPORTUNISTIC = 0x01
mock_lxmf.LXMessage.DIRECT = 0x02
mock_lxmf.LXMessage.PROPAGATED = 0x03
mock_lxmf.LXMessage.SENT = 0x04
# Install the mocks in sys.modules
sys.modules['RNS'] = mock_rns
sys.modules['RNS.vendor'] = MagicMock()
sys.modules['RNS.vendor.platformutils'] = MagicMock()
sys.modules['LXMF'] = mock_lxmf
# Now safe to import reticulum_wrapper
import reticulum_wrapper
@pytest.fixture
def temp_dir():
"""
Provides a temporary directory for test storage.
Automatically creates a temporary directory before the test
and cleans it up after the test completes.
Yields:
str: Path to temporary directory
"""
temp_path = tempfile.mkdtemp()
yield temp_path
# Cleanup
if os.path.exists(temp_path):
shutil.rmtree(temp_path)
@pytest.fixture
def wrapper(temp_dir):
"""
Provides an uninitialized ReticulumWrapper instance.
Args:
temp_dir: Temporary directory fixture
Returns:
ReticulumWrapper: Uninitialized wrapper instance
"""
return reticulum_wrapper.ReticulumWrapper(temp_dir)
@pytest.fixture
def initialized_wrapper(temp_dir):
"""
Provides an initialized ReticulumWrapper with mocked router and reticulum.
This fixture sets up a wrapper that appears to be fully initialized,
with mocked router and reticulum objects.
Args:
temp_dir: Temporary directory fixture
Returns:
ReticulumWrapper: Initialized wrapper with mocked dependencies
"""
wrapper = reticulum_wrapper.ReticulumWrapper(temp_dir)
wrapper.initialized = True
wrapper.router = MagicMock()
wrapper.reticulum = MagicMock()
return wrapper
@pytest.fixture
def mock_identity():
"""
Provides a mock RNS.Identity object.
Returns:
Mock: Mock identity with common attributes
"""
identity = Mock()
identity.get_public_key = Mock(return_value=b'test_public_key_32_bytes_long__')
identity.hash = b'test_identity_hash_16_b'
identity.hexhash = b'test_identity_hash_16_b'.hex()
return identity
@pytest.fixture
def mock_lxmf_message():
"""
Provides a mock LXMF message object.
Returns:
Mock: Mock LXMF message with common attributes
"""
message = MagicMock()
message.hash = b'test_message_hash_16'
message.desired_method = mock_lxmf.LXMessage.OPPORTUNISTIC
message.delivery_attempts = 0
message.try_propagation_on_fail = False
message.packed = None
message.propagation_packed = None
message.propagation_stamp = None
message.defer_propagation_stamp = False
return message
# Export mock modules for use in tests
@pytest.fixture
def mock_rns_module():
"""
Provides the mocked RNS module.
Returns:
MagicMock: The mocked RNS module
"""
return mock_rns
@pytest.fixture
def mock_lxmf_module():
"""
Provides the mocked LXMF module.
Returns:
MagicMock: The mocked LXMF module
"""
return mock_lxmf