Files
ZenXercise/tools/exercise-import/tests/test_exercise_import.py
T

50 lines
1.6 KiB
Python
Raw Normal View History

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