def test_mj_error_called(): error_message = None def error_callback(msg): nonlocal error_message error_message = msg.decode() cymj.set_error_callback(error_callback) functions.mju_error("error") assert error_message == "error"
def test_mj_error_raises(): def error_callback(msg): raise RuntimeError(msg.decode()) cymj.set_error_callback(error_callback) called = False try: with cymj.wrap_mujoco_warning(): functions.mju_error("error") except RuntimeError as e: assert e.args[0] == "error" called = True assert called
def test_mj_error_callback(): message = None called = False def callback(msg): nonlocal message message = msg.decode() raise RuntimeError(message) cymj.set_error_callback(callback) try: with cymj.wrap_mujoco_warning(): functions.mju_error("error") except RuntimeError as e: assert e.args[0] == "error" assert message == "error" called = True assert called