refactor: delete dead Python code in the core (and stop storing Wi-Fi passwords) (#608)

* refactor(plugins): remove the no-op PluginHealthMonitor

Its monitor loop did nothing (`if callbacks: pass`), register_health_check
had no callers and api_v3.health_monitor was never read by any route. The
live health data comes from PluginHealthTracker, which is untouched.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* refactor(store): drop the never-set uninstall tombstones

Nothing in production called mark_recently_uninstalled, so the
reconciler's was_recently_uninstalled check was always False. The
persistent uninstall registry is what actually stops resurrection; the
reconciler test now exercises that gate instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* refactor(common): delete unused config/display/game helpers, utils and error_handler

Nothing in core, the web UI, scripts or the plugin monorepo imports
config_helper, display_helper, game_helper, utils or error_handler; only
their own tests did. The error_handler re-exports leave src.common's
__all__; APIHelper, TextHelper, ScrollHelper, LogoHelper and the adaptive
layout exports are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* refactor(config): drop ConfigService's unused versioning and save API

ConfigVersion, get_version/get_version_history/get_version_config,
rollback, save_config, reload, get_plugin_config and the backward-compat
load_config/get_config_path/get_secrets_path had no callers. The display
controller only uses get_config, subscribe, unsubscribe and shutdown,
plus the file watcher. Change detection now compares against the
current checksum instead of the last history entry.

The subscriber tests asserted `callback.called or True`; they now
reload the way the watcher does and assert the notification.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* refactor(plugins): drop unread plugin state history and callbacks

plugin_state.PluginStateManager kept a bounded per-plugin transition
history that only get_state_history (tests only) read; get_state_info
reports a separate lifetime count, which stays. set_error_info and
record_display had no callers, and set_state_with_error's `error`
argument only fed the history.

The web-side state_manager.PluginStateManager loses
subscribe_to_state_changes, _notify_callbacks, set_plugin_error and
get_state_version, none of which had callers; with no subscribers the
old-state copy in update_plugin_state went with them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* refactor(plugins): remove unused PluginManager methods and attribute guards

update_all_plugins was only called by a test (the display loop uses
run_scheduled_updates); get_plugin_health_metrics,
get_plugin_resource_metrics and get_plugin_state had no callers; and
plugin_modules was written but never read. plugin_directories is now
initialised in __init__, so the hasattr() guards around it go.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* refactor(plugins): remove unused executor, loader, store and package helpers

- PluginExecutor.execute_safe: no callers.
- PluginLoader._parse_semver: only its own tests; compatibility.parse_semver
  is the live copy and test_compatibility.py already covers it.
- PluginStoreManager.get_installed_plugin_info: no callers.
- PluginResourceMonitor._local: never read.
- src.plugin_system.get_store_manager and __api_version__: no importers in
  core, scripts or the plugin monorepo.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(wifi): stop storing Wi-Fi passwords in wifi_config.json

WiFiManager appended every joined network's SSID and password, in
plaintext, to saved_networks in config/wifi_config.json, and nothing
(web UI, backup restore, scripts) ever read them back: NetworkManager
keeps its own credentials. The writes are gone, and loading the config
now drops any saved_networks key and rewrites the file, so passwords
already on disk are scrubbed.

Also removes _check_dnsmasq_conflict (never called) and _detect_trixie,
whose result only reached one log line, along with the
NM_CONNECTIONS_PATHS constant only it used.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* refactor(display): remove unreachable and unused DisplayController code

- _follower_rebuild_scroll_image: never called.
- mode_duration (never read) and last_mode_change (write-only).
- The `chosen_cap <= 0` branch: chosen_cap is either the minimum of
  caps already filtered to > 0 or DEFAULT_DYNAMIC_DURATION_CAP (180).
- The `max_duration < min_duration` branch directly after
  `max_duration = max(min_duration, max_duration)`.
- The circuit-breaker branch's `display_result = False` and
  `manager_to_display = None`: the first is overwritten a few lines
  later, the second is already None there.
- The bool-to-bool conversion of execute_display's result, which is
  always a bool.
- The `loaded_plugins` lookup in _update_modules: PluginManager has no
  such attribute, so it always fell through to `plugins`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* refactor(vegas): remove unused config update, boundary finder and refresh

VegasModeConfig.update had no callers outside its own tests (the
coordinator rebuilds the config with from_config on a change);
geometry.find_item_boundary and StreamManager._refresh_plugin_content
had no callers at all.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* refactor(run): drop the debug block that pretended to import the plugin system

In debug mode run.py put src/plugin_system itself on sys.path and printed
"Plugin system import successful" without importing anything. Nothing
imports plugin_system modules by bare name, so the path entry did
nothing either.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test: delete tests that test nothing

- test/plugins/test_{basketball_scoreboard,calendar,clock_simple,
  odds_ticker,soccer_scoreboard,text_display}.py skip everywhere the named
  plugins are not installed, including CI (LEDMATRIX_PLUGINS_DIR holds only
  the fixture plugin); test_plugin_matrix.py already covers every
  discovered plugin. Their PluginTestBase and the fixtures only it used
  (plugins_dir, mock_display_manager, mock_cache_manager,
  mock_plugin_manager, base_plugin_config in test/plugins/conftest.py) go
  with them.
- test_plugin_system.py: test_discover_plugins (body was `pass`) and
  test_dependency_check (a comment), plus the test_plugin_manager fixture
  only the former requested.
- test_display_manager.py: test_draw_image asserted that an image it had
  just assigned was not None.
- test_display_controller.py: the rotation and schedule-override tests
  re-implemented the run-loop arithmetic inline and asserted on their own
  result without calling the controller.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test: expect one plugin_last_update success stamp after update_all_plugins

EveryStampRecordsACompletion required at least two success-path stamps;
the second was update_all_plugins, removed as test-only. The worker and
synchronous paths share the remaining stamp in _execute_update_now, and
the check that every stamp calls _note_update_completed is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Chuck
2026-09-23 12:36:26 -04:00
committed by GitHub
co-authored by Claude Opus 5.5
parent e1ce7189f1
commit 84afa9d64f
57 changed files with 273 additions and 6254 deletions
-95
View File
@@ -7,7 +7,6 @@ import os
import sys
import json
from pathlib import Path
from unittest.mock import MagicMock, Mock
from typing import Any, Dict
# Add project root to path
@@ -19,100 +18,6 @@ if str(project_root) not in sys.path:
os.environ['EMULATOR'] = 'true'
@pytest.fixture
def plugins_dir() -> Path:
"""Get the plugins directory path.
Honors LEDMATRIX_PLUGINS_DIR (first entry) when set — the same override
test_plugin_matrix.py uses, so CI can point every plugin suite at the
bundled fixture plugins. Otherwise checks plugins/ first, then falls
back to plugin-repos/ for monorepo development environments.
"""
env = os.environ.get('LEDMATRIX_PLUGINS_DIR')
if env:
first = env.split(os.pathsep)[0]
if first:
return Path(first)
plugins_path = project_root / 'plugins'
plugin_repos_path = project_root / 'plugin-repos'
# Prefer plugins/ if it has actual plugin directories
if plugins_path.exists():
try:
has_plugins = any(
p for p in plugins_path.iterdir()
if p.is_dir() and not p.name.startswith('.')
)
if has_plugins:
return plugins_path
except PermissionError:
pass
if plugin_repos_path.exists():
return plugin_repos_path
return plugins_path
@pytest.fixture
def mock_display_manager() -> Any:
"""Create a mock DisplayManager for plugin tests."""
mock = MagicMock()
mock.width = 128
mock.height = 32
mock.clear = Mock()
mock.draw_text = Mock()
mock.draw_image = Mock()
mock.update_display = Mock()
mock.get_font = Mock(return_value=None)
# Some plugins access matrix.width/height
mock.matrix = MagicMock()
mock.matrix.width = 128
mock.matrix.height = 32
return mock
@pytest.fixture
def mock_cache_manager() -> Any:
"""Create a mock CacheManager for plugin tests."""
mock = MagicMock()
mock._memory_cache = {}
def mock_get(key: str, max_age: int = 300) -> Any:
return mock._memory_cache.get(key)
def mock_set(key: str, data: Any, ttl: int = None) -> None:
mock._memory_cache[key] = data
def mock_clear(key: str = None) -> None:
if key:
mock._memory_cache.pop(key, None)
else:
mock._memory_cache.clear()
mock.get = Mock(side_effect=mock_get)
mock.set = Mock(side_effect=mock_set)
mock.clear = Mock(side_effect=mock_clear)
return mock
@pytest.fixture
def mock_plugin_manager() -> Any:
"""Create a mock PluginManager for plugin tests."""
mock = MagicMock()
mock.plugins = {}
mock.plugin_manifests = {}
return mock
@pytest.fixture
def base_plugin_config() -> Dict[str, Any]:
"""Base configuration for plugins."""
return {
'enabled': True,
'update_interval': 300
}
def load_plugin_manifest(plugin_id: str, plugins_dir: Path) -> Dict[str, Any]:
"""Load plugin manifest.json."""
manifest_path = plugins_dir / plugin_id / 'manifest.json'
@@ -1,95 +0,0 @@
"""
Integration tests for basketball-scoreboard plugin.
Requires the real plugin to be installed (plugins/ or plugin-repos/,
or the dir named by LEDMATRIX_PLUGINS_DIR) — on machines without it,
every test here skips by design. CI covers plugin safety with the
bundled fixture plugin via test_plugin_matrix.py instead.
"""
import pytest
from test.plugins.test_plugin_base import PluginTestBase
class TestBasketballScoreboardPlugin(PluginTestBase):
"""Test basketball-scoreboard plugin integration."""
@pytest.fixture
def plugin_id(self):
return 'basketball-scoreboard'
def test_manifest_exists(self, plugin_id):
"""Test that plugin manifest exists."""
super().test_manifest_exists(plugin_id)
def test_manifest_has_required_fields(self, plugin_id):
"""Test that manifest has all required fields."""
super().test_manifest_has_required_fields(plugin_id)
def test_plugin_can_be_loaded(self, plugin_id):
"""Test that plugin module can be loaded."""
super().test_plugin_can_be_loaded(plugin_id)
def test_plugin_class_exists(self, plugin_id):
"""Test that plugin class exists."""
super().test_plugin_class_exists(plugin_id)
def test_plugin_can_be_instantiated(self, plugin_id):
"""Test that plugin can be instantiated."""
super().test_plugin_can_be_instantiated(plugin_id)
def test_plugin_has_required_methods(self, plugin_id):
"""Test that plugin has required methods."""
super().test_plugin_has_required_methods(plugin_id)
def test_plugin_update_method(self, plugin_id):
"""Test that plugin update() method works."""
super().test_plugin_update_method(plugin_id)
def test_plugin_display_method(self, plugin_id):
"""Test that plugin display() method works."""
super().test_plugin_display_method(plugin_id)
def test_plugin_has_display_modes(self, plugin_id):
"""Test that plugin has display modes."""
manifest = self.load_plugin_manifest(plugin_id)
assert 'display_modes' in manifest
# Manifest uses league-prefixed modes (nba_, wnba_, ncaam_, ncaaw_)
assert 'nba_live' in manifest['display_modes']
assert 'nba_recent' in manifest['display_modes']
assert 'nba_upcoming' in manifest['display_modes']
def test_plugin_has_get_display_modes(self, plugin_id):
"""Test that plugin can return display modes."""
manifest = self.load_plugin_manifest(plugin_id)
plugin_dir = self.plugins_dir / plugin_id
entry_point = manifest['entry_point']
class_name = manifest['class_name']
module = self.plugin_loader.load_module(
plugin_id=plugin_id,
plugin_dir=plugin_dir,
entry_point=entry_point
)
plugin_class = self.plugin_loader.get_plugin_class(
plugin_id=plugin_id,
module=module,
class_name=class_name
)
config = self.base_config.copy()
plugin_instance = self.plugin_loader.instantiate_plugin(
plugin_id=plugin_id,
plugin_class=plugin_class,
config=config,
display_manager=self.mock_display_manager,
cache_manager=self.mock_cache_manager,
plugin_manager=self.mock_plugin_manager
)
# Check if plugin has get_display_modes method
if hasattr(plugin_instance, 'get_display_modes'):
modes = plugin_instance.get_display_modes()
assert isinstance(modes, list)
assert len(modes) > 0
-63
View File
@@ -1,63 +0,0 @@
"""
Integration tests for calendar plugin.
Requires the real plugin to be installed (plugins/ or plugin-repos/,
or the dir named by LEDMATRIX_PLUGINS_DIR) — on machines without it,
every test here skips by design. CI covers plugin safety with the
bundled fixture plugin via test_plugin_matrix.py instead.
"""
import pytest
from test.plugins.test_plugin_base import PluginTestBase
class TestCalendarPlugin(PluginTestBase):
"""Test calendar plugin integration."""
@pytest.fixture
def plugin_id(self):
return 'calendar'
def test_manifest_exists(self, plugin_id):
"""Test that plugin manifest exists."""
super().test_manifest_exists(plugin_id)
def test_manifest_has_required_fields(self, plugin_id):
"""Test that manifest has all required fields."""
super().test_manifest_has_required_fields(plugin_id)
def test_plugin_can_be_loaded(self, plugin_id):
"""Test that plugin module can be loaded."""
super().test_plugin_can_be_loaded(plugin_id)
def test_plugin_class_exists(self, plugin_id):
"""Test that plugin class exists."""
super().test_plugin_class_exists(plugin_id)
def test_plugin_can_be_instantiated(self, plugin_id):
"""Test that plugin can be instantiated."""
# Calendar plugin may need credentials, but instantiation should work
super().test_plugin_can_be_instantiated(plugin_id)
def test_plugin_has_required_methods(self, plugin_id):
"""Test that plugin has required methods."""
super().test_plugin_has_required_methods(plugin_id)
def test_plugin_update_method(self, plugin_id):
"""Test that plugin update() method works."""
# Calendar requires Google API credentials, so this may skip
super().test_plugin_update_method(plugin_id)
def test_plugin_display_method(self, plugin_id):
"""Test that plugin display() method works."""
super().test_plugin_display_method(plugin_id)
def test_plugin_has_display_modes(self, plugin_id):
"""Test that plugin has display modes."""
manifest = self.load_plugin_manifest(plugin_id)
assert 'display_modes' in manifest
assert 'calendar' in manifest['display_modes']
def test_config_schema_valid(self, plugin_id):
"""Test that config schema is valid."""
super().test_config_schema_valid(plugin_id)
-103
View File
@@ -1,103 +0,0 @@
"""
Integration tests for clock-simple plugin.
Requires the real plugin to be installed (plugins/ or plugin-repos/,
or the dir named by LEDMATRIX_PLUGINS_DIR) — on machines without it,
every test here skips by design. CI covers plugin safety with the
bundled fixture plugin via test_plugin_matrix.py instead.
"""
import pytest
from test.plugins.test_plugin_base import PluginTestBase
class TestClockSimplePlugin(PluginTestBase):
"""Test clock-simple plugin integration."""
@pytest.fixture
def plugin_id(self):
return 'clock-simple'
def test_manifest_exists(self, plugin_id):
"""Test that plugin manifest exists."""
super().test_manifest_exists(plugin_id)
def test_manifest_has_required_fields(self, plugin_id):
"""Test that manifest has all required fields."""
super().test_manifest_has_required_fields(plugin_id)
def test_plugin_can_be_loaded(self, plugin_id):
"""Test that plugin module can be loaded."""
super().test_plugin_can_be_loaded(plugin_id)
def test_plugin_class_exists(self, plugin_id):
"""Test that plugin class exists."""
super().test_plugin_class_exists(plugin_id)
def test_plugin_can_be_instantiated(self, plugin_id):
"""Test that plugin can be instantiated."""
super().test_plugin_can_be_instantiated(plugin_id)
def test_plugin_has_required_methods(self, plugin_id):
"""Test that plugin has required methods."""
super().test_plugin_has_required_methods(plugin_id)
def test_plugin_update_method(self, plugin_id):
"""Test that plugin update() method works."""
# Clock doesn't need external APIs, so this should always work
super().test_plugin_update_method(plugin_id)
def test_plugin_display_method(self, plugin_id):
"""Test that plugin display() method works."""
super().test_plugin_display_method(plugin_id)
def test_plugin_has_display_modes(self, plugin_id):
"""Test that plugin has display modes."""
manifest = self.load_plugin_manifest(plugin_id)
assert 'display_modes' in manifest
assert 'clock-simple' in manifest['display_modes']
def test_clock_displays_time(self, plugin_id):
"""Test that clock plugin actually displays time."""
manifest = self.load_plugin_manifest(plugin_id)
plugin_dir = self.plugins_dir / plugin_id
entry_point = manifest['entry_point']
class_name = manifest['class_name']
module = self.plugin_loader.load_module(
plugin_id=plugin_id,
plugin_dir=plugin_dir,
entry_point=entry_point
)
plugin_class = self.plugin_loader.get_plugin_class(
plugin_id=plugin_id,
module=module,
class_name=class_name
)
config = self.base_config.copy()
config['timezone'] = 'UTC'
config['time_format'] = '12h'
config['show_date'] = True
plugin_instance = self.plugin_loader.instantiate_plugin(
plugin_id=plugin_id,
plugin_class=plugin_class,
config=config,
display_manager=self.mock_display_manager,
cache_manager=self.mock_cache_manager,
plugin_manager=self.mock_plugin_manager
)
# Update and display
plugin_instance.update()
plugin_instance.display(force_clear=True)
# Verify time was formatted
assert hasattr(plugin_instance, 'current_time')
assert plugin_instance.current_time is not None
# Verify display was called
assert self.mock_display_manager.clear.called
assert self.mock_display_manager.update_display.called
-62
View File
@@ -1,62 +0,0 @@
"""
Integration tests for odds-ticker plugin.
Requires the real plugin to be installed (plugins/ or plugin-repos/,
or the dir named by LEDMATRIX_PLUGINS_DIR) — on machines without it,
every test here skips by design. CI covers plugin safety with the
bundled fixture plugin via test_plugin_matrix.py instead.
"""
import pytest
from test.plugins.test_plugin_base import PluginTestBase
class TestOddsTickerPlugin(PluginTestBase):
"""Test odds-ticker plugin integration."""
@pytest.fixture
def plugin_id(self):
return 'odds-ticker'
def test_manifest_exists(self, plugin_id):
"""Test that plugin manifest exists."""
super().test_manifest_exists(plugin_id)
def test_manifest_has_required_fields(self, plugin_id):
"""Test that manifest has all required fields."""
super().test_manifest_has_required_fields(plugin_id)
def test_plugin_can_be_loaded(self, plugin_id):
"""Test that plugin module can be loaded."""
super().test_plugin_can_be_loaded(plugin_id)
def test_plugin_class_exists(self, plugin_id):
"""Test that plugin class exists."""
super().test_plugin_class_exists(plugin_id)
def test_plugin_can_be_instantiated(self, plugin_id):
"""Test that plugin can be instantiated."""
super().test_plugin_can_be_instantiated(plugin_id)
def test_plugin_has_required_methods(self, plugin_id):
"""Test that plugin has required methods."""
super().test_plugin_has_required_methods(plugin_id)
def test_plugin_update_method(self, plugin_id):
"""Test that plugin update() method works."""
# Odds ticker may need API access, but should handle gracefully
super().test_plugin_update_method(plugin_id)
def test_plugin_display_method(self, plugin_id):
"""Test that plugin display() method works."""
super().test_plugin_display_method(plugin_id)
def test_plugin_has_display_modes(self, plugin_id):
"""Test that plugin has display modes."""
manifest = self.load_plugin_manifest(plugin_id)
assert 'display_modes' in manifest
assert 'odds_ticker' in manifest['display_modes']
def test_config_schema_valid(self, plugin_id):
"""Test that config schema is valid."""
super().test_config_schema_valid(plugin_id)
-305
View File
@@ -1,305 +0,0 @@
"""
Base test class for plugin integration tests.
Provides common test functionality for all plugins.
"""
import pytest
import json
from typing import Dict, Any
from src.plugin_system.plugin_loader import PluginLoader
from src.plugin_system.base_plugin import BasePlugin
class PluginTestBase:
"""Base class for plugin integration tests."""
@pytest.fixture(autouse=True)
def setup_base(self, plugins_dir, mock_display_manager, mock_cache_manager,
mock_plugin_manager, base_plugin_config):
"""Setup base fixtures for all plugin tests."""
self.plugins_dir = plugins_dir
self.mock_display_manager = mock_display_manager
self.mock_cache_manager = mock_cache_manager
self.mock_plugin_manager = mock_plugin_manager
self.base_config = base_plugin_config
self.plugin_loader = PluginLoader()
def load_plugin_manifest(self, plugin_id: str) -> Dict[str, Any]:
"""Load plugin manifest.json."""
manifest_path = self.plugins_dir / plugin_id / 'manifest.json'
if not manifest_path.exists():
pytest.skip(f"Manifest not found for {plugin_id}")
with open(manifest_path, 'r') as f:
return json.load(f)
def load_plugin_config_schema(self, plugin_id: str) -> Dict[str, Any]:
"""Load plugin config_schema.json if it exists."""
schema_path = self.plugins_dir / plugin_id / 'config_schema.json'
if schema_path.exists():
with open(schema_path, 'r') as f:
return json.load(f)
return None
def test_manifest_exists(self, plugin_id: str):
"""Test that plugin manifest exists and is valid JSON."""
manifest = self.load_plugin_manifest(plugin_id)
assert manifest is not None
assert 'id' in manifest
assert manifest['id'] == plugin_id
assert 'class_name' in manifest
# entry_point is optional - default to 'manager.py' if missing
if 'entry_point' not in manifest:
manifest['entry_point'] = 'manager.py'
def test_manifest_has_required_fields(self, plugin_id: str):
"""Test that manifest has all required fields."""
manifest = self.load_plugin_manifest(plugin_id)
# Core required fields
required_fields = ['id', 'name', 'description', 'author', 'class_name']
for field in required_fields:
assert field in manifest, f"Manifest missing required field: {field}"
assert manifest[field], f"Manifest field {field} is empty"
# entry_point is required but some plugins may not have it explicitly
# If missing, assume it's 'manager.py'
if 'entry_point' not in manifest:
manifest['entry_point'] = 'manager.py'
def test_plugin_can_be_loaded(self, plugin_id: str):
"""Test that plugin module can be loaded."""
manifest = self.load_plugin_manifest(plugin_id)
plugin_dir = self.plugins_dir / plugin_id
entry_point = manifest.get('entry_point', 'manager.py')
module = self.plugin_loader.load_module(
plugin_id=plugin_id,
plugin_dir=plugin_dir,
entry_point=entry_point
)
assert module is not None
assert hasattr(module, manifest['class_name'])
def test_plugin_class_exists(self, plugin_id: str):
"""Test that plugin class exists in module."""
manifest = self.load_plugin_manifest(plugin_id)
plugin_dir = self.plugins_dir / plugin_id
entry_point = manifest.get('entry_point', 'manager.py')
class_name = manifest['class_name']
module = self.plugin_loader.load_module(
plugin_id=plugin_id,
plugin_dir=plugin_dir,
entry_point=entry_point
)
plugin_class = self.plugin_loader.get_plugin_class(
plugin_id=plugin_id,
module=module,
class_name=class_name
)
assert plugin_class is not None
assert issubclass(plugin_class, BasePlugin)
def test_plugin_can_be_instantiated(self, plugin_id: str):
"""Test that plugin can be instantiated with mock dependencies."""
manifest = self.load_plugin_manifest(plugin_id)
plugin_dir = self.plugins_dir / plugin_id
entry_point = manifest.get('entry_point', 'manager.py')
class_name = manifest['class_name']
module = self.plugin_loader.load_module(
plugin_id=plugin_id,
plugin_dir=plugin_dir,
entry_point=entry_point
)
plugin_class = self.plugin_loader.get_plugin_class(
plugin_id=plugin_id,
module=module,
class_name=class_name
)
# Merge base config with plugin-specific defaults
config = self.base_config.copy()
plugin_instance = self.plugin_loader.instantiate_plugin(
plugin_id=plugin_id,
plugin_class=plugin_class,
config=config,
display_manager=self.mock_display_manager,
cache_manager=self.mock_cache_manager,
plugin_manager=self.mock_plugin_manager
)
assert plugin_instance is not None
assert plugin_instance.plugin_id == plugin_id
assert plugin_instance.enabled == config.get('enabled', True)
def test_plugin_has_required_methods(self, plugin_id: str):
"""Test that plugin has required BasePlugin methods."""
manifest = self.load_plugin_manifest(plugin_id)
plugin_dir = self.plugins_dir / plugin_id
entry_point = manifest.get('entry_point', 'manager.py')
class_name = manifest['class_name']
module = self.plugin_loader.load_module(
plugin_id=plugin_id,
plugin_dir=plugin_dir,
entry_point=entry_point
)
plugin_class = self.plugin_loader.get_plugin_class(
plugin_id=plugin_id,
module=module,
class_name=class_name
)
config = self.base_config.copy()
plugin_instance = self.plugin_loader.instantiate_plugin(
plugin_id=plugin_id,
plugin_class=plugin_class,
config=config,
display_manager=self.mock_display_manager,
cache_manager=self.mock_cache_manager,
plugin_manager=self.mock_plugin_manager
)
# Check required methods exist
assert hasattr(plugin_instance, 'update')
assert hasattr(plugin_instance, 'display')
assert callable(plugin_instance.update)
assert callable(plugin_instance.display)
def test_plugin_update_method(self, plugin_id: str):
"""Test that plugin update() method can be called without errors."""
manifest = self.load_plugin_manifest(plugin_id)
plugin_dir = self.plugins_dir / plugin_id
entry_point = manifest.get('entry_point', 'manager.py')
class_name = manifest['class_name']
module = self.plugin_loader.load_module(
plugin_id=plugin_id,
plugin_dir=plugin_dir,
entry_point=entry_point
)
plugin_class = self.plugin_loader.get_plugin_class(
plugin_id=plugin_id,
module=module,
class_name=class_name
)
config = self.base_config.copy()
plugin_instance = self.plugin_loader.instantiate_plugin(
plugin_id=plugin_id,
plugin_class=plugin_class,
config=config,
display_manager=self.mock_display_manager,
cache_manager=self.mock_cache_manager,
plugin_manager=self.mock_plugin_manager
)
# Call update() - should not raise exceptions
# Some plugins may need API keys, but they should handle that gracefully
try:
plugin_instance.update()
except Exception as e:
# If it's a missing API key or similar, that's acceptable for integration tests
error_msg = str(e).lower()
if 'api' in error_msg or 'key' in error_msg or 'auth' in error_msg or 'credential' in error_msg:
pytest.skip(f"Plugin requires API credentials: {e}")
else:
raise
def test_plugin_display_method(self, plugin_id: str):
"""Test that plugin display() method can be called without errors."""
manifest = self.load_plugin_manifest(plugin_id)
plugin_dir = self.plugins_dir / plugin_id
entry_point = manifest.get('entry_point', 'manager.py')
class_name = manifest['class_name']
module = self.plugin_loader.load_module(
plugin_id=plugin_id,
plugin_dir=plugin_dir,
entry_point=entry_point
)
plugin_class = self.plugin_loader.get_plugin_class(
plugin_id=plugin_id,
module=module,
class_name=class_name
)
config = self.base_config.copy()
plugin_instance = self.plugin_loader.instantiate_plugin(
plugin_id=plugin_id,
plugin_class=plugin_class,
config=config,
display_manager=self.mock_display_manager,
cache_manager=self.mock_cache_manager,
plugin_manager=self.mock_plugin_manager
)
# Some plugins need matrix attribute on display_manager (set before update)
if not hasattr(self.mock_display_manager, 'matrix'):
from unittest.mock import MagicMock
self.mock_display_manager.matrix = MagicMock()
self.mock_display_manager.matrix.width = 128
self.mock_display_manager.matrix.height = 32
# Call update() first if needed
try:
plugin_instance.update()
except Exception as e:
error_msg = str(e).lower()
if 'api' in error_msg or 'key' in error_msg or 'auth' in error_msg:
pytest.skip(f"Plugin requires API credentials: {e}")
# Some plugins need a mode set before display
# Try to set a mode if the plugin has that capability
if hasattr(plugin_instance, 'set_mode') and manifest.get('display_modes'):
try:
first_mode = manifest['display_modes'][0]
plugin_instance.set_mode(first_mode)
except Exception:
pass # If set_mode doesn't exist or fails, continue
# Call display() - should not raise exceptions
try:
plugin_instance.display(force_clear=True)
except Exception as e:
# Some plugins may need specific setup - if it's a mode issue, that's acceptable
error_msg = str(e).lower()
if 'mode' in error_msg or 'manager' in error_msg:
# This is acceptable - plugin needs proper mode setup
pass
else:
raise
# Verify display_manager methods were called (if display succeeded)
# Some plugins may not call these if they skip display due to missing data
# So we just verify the method was callable without exceptions
assert hasattr(plugin_instance, 'display')
def test_plugin_has_display_modes(self, plugin_id: str):
"""Test that plugin has display modes defined."""
manifest = self.load_plugin_manifest(plugin_id)
assert 'display_modes' in manifest
assert isinstance(manifest['display_modes'], list)
assert len(manifest['display_modes']) > 0
def test_config_schema_valid(self, plugin_id: str):
"""Test that config schema is valid JSON if it exists."""
schema = self.load_plugin_config_schema(plugin_id)
if schema is not None:
assert isinstance(schema, dict)
# Schema should have 'type' field for JSON Schema
assert 'type' in schema or 'properties' in schema
-94
View File
@@ -1,94 +0,0 @@
"""
Integration tests for soccer-scoreboard plugin.
Requires the real plugin to be installed (plugins/ or plugin-repos/,
or the dir named by LEDMATRIX_PLUGINS_DIR) — on machines without it,
every test here skips by design. CI covers plugin safety with the
bundled fixture plugin via test_plugin_matrix.py instead.
"""
import pytest
from test.plugins.test_plugin_base import PluginTestBase
class TestSoccerScoreboardPlugin(PluginTestBase):
"""Test soccer-scoreboard plugin integration."""
@pytest.fixture
def plugin_id(self):
return 'soccer-scoreboard'
def test_manifest_exists(self, plugin_id):
"""Test that plugin manifest exists."""
super().test_manifest_exists(plugin_id)
def test_manifest_has_required_fields(self, plugin_id):
"""Test that manifest has all required fields."""
super().test_manifest_has_required_fields(plugin_id)
def test_plugin_can_be_loaded(self, plugin_id):
"""Test that plugin module can be loaded."""
super().test_plugin_can_be_loaded(plugin_id)
def test_plugin_class_exists(self, plugin_id):
"""Test that plugin class exists."""
super().test_plugin_class_exists(plugin_id)
def test_plugin_can_be_instantiated(self, plugin_id):
"""Test that plugin can be instantiated."""
super().test_plugin_can_be_instantiated(plugin_id)
def test_plugin_has_required_methods(self, plugin_id):
"""Test that plugin has required methods."""
super().test_plugin_has_required_methods(plugin_id)
def test_plugin_update_method(self, plugin_id):
"""Test that plugin update() method works."""
super().test_plugin_update_method(plugin_id)
def test_plugin_display_method(self, plugin_id):
"""Test that plugin display() method works."""
super().test_plugin_display_method(plugin_id)
def test_plugin_has_display_modes(self, plugin_id):
"""Test that plugin has display modes."""
manifest = self.load_plugin_manifest(plugin_id)
assert 'display_modes' in manifest
assert 'soccer_live' in manifest['display_modes']
assert 'soccer_recent' in manifest['display_modes']
assert 'soccer_upcoming' in manifest['display_modes']
def test_plugin_has_get_display_modes(self, plugin_id):
"""Test that plugin can return display modes."""
manifest = self.load_plugin_manifest(plugin_id)
plugin_dir = self.plugins_dir / plugin_id
entry_point = manifest['entry_point']
class_name = manifest['class_name']
module = self.plugin_loader.load_module(
plugin_id=plugin_id,
plugin_dir=plugin_dir,
entry_point=entry_point
)
plugin_class = self.plugin_loader.get_plugin_class(
plugin_id=plugin_id,
module=module,
class_name=class_name
)
config = self.base_config.copy()
plugin_instance = self.plugin_loader.instantiate_plugin(
plugin_id=plugin_id,
plugin_class=plugin_class,
config=config,
display_manager=self.mock_display_manager,
cache_manager=self.mock_cache_manager,
plugin_manager=self.mock_plugin_manager
)
# Check if plugin has get_display_modes method
if hasattr(plugin_instance, 'get_display_modes'):
modes = plugin_instance.get_display_modes()
assert isinstance(modes, list)
assert len(modes) > 0
-114
View File
@@ -1,114 +0,0 @@
"""
Integration tests for text-display plugin.
Requires the real plugin to be installed (plugins/ or plugin-repos/,
or the dir named by LEDMATRIX_PLUGINS_DIR) — on machines without it,
every test here skips by design. CI covers plugin safety with the
bundled fixture plugin via test_plugin_matrix.py instead.
"""
import pytest
from unittest.mock import MagicMock
from test.plugins.test_plugin_base import PluginTestBase
class TestTextDisplayPlugin(PluginTestBase):
"""Test text-display plugin integration."""
@pytest.fixture
def plugin_id(self):
return 'text-display'
def test_manifest_exists(self, plugin_id):
"""Test that plugin manifest exists."""
super().test_manifest_exists(plugin_id)
def test_manifest_has_required_fields(self, plugin_id):
"""Test that manifest has all required fields."""
super().test_manifest_has_required_fields(plugin_id)
def test_plugin_can_be_loaded(self, plugin_id):
"""Test that plugin module can be loaded."""
super().test_plugin_can_be_loaded(plugin_id)
def test_plugin_class_exists(self, plugin_id):
"""Test that plugin class exists."""
super().test_plugin_class_exists(plugin_id)
def test_plugin_can_be_instantiated(self, plugin_id):
"""Test that plugin can be instantiated."""
super().test_plugin_can_be_instantiated(plugin_id)
def test_plugin_has_required_methods(self, plugin_id):
"""Test that plugin has required methods."""
super().test_plugin_has_required_methods(plugin_id)
def test_plugin_update_method(self, plugin_id):
"""Test that plugin update() method works."""
# Text display doesn't need external APIs
super().test_plugin_update_method(plugin_id)
def test_plugin_display_method(self, plugin_id):
"""Test that plugin display() method works."""
super().test_plugin_display_method(plugin_id)
def test_plugin_has_display_modes(self, plugin_id):
"""Test that plugin has display modes."""
manifest = self.load_plugin_manifest(plugin_id)
assert 'display_modes' in manifest
assert 'text_display' in manifest['display_modes']
def test_text_display_shows_text(self, plugin_id):
"""Test that text display plugin actually displays text."""
manifest = self.load_plugin_manifest(plugin_id)
plugin_dir = self.plugins_dir / plugin_id
entry_point = manifest.get('entry_point', 'manager.py')
class_name = manifest['class_name']
module = self.plugin_loader.load_module(
plugin_id=plugin_id,
plugin_dir=plugin_dir,
entry_point=entry_point
)
plugin_class = self.plugin_loader.get_plugin_class(
plugin_id=plugin_id,
module=module,
class_name=class_name
)
config = self.base_config.copy()
config['text'] = 'Test Message'
config['scroll'] = False
config['text_color'] = [255, 255, 255]
config['background_color'] = [0, 0, 0]
# Mock display_manager.matrix to have width/height attributes
if not hasattr(self.mock_display_manager, 'matrix'):
self.mock_display_manager.matrix = MagicMock()
self.mock_display_manager.matrix.width = 128
self.mock_display_manager.matrix.height = 32
plugin_instance = self.plugin_loader.instantiate_plugin(
plugin_id=plugin_id,
plugin_class=plugin_class,
config=config,
display_manager=self.mock_display_manager,
cache_manager=self.mock_cache_manager,
plugin_manager=self.mock_plugin_manager
)
# Update and display
plugin_instance.update()
plugin_instance.display(force_clear=True)
# Verify text was set
assert plugin_instance.text == 'Test Message'
# Verify display was called (may be called via image assignment)
assert (self.mock_display_manager.update_display.called or
hasattr(self.mock_display_manager, 'image'))
def test_config_schema_valid(self, plugin_id):
"""Test that config schema is valid."""
super().test_config_schema_valid(plugin_id)