mirror of
https://github.com/ChuckBuilds/LEDMatrix.git
synced 2026-10-04 22:35:08 +00:00
fix(element-style): clamp out-of-range colour components instead of rejecting
A regression this framework shipped. The eight scoreboards used to read their colours through sports_card.coerce_rgb, which clamps; routing them through the shared element_color sent them through _normalize_color, which rejected any component outside 0..255 and fell back to the default. So a configured [999, -5, 20] -- a typo'd bright red -- rendered white instead of (255, 0, 20). Their own test_element_text_colors.py caught it: one case of nineteen, in all eight plugins, failing only once the core change reached main. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -53,6 +53,14 @@ class TestColour:
|
||||
cfg = {"customization": {"score_text": {"text_color": value}}}
|
||||
assert C.element_color(cfg, "score_text", (9, 9, 9)) == (9, 9, 9)
|
||||
|
||||
def test_out_of_range_components_are_clamped_not_rejected(self):
|
||||
"""The readers this replaced clamped, and the eight scoreboards' own
|
||||
tests pin it. Rejecting instead turned a typo'd [999, -5, 20] -- a
|
||||
bright red -- into the default white, which is a colour the user never
|
||||
asked for rather than the one they nearly asked for."""
|
||||
cfg = {"customization": {"score_text": {"text_color": [999, -5, 20]}}}
|
||||
assert C.element_color(cfg, "score_text", (9, 9, 9)) == (255, 0, 20)
|
||||
|
||||
def test_coerce_rgb_clamps_rather_than_rejecting(self):
|
||||
assert C.coerce_rgb([300, -5, 20], (0, 0, 0)) == (255, 0, 20)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user