def testLoadXML(self): with open(HUMANOID_XML_PATH, "r") as f: xml_string = f.read() model = core.MjModel.from_xml_string(xml_string) core.MjData(model) with self.assertRaises(TypeError): core.MjModel() with self.assertRaises(core.Error): core.MjModel.from_xml_path("/path/to/nonexistent/model/file.xml") xml_with_warning = """ <mujoco> <size njmax='2'/> <worldbody> <body pos='0 0 0'> <geom type='box' size='.1 .1 .1'/> </body> <body pos='0 0 0'> <joint type='slide' axis='1 0 0'/> <geom type='box' size='.1 .1 .1'/> </body> </worldbody> </mujoco>""" # This model should compile successfully, but raise a warning on the first # simulation step. model = core.MjModel.from_xml_string(xml_with_warning) data = core.MjData(model) with mock.patch.object(core, "logging") as mock_logging: mjlib.mj_step(model.ptr, data.ptr) mock_logging.warn.assert_called_once_with( "Pre-allocated constraint buffer is full. Increase njmax above 2. " "Time = 0.0000.")
def testLoadXML(self): with open(HUMANOID_XML_PATH, "r") as f: xml_string = f.read() model = core.MjModel.from_xml_string(xml_string) core.MjData(model) with self.assertRaises(TypeError): core.MjModel() with self.assertRaises(core.Error): core.MjModel.from_xml_path("/path/to/nonexistent/model/file.xml") xml_with_warning = """ <mujoco> <size njmax='2'/> <worldbody> <body pos='0 0 0'> <geom type='box' size='.1 .1 .1'/> </body> <body pos='0 0 0'> <joint type='slide' axis='1 0 0'/> <geom type='box' size='.1 .1 .1'/> </body> </worldbody> </mujoco>""" with mock.patch.object(core, "logging") as mock_logging: core.MjModel.from_xml_string(xml_with_warning) mock_logging.warn.assert_called_once_with( "Error: Pre-allocated constraint buffer is full. " "Increase njmax above 2. Time = 0.0000.")