import xml.etree.ElementTree as ET import pytest import yaml from iiwa_genesis.config import ROOT, DESCRIPTION, load_config def config_file(tmp_path, mode="without_gripper"): data = yaml.safe_load((ROOT / "configs/scene.yaml").read_text()) data["scene"]["mode"] = mode file = tmp_path / "scene.yaml" file.write_text(yaml.safe_dump(data)) return file @pytest.mark.parametrize("mode,count", [("without_gripper", 1), ("with_gripper", 2)]) def test_mode_selects_urdf_and_cameras(tmp_path, mode, count): cfg = load_config(config_file(tmp_path, mode)) assert len(cfg["cameras"]) == count assert cfg["robot"]["urdf"].name == f"iiwa_{mode}.urdf" @pytest.mark.parametrize("mode", ["without_gripper", "with_gripper"]) def test_urdf_tree_and_assets(mode): path = DESCRIPTION / f"urdf/iiwa_{mode}.urdf" root = ET.parse(path).getroot() links = {l.get("name") for l in root.findall("link")} joints = root.findall("joint") assert sum(j.get("type") == "revolute" for j in joints) == 7 children = [j.find("child").get("link") for j in joints] assert len(children) == len(set(children)) assert links - set(children) == {"world"} assert all(j.find("parent").get("link") in links for j in joints) assert ("camera_optical_frame" in links) == (mode == "with_gripper") for mesh in root.iter("mesh"): assert (path.parent / mesh.get("filename")).is_file() text = path.read_text() for prohibited in ("package://", "xacro", "ros2_control", "