Add preset persistence and startup default.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Test ESPNow receive functionality - runs on MicroPython device."""
|
||||
import json
|
||||
import os
|
||||
import utime
|
||||
from settings import Settings
|
||||
from presets import Presets
|
||||
@@ -621,6 +622,45 @@ def test_select_with_step():
|
||||
print(" ✓ Step set correctly when switching presets")
|
||||
|
||||
|
||||
def test_preset_save_load():
|
||||
"""Test saving and loading presets to/from JSON."""
|
||||
print("\nTest 10: Preset save/load")
|
||||
settings = Settings()
|
||||
patterns = Presets(settings["led_pin"], settings["num_leds"])
|
||||
|
||||
patterns.edit("saved_preset", {
|
||||
"p": "blink",
|
||||
"d": 150,
|
||||
"b": 200,
|
||||
"c": [(1, 2, 3), (4, 5, 6)],
|
||||
"a": False,
|
||||
"n1": 1,
|
||||
"n2": 2,
|
||||
"n3": 3,
|
||||
"n4": 4,
|
||||
"n5": 5,
|
||||
"n6": 6,
|
||||
})
|
||||
assert patterns.save(), "Save should return True"
|
||||
|
||||
reloaded = Presets(settings["led_pin"], settings["num_leds"])
|
||||
assert reloaded.load(), "Load should return True"
|
||||
|
||||
preset = reloaded.presets.get("saved_preset")
|
||||
assert preset is not None, "Preset should be loaded"
|
||||
assert preset.p == "blink", "Pattern should be blink"
|
||||
assert preset.d == 150, "Delay should be 150"
|
||||
assert preset.b == 200, "Brightness should be 200"
|
||||
assert preset.c == [(1, 2, 3), (4, 5, 6)], "Colors should be restored as tuples"
|
||||
assert preset.a is False, "Auto should be False"
|
||||
assert (preset.n1, preset.n2, preset.n3, preset.n4, preset.n5, preset.n6) == (1, 2, 3, 4, 5, 6), "n1-n6 should match"
|
||||
try:
|
||||
os.remove("presets.json")
|
||||
except OSError:
|
||||
pass
|
||||
print(" ✓ Preset save/load works correctly")
|
||||
|
||||
|
||||
def main():
|
||||
"""Run all tests."""
|
||||
print("=" * 60)
|
||||
@@ -637,6 +677,7 @@ def main():
|
||||
test_switch_presets()
|
||||
test_beat_functionality()
|
||||
test_select_with_step()
|
||||
test_preset_save_load()
|
||||
|
||||
print("\n" + "=" * 60)
|
||||
print("All tests passed! ✓")
|
||||
|
||||
Reference in New Issue
Block a user