Files
ZenXercise/tools/exercise-import/tests/test_exercise_import.py
T
CedricandClaude Opus 5.5 1289fadb98 Stage 1: project setup, Exercise Library, both Mode designs and the Mode switch
- Flutter Android app on CookIT's stack (provider, shared_preferences, gen-l10n)
- tools/exercise-import turns free-exercise-db into 876 bundled Exercises
  with 1,746 WebP images (20 MB); stretching -> Stretching, rest -> Workout
- ZenStyle tokens per Mode: calm rounded sage/teal with breath ripples vs.
  dark ember-to-red with floor-tape slashes; the theme morphs at each
  Mode's own pace
- Remembered global Mode switch, Plans / Library / History tabs

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-28 23:18:03 +01:00

51 lines
1.6 KiB
Python

import json
from PIL import Image
from exercise_import import mode_of, run, slim
RAW = {
"id": "Calf_Stretch",
"name": "Calf Stretch",
"force": "static",
"level": "beginner",
"mechanic": None,
"equipment": "body only",
"primaryMuscles": ["calves"],
"secondaryMuscles": [],
"instructions": ["Stand tall. ", "", "Lean forward."],
"category": "stretching",
"images": ["Calf_Stretch/0.jpg", "Calf_Stretch/1.jpg"],
}
def test_stretching_category_is_stretching_mode_and_others_workout():
assert mode_of("stretching") == "stretching"
for category in ["strength", "plyometrics", "cardio", "powerlifting"]:
assert mode_of(category) == "workout"
def test_slim_keeps_needed_fields_and_cleans_instructions():
result = slim(RAW)
assert result["mode"] == "stretching"
assert result["instructions"] == ["Stand tall.", "Lean forward."]
assert result["imageCount"] == 2
assert "images" not in result
def test_run_writes_json_and_flattened_small_webps(tmp_path):
source = tmp_path / "db"
(source / "dist").mkdir(parents=True)
(source / "exercises" / "Calf_Stretch").mkdir(parents=True)
(source / "dist" / "exercises.json").write_text(json.dumps([RAW]), encoding="utf-8")
for i in range(2):
Image.new("RGB", (850, 567), "white").save(source / "exercises" / "Calf_Stretch" / f"{i}.jpg")
out = tmp_path / "out"
run(source, out)
written = json.loads((out / "exercises.json").read_text(encoding="utf-8"))
assert [e["id"] for e in written] == ["Calf_Stretch"]
with Image.open(out / "images" / "Calf_Stretch_1.webp") as image:
assert max(image.size) == 480