Files
SkillFactory/tests/test_go2_leg_extraction.py
T
chenlin 7f39abb613 release: SkillFactory v0.0.1
Add declarative single-leg import, fixed-anchor benchmark, masked shared-policy PPO prototype, regression tests, and consolidated documentation.
2026-10-10 09:58:30 +08:00

72 lines
2.9 KiB
Python

"""Pure XML tests: no Kit, Isaac Lab, network or GPU required."""
import importlib.util
import shutil
import xml.etree.ElementTree as ET
from pathlib import Path
import pytest
SPEC = importlib.util.spec_from_file_location(
"extract_leg", Path(__file__).parents[1] / "scripts/assets/extract_go2_leg.py"
)
extractor = importlib.util.module_from_spec(SPEC)
SPEC.loader.exec_module(extractor)
def test_repeatable_and_real_subtree(tmp_path):
a, b = tmp_path / "a", tmp_path / "b"
manifest = extractor.extract(extractor.DEFAULT_SOURCE, a)
extractor.extract(extractor.DEFAULT_SOURCE, b)
assert (a / "go2_fl.urdf").read_bytes() == (b / "go2_fl.urdf").read_bytes()
assert (a / "manifest.json").read_bytes() == (b / "manifest.json").read_bytes()
robot = ET.parse(a / "go2_fl.urdf").getroot()
assert manifest["joint_order"] == list(extractor.JOINTS)
assert len([j for j in robot.findall("joint") if j.get("type") == "revolute"]) == 3
assert {link.get("name") for link in robot.findall("link")} == {
"anchor_base",
"FL_hip",
"FL_thigh",
"FL_calf",
"FL_foot",
"FL_hip_rotor",
"FL_thigh_rotor",
"FL_calf_rotor",
"FL_calflower",
"FL_calflower1",
}
assert robot.find("joint[@name='FL_foot_joint']").get("dont_collapse") == "true"
assert robot.find("joint[@name='FL_hip_joint']/origin").get("xyz") == "0 0 0"
assert robot.find("link[@name='anchor_base']/collision") is None
for mesh in robot.findall(".//mesh"):
assert (a / mesh.get("filename")).is_file()
assert manifest["skill"]["valid"] is False
assert (a / "LICENSE").is_file()
assert manifest["missing_inertial_fixed_links"] == ["FL_calflower", "FL_calflower1"]
center = extractor.foot_center(robot)
assert abs(center[2] + manifest["anchor"]["default_height"] - 0.022 - 0.01) < 1e-12
original = ET.parse(extractor.DEFAULT_SOURCE / "urdf/go2_description.urdf").getroot()
old = extractor.foot_center(original)
assert all(
abs(new + shift - old_value) < 1e-10
for new, shift, old_value in zip(center, manifest["anchor"]["original_mount_translation"], old)
)
def test_missing_reference_fails(tmp_path):
source = tmp_path / "unitree/robots/go2_description"
shutil.copytree(extractor.DEFAULT_SOURCE, source)
(source / "dae/hip.dae").unlink()
with pytest.raises(FileNotFoundError):
extractor.extract(source, tmp_path / "out")
def test_invalid_inertia_fails(tmp_path):
source = tmp_path / "unitree/robots/go2_description"
shutil.copytree(extractor.DEFAULT_SOURCE, source)
tree = ET.parse(source / "urdf/go2_description.urdf")
tree.find("link[@name='FL_thigh']/inertial/inertia").set("ixy", "100")
tree.write(source / "urdf/go2_description.urdf")
with pytest.raises(ValueError, match="Invalid inertia"):
extractor.extract(source, tmp_path / "out")