mirror of
https://github.com/ChuckBuilds/LEDMatrix.git
synced 2026-05-15 10:03:31 +00:00
Remove unused imports across 86 files in src/, web_interface/, test/, and scripts/ using autoflake. No logic changes — only dead import statements and unused names in from-imports are removed. Also remove bare exception aliases where the variable is never referenced in the handler body: - src/cache/disk_cache.py: except (IOError, OSError, PermissionError) as e - src/cache_manager.py: except (OSError, IOError, PermissionError) as perm_error - src/plugin_system/resource_monitor.py: except Exception as e - web_interface/app.py: except Exception as read_err 86 files changed, 205 lines removed, 18 pre-existing test failures unchanged. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
120 lines
4.5 KiB
Python
120 lines
4.5 KiB
Python
import pytest
|
|
from unittest.mock import MagicMock, patch
|
|
from PIL import ImageDraw
|
|
from src.display_manager import DisplayManager
|
|
|
|
@pytest.fixture
|
|
def mock_rgb_matrix():
|
|
"""Mock the rgbmatrix library."""
|
|
with patch('src.display_manager.RGBMatrix') as mock_matrix, \
|
|
patch('src.display_manager.RGBMatrixOptions') as mock_options, \
|
|
patch('src.display_manager.freetype'):
|
|
|
|
# Setup matrix instance mock
|
|
matrix_instance = MagicMock()
|
|
matrix_instance.width = 128
|
|
matrix_instance.height = 32
|
|
matrix_instance.CreateFrameCanvas.return_value = MagicMock()
|
|
matrix_instance.Clear = MagicMock()
|
|
matrix_instance.SetImage = MagicMock()
|
|
mock_matrix.return_value = matrix_instance
|
|
|
|
yield {
|
|
'matrix_class': mock_matrix,
|
|
'options_class': mock_options,
|
|
'matrix_instance': matrix_instance
|
|
}
|
|
|
|
class TestDisplayManagerInitialization:
|
|
"""Test DisplayManager initialization."""
|
|
|
|
def test_init_hardware_mode(self, test_config, mock_rgb_matrix):
|
|
"""Test initialization in hardware mode."""
|
|
# Ensure EMULATOR env var is not set
|
|
with patch.dict('os.environ', {'EMULATOR': 'false'}):
|
|
dm = DisplayManager(test_config)
|
|
|
|
assert dm.width == 128
|
|
assert dm.height == 32
|
|
assert dm.matrix is not None
|
|
|
|
# Verify options were set correctly
|
|
mock_rgb_matrix['options_class'].assert_called()
|
|
options = mock_rgb_matrix['options_class'].return_value
|
|
assert options.rows == 32
|
|
assert options.cols == 64
|
|
assert options.chain_length == 2
|
|
|
|
def test_init_emulator_mode(self, test_config):
|
|
"""Test initialization in emulator mode."""
|
|
# Set EMULATOR env var and patch the import
|
|
with patch.dict('os.environ', {'EMULATOR': 'true'}), \
|
|
patch('src.display_manager.RGBMatrix') as mock_matrix, \
|
|
patch('src.display_manager.RGBMatrixOptions') as mock_options:
|
|
|
|
# Setup matrix instance
|
|
matrix_instance = MagicMock()
|
|
matrix_instance.width = 128
|
|
matrix_instance.height = 32
|
|
mock_matrix.return_value = matrix_instance
|
|
|
|
dm = DisplayManager(test_config)
|
|
|
|
assert dm.width == 128
|
|
assert dm.height == 32
|
|
mock_matrix.assert_called()
|
|
|
|
|
|
class TestDisplayManagerDrawing:
|
|
"""Test drawing operations."""
|
|
|
|
def test_clear(self, test_config, mock_rgb_matrix):
|
|
"""Test clear operation."""
|
|
with patch.dict('os.environ', {'EMULATOR': 'false'}):
|
|
dm = DisplayManager(test_config)
|
|
dm.clear()
|
|
# clear() calls Clear() multiple times (offscreen_canvas, current_canvas, matrix)
|
|
assert dm.matrix.Clear.called
|
|
|
|
def test_draw_text(self, test_config, mock_rgb_matrix):
|
|
"""Test text drawing."""
|
|
with patch.dict('os.environ', {'EMULATOR': 'false'}):
|
|
dm = DisplayManager(test_config)
|
|
|
|
# Mock font
|
|
font = MagicMock()
|
|
|
|
dm.draw_text("Test", 0, 0, font)
|
|
|
|
# Verify draw_text was called (DisplayManager uses freetype/PIL)
|
|
# The actual implementation uses freetype or PIL, not graphics module
|
|
assert True # draw_text should execute without error
|
|
|
|
def test_draw_image(self, test_config, mock_rgb_matrix):
|
|
"""Test image drawing."""
|
|
with patch.dict('os.environ', {'EMULATOR': 'false'}):
|
|
dm = DisplayManager(test_config)
|
|
|
|
# DisplayManager doesn't have draw_image method
|
|
# It uses SetImage on canvas in update_display()
|
|
# Just verify DisplayManager can handle image operations
|
|
from PIL import Image
|
|
test_image = Image.new('RGB', (64, 32))
|
|
dm.image = test_image
|
|
dm.draw = ImageDraw.Draw(dm.image)
|
|
|
|
# Verify image was set
|
|
assert dm.image is not None
|
|
|
|
|
|
class TestDisplayManagerResourceManagement:
|
|
"""Test resource management."""
|
|
|
|
def test_cleanup(self, test_config, mock_rgb_matrix):
|
|
"""Test cleanup operation."""
|
|
with patch.dict('os.environ', {'EMULATOR': 'false'}):
|
|
dm = DisplayManager(test_config)
|
|
dm.cleanup()
|
|
|
|
dm.matrix.Clear.assert_called()
|