MCPcopy Create free account
hub / github.com/google-deepmind/dm_control / testAdd

Method testAdd

dm_control/mjcf/element_test.py:164–199  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

162 test_invalid_attr_recursively(mujoco)
163
164 def testAdd(self):
165 mujoco = element.RootElement(model='test')
166
167 # repeated elements
168 body_foo_attributes = dict(name='foo', pos=[0, 1, 0], quat=[0, 1, 0, 0])
169 body_foo = mujoco.worldbody.add('body', **body_foo_attributes)
170 self.assertEqual(body_foo.tag, 'body')
171 joint_foo_attributes = dict(name='foo', type='free')
172 joint_foo = body_foo.add('joint', **joint_foo_attributes)
173 self.assertEqual(joint_foo.tag, 'joint')
174 self._test_properties(body_foo, parent=mujoco.worldbody, root=mujoco)
175 self._test_attributes(body_foo, expected_values=body_foo_attributes)
176 self._test_children(body_foo)
177 self._test_properties(joint_foo, parent=body_foo, root=mujoco)
178 self._test_attributes(joint_foo, expected_values=joint_foo_attributes)
179 self._test_children(joint_foo)
180
181 # non-repeated, on-demand elements
182 self.assertIsNone(body_foo.inertial)
183 body_foo_inertial_attributes = dict(mass=1.0, pos=[0, 0, 0])
184 body_foo_inertial = body_foo.add('inertial', **body_foo_inertial_attributes)
185 self._test_properties(body_foo_inertial, parent=body_foo, root=mujoco)
186 self._test_attributes(body_foo_inertial,
187 expected_values=body_foo_inertial_attributes)
188 self._test_children(body_foo_inertial)
189
190 with self.assertRaisesRegex(ValueError, '<inertial> child already exists'):
191 body_foo.add('inertial', **body_foo_inertial_attributes)
192
193 # non-repeated, non-on-demand elements
194 with self.assertRaisesRegex(ValueError, '<compiler> child already exists'):
195 mujoco.add('compiler')
196 self.assertIsNotNone(mujoco.compiler)
197 with self.assertRaisesRegex(ValueError, '<default> child already exists'):
198 mujoco.add('default')
199 self.assertIsNotNone(mujoco.default)
200
201 def testInsert(self):
202 mujoco = element.RootElement(model='test')

Callers

nothing calls this directly

Calls 5

_test_propertiesMethod · 0.95
_test_attributesMethod · 0.95
_test_childrenMethod · 0.95
assertEqualMethod · 0.80
addMethod · 0.45

Tested by

no test coverage detected