Rework roll pattern to use gradient palette and add preset-based tests
Made-with: Cursor
This commit is contained in:
71
pico/test/test_all_on_presets.py
Normal file
71
pico/test/test_all_on_presets.py
Normal file
@@ -0,0 +1,71 @@
|
||||
"""
|
||||
On-device test that turns all LEDs on via Presets and verifies strip 0 (pin 6).
|
||||
|
||||
Usage (from pico/ dir or project root with adjusted paths):
|
||||
|
||||
mpremote connect <device> cp src/*.py :
|
||||
mpremote connect <device> cp src/patterns/*.py :patterns
|
||||
mpremote connect <device> cp lib/*.py :
|
||||
mpremote connect <device> cp test/test_all_on_presets.py :
|
||||
mpremote connect <device> run test_all_on_presets.py
|
||||
"""
|
||||
|
||||
from presets import Presets, Preset
|
||||
|
||||
|
||||
def verify_strip0_on(presets, expected_color):
|
||||
"""Check that every LED on strip 0 matches expected_color."""
|
||||
if not presets.strips:
|
||||
print("No strips; skipping strip-0 on test.")
|
||||
return
|
||||
|
||||
strip = presets.strips[0]
|
||||
r_exp, g_exp, b_exp = expected_color
|
||||
|
||||
for i in range(strip.num_leds):
|
||||
o = i * 3
|
||||
g = strip.ar[o]
|
||||
r = strip.ar[o + 1]
|
||||
b = strip.ar[o + 2]
|
||||
if (r, g, b) != (r_exp, g_exp, b_exp):
|
||||
raise AssertionError(
|
||||
"Strip 0 LED %d: got (%d,%d,%d), expected (%d,%d,%d)"
|
||||
% (i, r, g, b, r_exp, g_exp, b_exp)
|
||||
)
|
||||
|
||||
|
||||
def main():
|
||||
presets = Presets()
|
||||
|
||||
if not presets.strips:
|
||||
print("No strips; skipping all-on-presets test.")
|
||||
return
|
||||
|
||||
# Full-brightness white via the built-in 'on' pattern.
|
||||
base_color = (255, 255, 255)
|
||||
brightness = 255
|
||||
|
||||
data = {
|
||||
"p": "on",
|
||||
"c": [base_color],
|
||||
"b": brightness,
|
||||
}
|
||||
|
||||
name = "test_all_on_presets"
|
||||
preset = Preset(data)
|
||||
presets.presets[name] = preset
|
||||
|
||||
presets.select(name)
|
||||
presets.tick()
|
||||
|
||||
# Compute the color actually written by the pattern after brightness scaling.
|
||||
expected_color = presets.apply_brightness(base_color, brightness)
|
||||
|
||||
verify_strip0_on(presets, expected_color)
|
||||
|
||||
print("test_all_on_presets: OK")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user