test: replace can't-fail tests with real assertions

test_font_manager.py was 5 of 6 tests shaped as 'try: call(); assert True /
except: assert True' — running in CI while unable to fail on any
regression. Rewritten against the real FontManager API and the bundled
assets/fonts: returned font types, cache-hit identity, distinct entries per
size, default-font fallback for unknown families and corrupt files
(recorded in failed_loads), BDF native-size reading, text measurement, and
cache lifecycle.

test_display_manager.py's test_draw_text ended in 'assert True'; it now
renders onto a known-black canvas and asserts pixels were actually lit —
which required un-breaking the fixture's freetype MagicMock so draw_text's
isinstance check doesn't silently swallow the draw.

test_display_controller.py carried a permanently-skipped test whose skip
reason already declared it redundant; deleted.

Both display test files now set EMULATOR=true before importing
display_manager (the same convention as test_display_dirty_tracking.py) so
they collect standalone instead of depending on which test module imports
display_manager first.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NohXi78cwsAKtN1sCfxjUh
This commit is contained in:
Claude
2026-08-06 22:30:32 +00:00
parent 911c559fd4
commit ca04820754
3 changed files with 148 additions and 94 deletions
+28 -11
View File
@@ -1,6 +1,15 @@
import os
import pytest
from unittest.mock import MagicMock, patch
from PIL import ImageDraw
# display_manager imports the hardware rgbmatrix module at import time unless
# EMULATOR=true. Use the emulator (same convention as
# test_display_dirty_tracking.py) so this file collects standalone instead of
# relying on collection order — the tests below patch RGBMatrix/
# RGBMatrixOptions explicitly, so the underlying binding doesn't matter here.
os.environ.setdefault("EMULATOR", "true")
from src.display_manager import DisplayManager
@pytest.fixture
@@ -77,18 +86,26 @@ class TestDisplayManagerDrawing:
assert dm.matrix.Clear.called
def test_draw_text(self, test_config, mock_rgb_matrix):
"""Test text drawing."""
"""Text drawn through draw_text must actually light pixels."""
from PIL import Image, ImageDraw, ImageFont
import src.display_manager as dm_mod
with patch.dict('os.environ', {'EMULATOR': 'false'}):
dm = DisplayManager(test_config)
# Mock font
font = MagicMock()
dm.draw_text("Test", 0, 0, font)
# Verify draw_text was called (DisplayManager uses freetype/PIL)
# The actual implementation uses freetype or PIL, not graphics module
assert True # draw_text should execute without error
DisplayManager._instance = None
dm = DisplayManager(test_config, suppress_test_pattern=True)
# The fixture replaces the module's freetype with a MagicMock,
# which breaks draw_text's isinstance(font, freetype.Face) check
# (and silently swallows the draw). Give the mock a real class so
# isinstance works and the PIL path is taken.
dm_mod.freetype.Face = type("_FakeFace", (), {})
# Start from a known-black canvas so the assertion below can only
# pass if draw_text itself lit something.
dm.image = Image.new('RGB', (dm.width, dm.height))
dm.draw = ImageDraw.Draw(dm.image)
dm.draw_text("Test", 0, 0, font=ImageFont.load_default())
assert dm.image.convert("L").getbbox() is not None, \
"draw_text lit no pixels"
def test_draw_image(self, test_config, mock_rgb_matrix):
"""Test image drawing."""