Prevent deletion from an attached mjSpec.
This change disallows calling `mjs_delete` on an mjSpec that has been attached to another mjSpec via `mjs_attach`. Attempting to delete an element from an attached spec will now result in an error. The Python bindings for `mjSpec.delete` have been updated to raise a ValueError when this occurs. PiperOrigin-RevId: 897266695 Change-Id: Ic0670125a3028191ec50eca890f02b5910ec8b03
This commit is contained in:
committed by
Copybara-Service
parent
a744b366fb
commit
6b724616c0
@@ -979,7 +979,6 @@ class SpecsTest(absltest.TestCase):
|
||||
self.assertEqual(mesh.plugin.name, 'inst')
|
||||
self.assertEqual(mesh.plugin.plugin_name, 'mujoco.sdf.torus')
|
||||
|
||||
|
||||
def test_duplicate_name_error(self):
|
||||
main_xml = """
|
||||
<mujoco>
|
||||
@@ -1391,6 +1390,21 @@ class SpecsTest(absltest.TestCase):
|
||||
with self.assertRaisesRegex(ValueError, 'Frame not found.'):
|
||||
parent.attach(child4, frame='invalid_frame', prefix='child3-')
|
||||
|
||||
def test_delete_from_attached_spec_error(self):
|
||||
parent = mujoco.MjSpec()
|
||||
child = mujoco.MjSpec()
|
||||
body = child.worldbody.add_body(name='child_body')
|
||||
geom = body.add_geom(name='child_geom')
|
||||
|
||||
frame = parent.worldbody.add_frame()
|
||||
parent.attach(child, frame=frame, prefix='child_')
|
||||
|
||||
# Now child spec is attached. Deleting from it should raise ValueError.
|
||||
with self.assertRaisesRegex(
|
||||
ValueError, 'Cannot delete element from an attached mjSpec.'
|
||||
):
|
||||
child.delete(geom)
|
||||
|
||||
def test_attach_valid_child_lists(self):
|
||||
xml1 = """
|
||||
<mujoco>
|
||||
|
||||
Reference in New Issue
Block a user