Capture mjs_attach error message in the Python bindings.

PiperOrigin-RevId: 682409212
Change-Id: I391ee48626e7dcd985f65a231370ef5ec16124d7
This commit is contained in:
Alessio Quaglino
2024-10-04 12:18:36 -07:00
committed by Copybara-Service
parent 3091665c16
commit 6e66cafe76
8 changed files with 68 additions and 3 deletions
+15
View File
@@ -846,5 +846,20 @@ class SpecsTest(absltest.TestCase):
with self.assertRaises(IndexError):
material.textures[-1] = 'x'
def test_attach_error(self):
child = mujoco.MjSpec()
parent = mujoco.MjSpec()
parent.degree = not child.degree
body = parent.worldbody.add_body()
frame = child.worldbody.add_frame()
with self.assertRaises(ValueError) as cm:
body.attach_frame(frame, '', '')
self.assertEqual(
str(cm.exception),
'Error: cannot attach mjSpecs with incompatible compiler/angle'
' attribute',
)
if __name__ == '__main__':
absltest.main()