mirror of
https://github.com/ChuckBuilds/LEDMatrix.git
synced 2026-10-06 23:35:08 +00:00
Whole-tree audit. Every symbol was checked against core, the plugin monorepo and all eight third-party plugins in plugins.json first. - Deprecate (removal 3.10.0) plugin-facing methods nothing calls: LogoDownloader bulk download, ConfigManager backup/secret wrappers, APIHelper extras, BackgroundDataService poll API, PluginManager / PluginStateManager info readers, and a few CacheManager, FontManager, BaseOddsManager, DynamicTeamResolver methods and PluginTestCase. plugin_api_usage.py learns their receiver names; DEPRECATIONS doc regenerated. - Remove core-internal dead code: CacheMetrics, Vegas status/stats plumbing, sync "new cycle" message (followers ignore unknown types), unused operation types, test-only PluginCatalog readers, IPC to_dict and ping, _parse_form_value, CacheStrategyProtocol, ErrorAggregator callbacks, duplicate web response helpers. - Web UI: drop never-mounted json-file-manager.js, the example widget, utils/error_handler.js, four uncalled PluginAPI methods, and 29 escapeHtml shims (call window.LEDEscape directly). Public globals, BaseWidget and widget names unchanged. - Remove six one-off scripts (owner decision) and the unused markupsafe and pytest-mock pins. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
87 lines
2.9 KiB
Python
87 lines
2.9 KiB
Python
"""CacheStrategy intervals, pinned across the whole input grid.
|
|
|
|
The strategy table used to carry a per-sport defaults dict whose every value
|
|
was 60, a soccer branch identical to its else, and a config lookup of
|
|
`<sport>_scoreboard` sections that only the replaced built-in scoreboards
|
|
had. These tests pin the returned strategy for every data type x sport key,
|
|
so simplifying the lookup cannot change what any caller gets back.
|
|
"""
|
|
|
|
import pytest
|
|
|
|
from src.cache.cache_strategy import CacheStrategy
|
|
|
|
|
|
SPORT_KEYS = [None, "", "nfl", "nba", "mlb", "nhl", "soccer", "ncaa_fb",
|
|
"ncaa_baseball", "ncaam_basketball", "milb",
|
|
"football-scoreboard", "curling"]
|
|
|
|
|
|
def _fixed(max_age, memory_ttl, **extra):
|
|
return {"max_age": max_age, "memory_ttl": memory_ttl,
|
|
"force_refresh": False, **extra}
|
|
|
|
|
|
DEFAULT = _fixed(300, 600)
|
|
FIXED = {
|
|
"weather_current": _fixed(300, 600),
|
|
"stocks": _fixed(600, 1200, market_hours_only=True),
|
|
"crypto": _fixed(300, 600),
|
|
"sports_recent": _fixed(1800, 3600),
|
|
"sports_upcoming": _fixed(10800, 21600),
|
|
"sports_schedules": _fixed(86400, 172800),
|
|
"leaderboard": _fixed(604800, 1209600),
|
|
"news": _fixed(3600, 7200),
|
|
"odds": _fixed(1800, 3600),
|
|
"odds_live": _fixed(120, 240),
|
|
"team_info": _fixed(604800, 1209600),
|
|
"logos": _fixed(2592000, 5184000),
|
|
"default": DEFAULT,
|
|
}
|
|
|
|
|
|
def _expected(data_type, sport_key):
|
|
if data_type in ("live_scores", "sports_live"):
|
|
if sport_key:
|
|
interval = 60
|
|
else:
|
|
interval = 15 if data_type == "live_scores" else 30
|
|
return {"max_age": interval, "memory_ttl": interval * 2,
|
|
"force_refresh": True}
|
|
return FIXED.get(data_type, DEFAULT)
|
|
|
|
|
|
def test_strategy_table_for_every_data_type_and_sport():
|
|
strategy = CacheStrategy()
|
|
data_types = ["live_scores", "sports_live", *FIXED, "unknown", ""]
|
|
for data_type in data_types:
|
|
for sport_key in SPORT_KEYS:
|
|
got = strategy.get_cache_strategy(data_type, sport_key)
|
|
assert got == _expected(data_type, sport_key), (data_type, sport_key)
|
|
|
|
|
|
@pytest.mark.parametrize("key", [
|
|
"soccer_live", "soccer_current", "soccer_scoreboard", "SOCCER_LIVE",
|
|
"nfl_live", "live", "hockey_current", "nba_live_scores",
|
|
])
|
|
def test_live_keys_including_soccer_are_sports_live(key):
|
|
assert CacheStrategy().get_data_type_from_key(key) == "sports_live"
|
|
|
|
|
|
@pytest.mark.parametrize("key,data_type", [
|
|
("odds_soccer_live", "odds_live"),
|
|
("odds_x", "odds"),
|
|
("weather", "weather_current"),
|
|
("crypto_stock", "crypto"),
|
|
("stock", "stocks"),
|
|
("news_soccer", "news"),
|
|
("soccer_schedule", "sports_schedules"),
|
|
("soccer_recent", "sports_recent"),
|
|
("soccer_upcoming", "sports_upcoming"),
|
|
("soccer_logo", "team_info"),
|
|
("soccer", "default"),
|
|
("", "default"),
|
|
])
|
|
def test_non_live_keys_keep_their_data_type(key, data_type):
|
|
assert CacheStrategy().get_data_type_from_key(key) == data_type
|