Add auto-generated tree element lists to Python bindings.

PiperOrigin-RevId: 680973047
Change-Id: I948151260cba330c6b7218cecf13aae2c7ae92c7
This commit is contained in:
Alessio Quaglino
2024-10-01 05:22:07 -07:00
committed by Copybara-Service
parent 62ec802ec1
commit 8a825e6050
3 changed files with 60 additions and 229 deletions
+20
View File
@@ -574,6 +574,26 @@ class SpecsTest(absltest.TestCase):
self.assertEqual(spec.sensors[1].name, 'sensor2')
self.assertEqual(spec.sensors[2].name, 'sensor3')
def test_body_list(self):
main_xml = """
<mujoco>
<worldbody>
<body name="body1">
<body name="body3">
<body name="body4"/>
</body>
</body>
<body name="body2"/>
</worldbody>
</mujoco>
"""
spec = mujoco.MjSpec.from_string(main_xml)
self.assertLen(spec.bodies, 4)
self.assertEqual(spec.bodies[0].name, 'body1')
self.assertEqual(spec.bodies[1].name, 'body2')
self.assertEqual(spec.bodies[2].name, 'body3')
self.assertEqual(spec.bodies[3].name, 'body4')
def test_iterators(self):
spec = mujoco.MjSpec()
geom1 = spec.worldbody.add_geom()