- device.py: device communication/handling - cli.py: CLI interface updates - web.py: web interface - build.py, build.sh, install.sh: build and install scripts - Pipfile: Python dependencies - lib/mpremote: mpremote library - test_*.py: import and LED tests - Updated .gitignore and README Co-authored-by: Cursor <cursoragent@cursor.com>
88 lines
3.0 KiB
Python
88 lines
3.0 KiB
Python
#!/usr/bin/env python3
|
|
"""Test script for updating number of LEDs"""
|
|
import sys
|
|
import json
|
|
import subprocess
|
|
|
|
print("Testing CLI with -l (number of LEDs) option...")
|
|
print("=" * 60)
|
|
|
|
# Test 1: Check help output
|
|
print("\n1. Testing help output:")
|
|
result = subprocess.run(
|
|
[sys.executable, "cli.py", "-h"],
|
|
capture_output=True,
|
|
text=True,
|
|
cwd="/home/jimmy/projects/led-tool"
|
|
)
|
|
if "-l" in result.stdout or "--leds" in result.stdout:
|
|
print(" ✓ Help shows -l/--leds option")
|
|
else:
|
|
print(" ✗ Help does not show -l/--leds option")
|
|
print(f" Output: {result.stdout[:200]}")
|
|
|
|
# Test 2: Test with --no-download and --no-upload (won't connect to device)
|
|
print("\n2. Testing -l 100 with --no-download --no-upload:")
|
|
result = subprocess.run(
|
|
[sys.executable, "cli.py", "-l", "100", "--no-download", "--no-upload"],
|
|
capture_output=True,
|
|
text=True,
|
|
cwd="/home/jimmy/projects/led-tool"
|
|
)
|
|
|
|
output = result.stdout
|
|
print(f" Return code: {result.returncode}")
|
|
print(f" Output:\n{output}")
|
|
|
|
# Check if num_leds is in the output
|
|
if "num_leds" in output or '"num_leds": 100' in output:
|
|
print(" ✓ num_leds is set to 100 in output")
|
|
# Try to parse as JSON
|
|
try:
|
|
# Extract JSON from output (it should be the last part)
|
|
lines = output.strip().split('\n')
|
|
json_str = '\n'.join([l for l in lines if l.strip().startswith('{') or l.strip().startswith('"')])
|
|
if not json_str:
|
|
json_str = output.strip()
|
|
settings = json.loads(json_str)
|
|
if settings.get("num_leds") == 100:
|
|
print(" ✓ JSON is valid and num_leds = 100")
|
|
else:
|
|
print(f" ✗ num_leds is {settings.get('num_leds')}, expected 100")
|
|
except json.JSONDecodeError as e:
|
|
print(f" ⚠ Could not parse as JSON: {e}")
|
|
print(f" Raw output: {output[:500]}")
|
|
else:
|
|
print(" ✗ num_leds not found in output")
|
|
print(f" Output: {output[:500]}")
|
|
|
|
# Test 3: Test with multiple options including LEDs
|
|
print("\n3. Testing -l 60 with other options:")
|
|
result = subprocess.run(
|
|
[sys.executable, "cli.py", "-l", "60", "-b", "128", "-n", "TestLED", "--no-download", "--no-upload"],
|
|
capture_output=True,
|
|
text=True,
|
|
cwd="/home/jimmy/projects/led-tool"
|
|
)
|
|
|
|
output = result.stdout
|
|
if result.returncode == 0:
|
|
try:
|
|
settings = json.loads(output.strip())
|
|
if settings.get("num_leds") == 60:
|
|
print(" ✓ num_leds is set to 60")
|
|
if settings.get("brightness") == 128:
|
|
print(" ✓ brightness is set to 128")
|
|
if settings.get("name") == "TestLED":
|
|
print(" ✓ name is set to TestLED")
|
|
print(f" Settings: {json.dumps(settings, indent=2)}")
|
|
except json.JSONDecodeError:
|
|
print(f" ⚠ Could not parse output as JSON")
|
|
print(f" Output: {output[:500]}")
|
|
else:
|
|
print(f" ✗ Command failed with return code {result.returncode}")
|
|
print(f" Error: {result.stderr}")
|
|
|
|
print("\n" + "=" * 60)
|
|
print("Test complete!")
|