mirror of
https://github.com/ChuckBuilds/LEDMatrix.git
synced 2026-10-04 22:35:08 +00:00
fix(plugin-system): load/enable failures, atomic state files, pip lock, test-double parity (#645)
- load_plugin: an on_enable() that raises unregisters the instance, so the next load retries instead of returning True "already loaded". - get_plugin_info: guard plugin.get_info(); one plugin raising no longer breaks /api/v3/plugins/installed. - plugin_state.json and the operation history are written with atomic_write_text under their lock. - plugin_loader: module-level lock serialises pip installs across the parallel startup loaders. - store_manager._install_via_download: extract dir cleanup moved to finally. - Test doubles: draw_image() warns (DeprecationWarning; the real DisplayManager has none), MockDisplayManager.draw_text accepts the real signature's optional params, VisualTestDisplayManager logs draw errors at WARNING. - Docs/comments: compatibility.py method name, PluginState.LOADED meaning, brittle schema count, why _report_skip_once uses setdefault. - Remove unused PluginOperationQueue.get_active_operations(). Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -9,6 +9,8 @@ get_cached_data_with_strategy() and previously hit an AttributeError that
|
||||
its own broad except swallowed, producing an empty-but-green render).
|
||||
"""
|
||||
|
||||
import pytest
|
||||
|
||||
from src.plugin_system.testing.mocks import MockCacheManager
|
||||
|
||||
|
||||
@@ -43,3 +45,64 @@ class TestMockCacheManagerStrategyMethod:
|
||||
cm.get_cached_data_with_strategy("k", "sports_live")
|
||||
cm.reset()
|
||||
assert cm.get_cached_data_with_strategy_calls == []
|
||||
|
||||
|
||||
class TestDisplayDoublesMatchTheRealDisplayManager:
|
||||
"""The real DisplayManager has no draw_image(); the doubles keep it so
|
||||
existing plugin test suites still pass, but warn, because a plugin that
|
||||
calls it passes its tests and then raises AttributeError on the Pi."""
|
||||
|
||||
@staticmethod
|
||||
def _real_display_manager(monkeypatch):
|
||||
# Without EMULATOR the import needs the hardware rgbmatrix module.
|
||||
monkeypatch.setenv("EMULATOR", "true")
|
||||
from src.display_manager import DisplayManager
|
||||
return DisplayManager
|
||||
|
||||
def test_real_display_manager_has_no_draw_image(self, monkeypatch):
|
||||
DisplayManager = self._real_display_manager(monkeypatch)
|
||||
assert not hasattr(DisplayManager, 'draw_image')
|
||||
|
||||
def test_mock_draw_image_warns_and_still_records(self):
|
||||
from PIL import Image
|
||||
from src.plugin_system.testing.mocks import MockDisplayManager
|
||||
|
||||
dm = MockDisplayManager()
|
||||
with pytest.warns(DeprecationWarning, match=r"image\.paste\(img, \(x, y\)\)"):
|
||||
dm.draw_image(Image.new('RGB', (4, 4)), 1, 2)
|
||||
assert dm.draw_calls[-1]['type'] == 'image'
|
||||
|
||||
@pytest.mark.parametrize("cls_name", ["VisualTestDisplayManager", "BoundsCheckingDisplayManager"])
|
||||
def test_visual_draw_image_warns_and_still_pastes(self, cls_name):
|
||||
from PIL import Image
|
||||
import src.plugin_system.testing as testing
|
||||
|
||||
dm = getattr(testing, cls_name)(width=16, height=8)
|
||||
with pytest.warns(DeprecationWarning, match="DisplayManager has no such method"):
|
||||
dm.draw_image(Image.new('RGB', (2, 2), (0, 0, 255)), 3, 3)
|
||||
assert dm.image.getpixel((3, 3)) == (0, 0, 255)
|
||||
|
||||
def test_mock_draw_text_accepts_the_real_signature(self, monkeypatch):
|
||||
import inspect
|
||||
DisplayManager = self._real_display_manager(monkeypatch)
|
||||
from src.plugin_system.testing.mocks import MockDisplayManager
|
||||
|
||||
real = inspect.signature(DisplayManager.draw_text).parameters
|
||||
mock = inspect.signature(MockDisplayManager.draw_text).parameters
|
||||
for name, param in real.items():
|
||||
assert name in mock, name
|
||||
assert mock[name].default == param.default, name
|
||||
|
||||
dm = MockDisplayManager()
|
||||
dm.draw_text("hi", small_font=True, centered=True)
|
||||
assert dm.draw_calls[-1]['text'] == "hi"
|
||||
|
||||
def test_visual_draw_failure_is_logged_at_warning(self, caplog):
|
||||
import logging
|
||||
from src.plugin_system.testing import VisualTestDisplayManager
|
||||
|
||||
dm = VisualTestDisplayManager(width=16, height=8)
|
||||
with caplog.at_level(logging.WARNING):
|
||||
dm.draw_image(object(), 0, 0) # not an image: paste raises
|
||||
assert any(r.levelno == logging.WARNING and "Error drawing image" in r.getMessage()
|
||||
for r in caplog.records)
|
||||
|
||||
Reference in New Issue
Block a user