mirror of
https://github.com/ChuckBuilds/LEDMatrix.git
synced 2026-08-01 16:58:06 +00:00
fix(testing): add MockCacheManager.get_cached_data_with_strategy/save_cache (#409)
* fix(testing): add MockCacheManager.get_cached_data_with_strategy/save_cache ledmatrix-leaderboard's data_fetcher.py calls these two real-CacheManager methods (src/cache_manager.py:313,817), but MockCacheManager had neither -- update() always hit an AttributeError, caught by a broad except and logged, so the harness rendered an empty-but-green leaderboard on every test run without ever exercising real standings data. Both mocks delegate to the existing get()/set() -- a mock doesn't need the real strategy's per-data-type max_age/market-hours timing, plugins under test just need the methods to exist and round-trip whatever was cached. * fix(testing): clear get_cached_data_with_strategy_calls in MockCacheManager.reset() reset() cleared get_calls/set_calls/delete_calls but not the newer get_cached_data_with_strategy_calls tracker, so a reused mock (e.g. across test cases sharing a fixture) retained stale strategy-call records after reset(). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KEZK1P1Q1fu5pcuVrkrCFZ --------- Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -71,6 +71,7 @@ class MockCacheManager:
|
||||
self.get_calls = []
|
||||
self.set_calls = []
|
||||
self.delete_calls = []
|
||||
self.get_cached_data_with_strategy_calls = []
|
||||
# Real temp dir for plugins that write/read files under cache_dir.
|
||||
# Registered for cleanup so each mock instance doesn't leak a tmp dir.
|
||||
self.cache_dir = tempfile.mkdtemp(prefix="ledmatrix-mock-cache-")
|
||||
@@ -108,6 +109,24 @@ class MockCacheManager:
|
||||
self.delete_calls.append(key)
|
||||
if key in self._cache:
|
||||
del self._cache[key]
|
||||
|
||||
def get_cached_data_with_strategy(self, key: str, data_type: str = 'default') -> Optional[Any]:
|
||||
"""Mock of CacheManager.get_cached_data_with_strategy (src/cache_manager.py).
|
||||
|
||||
The real method picks a max_age/memory_ttl strategy per data_type
|
||||
(and extends it during market-closed hours for market data) before
|
||||
delegating to get_cached_data(). None of that timing nuance matters
|
||||
for a mock -- plugins under test just need the method to exist and
|
||||
return whatever was cached, so this delegates straight to get().
|
||||
"""
|
||||
self.get_cached_data_with_strategy_calls.append({'key': key, 'data_type': data_type})
|
||||
return self.get(key)
|
||||
|
||||
def save_cache(self, key: str, data: Any) -> None:
|
||||
"""Mock of CacheManager.save_cache (src/cache_manager.py) -- the
|
||||
write-side counterpart to get_cached_data_with_strategy, used by the
|
||||
same real-CacheManager-oriented plugins. Delegates to set()."""
|
||||
self.set(key, data)
|
||||
if key in self._cache_timestamps:
|
||||
del self._cache_timestamps[key]
|
||||
|
||||
@@ -118,6 +137,7 @@ class MockCacheManager:
|
||||
self.get_calls = []
|
||||
self.set_calls = []
|
||||
self.delete_calls = []
|
||||
self.get_cached_data_with_strategy_calls = []
|
||||
|
||||
|
||||
class MockConfigManager:
|
||||
|
||||
Reference in New Issue
Block a user