from types import SimpleNamespace import numpy as np from motrix_envs.locomotion.go1.dreamwaq import _sanitize_dof_pos from motrix_envs.locomotion.go1.walk_np import Go1WalkTask def test_sanitize_dof_pos_handles_zero_quaternion_with_nonfinite_joints(): dof_pos = np.zeros((2, 19), dtype=np.float32) dof_pos[0, 3:7] = 0.0 dof_pos[0, 7] = np.inf dof_pos[1, 3:7] = [0.0, 0.0, 0.5, 0.5] dof_pos[1, 8] = np.nan clean = _sanitize_dof_pos(dof_pos) assert np.isfinite(clean).all() np.testing.assert_allclose(clean[0, 3:7], [0.0, 0.0, 0.0, 1.0]) np.testing.assert_allclose(np.linalg.norm(clean[:, 3:7], axis=1), 1.0) assert clean[0, 7] == 0.0 assert clean[1, 8] == 0.0 def test_apply_action_advances_three_frame_action_history(): task = Go1WalkTask.__new__(Go1WalkTask) task.get_dof_vel = lambda data: np.ones((1, 12), dtype=np.float32) task._compute_torques = lambda actions, data: actions state = SimpleNamespace( data=SimpleNamespace(actuator_ctrls=None), info={ "current_actions": np.full((1, 12), 2.0, dtype=np.float32), "last_actions": np.full((1, 12), 1.0, dtype=np.float32), "last_last_actions": np.zeros((1, 12), dtype=np.float32), }, ) actions = np.full((1, 12), 3.0, dtype=np.float32) task.apply_action(actions, state) actions.fill(9.0) np.testing.assert_array_equal(state.info["last_last_actions"], 1.0) np.testing.assert_array_equal(state.info["last_actions"], 2.0) np.testing.assert_array_equal(state.info["current_actions"], 3.0)