Files
LEDMatrix/test/plugins/test_visual_rendering.py
ChuckandClaude Opus 5.5 2601cb4cbb chore(deprecation): remove the 35 APIs deprecated for 3.8.0 (#708)
* chore(deprecation): remove the 35 APIs deprecated for 3.8.0

The usage scan (docs/DEPRECATIONS_3.8.md, regenerated 2026-10-01 and
committed here) finds no call or override of any of them in the 46
monorepo plugins or the 8 third-party plugins plugins.json lists; the
only core callers were other deprecated methods removed alongside.

- CacheManager: 13 methods, plus the private helpers only
  has_data_changed used (_has_*_changed, _is_market_open).
- DisplayManager: 7 methods, plus WEATHER_COLORS and the private
  _draw_sun/_cloud/_rain/_snow/_storm helpers only the icon methods used.
- FontManager: 14 methods, plus size_tokens, _save_overrides and
  _clear_plugin_font_cache. font_overrides and _load_overrides stay:
  resolve_font() still applies config/font_overrides.json.
  performance_stats stays: get_font() keeps it and tests read it.
- PluginManager.get_enabled_plugins.

test_deprecation.py pins only the two 3.9.0 markers now; the scanner
tests run against a stand-in core instead of the real markers. The
memory-tier tests read stats through log_memory_cache_stats() and the
component, and the test of the removed _clear_plugin_font_cache goes.
Docs drop the removed methods' reference entries; the Deprecated APIs
table becomes "Removed in 3.8.0". CHANGELOG gains a Removed section.

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

* chore(deprecation): drop the test harness's copies of the removed icon methods

VisualTestDisplayManager still drew weather icons that DisplayManager no
longer has, so a plugin's visual tests could pass on calls that raise
AttributeError on the real display. Its draw_sun/draw_cloud/draw_rain/
draw_snow/draw_weather_icon/draw_text_with_icons, WEATHER_COLORS and the
private helpers go, with the tests that exercised them. The CHANGELOG's
Deprecations entries no longer say nothing is removed.

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

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-01 10:45:28 -04:00

199 lines
7.5 KiB
Python

"""
Tests for VisualTestDisplayManager.
Verifies that the visual display manager actually renders pixels,
loads fonts, and can save snapshots.
"""
from PIL import Image
from src.plugin_system.testing import VisualTestDisplayManager
class TestVisualDisplayManager:
"""Test VisualTestDisplayManager pixel rendering."""
def test_creates_image_with_correct_dimensions(self):
vdm = VisualTestDisplayManager(width=128, height=32)
assert vdm.image.size == (128, 32)
def test_creates_image_custom_dimensions(self):
vdm = VisualTestDisplayManager(width=64, height=64)
assert vdm.image.size == (64, 64)
assert vdm.width == 64
assert vdm.height == 64
def test_draw_text_renders_pixels(self):
vdm = VisualTestDisplayManager(width=128, height=32)
vdm.draw_text("Hello", x=0, y=0, color=(255, 255, 255))
pixels = list(vdm.image.getdata())
non_black = [p for p in pixels if p != (0, 0, 0)]
assert len(non_black) > 0, "draw_text should render actual pixels"
def test_draw_text_centered(self):
vdm = VisualTestDisplayManager(width=128, height=32)
vdm.draw_text("Test", color=(255, 0, 0)) # x=None centers text
pixels = list(vdm.image.getdata())
non_black = [p for p in pixels if p != (0, 0, 0)]
assert len(non_black) > 0
def test_draw_text_with_centered_flag(self):
vdm = VisualTestDisplayManager(width=128, height=32)
vdm.draw_text("X", x=64, y=10, centered=True, color=(0, 255, 0))
pixels = list(vdm.image.getdata())
non_black = [p for p in pixels if p != (0, 0, 0)]
assert len(non_black) > 0
def test_draw_text_tracks_calls(self):
vdm = VisualTestDisplayManager(width=128, height=32)
vdm.draw_text("Hello", x=10, y=5, color=(255, 0, 0))
assert len(vdm.draw_calls) == 1
assert vdm.draw_calls[0]['type'] == 'text'
assert vdm.draw_calls[0]['text'] == 'Hello'
assert vdm.draw_calls[0]['x'] == 10
assert vdm.draw_calls[0]['y'] == 5
def test_clear_resets_canvas(self):
vdm = VisualTestDisplayManager(width=128, height=32)
vdm.draw_text("Hello", x=0, y=0, color=(255, 255, 255))
vdm.clear()
pixels = list(vdm.image.getdata())
non_black = [p for p in pixels if p != (0, 0, 0)]
assert len(non_black) == 0, "clear() should reset all pixels to black"
assert vdm.clear_called is True
def test_update_display_sets_flag(self):
vdm = VisualTestDisplayManager(width=128, height=32)
assert vdm.update_called is False
vdm.update_display()
assert vdm.update_called is True
def test_matrix_proxy(self):
vdm = VisualTestDisplayManager(width=128, height=32)
assert vdm.matrix.width == 128
assert vdm.matrix.height == 32
def test_width_height_properties(self):
vdm = VisualTestDisplayManager(width=64, height=32)
assert vdm.width == 64
assert vdm.height == 32
assert vdm.display_width == 64
assert vdm.display_height == 32
def test_save_snapshot(self, tmp_path):
vdm = VisualTestDisplayManager(width=128, height=32)
vdm.draw_text("Test", x=10, y=10, color=(255, 0, 0))
output = tmp_path / "test_render.png"
vdm.save_snapshot(str(output))
assert output.exists()
with Image.open(str(output)) as saved_img:
assert saved_img.size == (128, 32)
def test_get_image(self):
vdm = VisualTestDisplayManager(width=128, height=32)
img = vdm.get_image()
assert isinstance(img, Image.Image)
assert img.size == (128, 32)
def test_get_image_base64(self):
vdm = VisualTestDisplayManager(width=128, height=32)
vdm.draw_text("Hi", x=0, y=0, color=(255, 255, 255))
b64 = vdm.get_image_base64()
assert isinstance(b64, str)
assert len(b64) > 0
# Should be valid base64 PNG
import base64
decoded = base64.b64decode(b64)
assert decoded[:4] == b'\x89PNG'
def test_font_attributes_exist(self):
vdm = VisualTestDisplayManager(width=128, height=32)
assert hasattr(vdm, 'regular_font')
assert hasattr(vdm, 'small_font')
assert hasattr(vdm, 'extra_small_font')
assert hasattr(vdm, 'calendar_font')
assert hasattr(vdm, 'bdf_5x7_font')
assert hasattr(vdm, 'font')
def test_get_text_width(self):
vdm = VisualTestDisplayManager(width=128, height=32)
w = vdm.get_text_width("Hello", vdm.regular_font)
assert isinstance(w, int)
assert w > 0
def test_get_font_height(self):
vdm = VisualTestDisplayManager(width=128, height=32)
h = vdm.get_font_height(vdm.regular_font)
assert isinstance(h, int)
assert h > 0
def test_image_paste(self):
"""Verify plugins can paste images onto the display."""
vdm = VisualTestDisplayManager(width=128, height=32)
overlay = Image.new('RGB', (10, 10), (255, 0, 0))
vdm.image.paste(overlay, (0, 0))
pixel = vdm.image.getpixel((5, 5))
assert pixel == (255, 0, 0)
def test_image_assignment(self):
"""Verify plugins can assign a new image to display_manager.image."""
vdm = VisualTestDisplayManager(width=128, height=32)
new_img = Image.new('RGB', (128, 32), (0, 255, 0))
vdm.image = new_img
assert vdm.image.getpixel((0, 0)) == (0, 255, 0)
def test_draw_image(self):
vdm = VisualTestDisplayManager(width=128, height=32)
overlay = Image.new('RGB', (10, 10), (0, 0, 255))
vdm.draw_image(overlay, 5, 5)
assert len(vdm.draw_calls) == 1
assert vdm.draw_calls[0]['type'] == 'image'
# Verify pixels were actually pasted
pixel = vdm.image.getpixel((7, 7))
assert pixel == (0, 0, 255)
def test_reset(self):
vdm = VisualTestDisplayManager(width=128, height=32)
vdm.draw_text("Hi", x=0, y=0)
vdm.clear()
vdm.update_display()
vdm.reset()
assert vdm.clear_called is False
assert vdm.update_called is False
assert len(vdm.draw_calls) == 0
pixels = list(vdm.image.getdata())
assert all(p == (0, 0, 0) for p in pixels)
def test_scrolling_state(self):
vdm = VisualTestDisplayManager(width=128, height=32)
assert vdm.is_currently_scrolling() is False
vdm.set_scrolling_state(True)
assert vdm.is_currently_scrolling() is True
vdm.set_scrolling_state(False)
assert vdm.is_currently_scrolling() is False
def test_process_deferred_updates_is_noop(self):
# Ticker-style plugins (news, odds-ticker, leaderboard, stock-news,
# stocks) call this unconditionally alongside set_scrolling_state();
# it must exist and be harmless so those plugins render under the
# harness instead of raising AttributeError.
vdm = VisualTestDisplayManager(width=128, height=32)
vdm.set_scrolling_state(True)
vdm.process_deferred_updates() # should not raise
assert vdm.is_currently_scrolling() is True
def test_format_date_with_ordinal(self):
from datetime import datetime
vdm = VisualTestDisplayManager(width=128, height=32)
dt = datetime(2025, 8, 1)
result = vdm.format_date_with_ordinal(dt)
assert '1st' in result
dt = datetime(2025, 8, 3)
result = vdm.format_date_with_ordinal(dt)
assert '3rd' in result
dt = datetime(2025, 8, 11)
result = vdm.format_date_with_ordinal(dt)
assert '11th' in result