Skip to content

Commit 394b6ff

Browse files
committed
test: add coverage for shift+z/c keys and omni_angular keyboard action
1 parent f72ac9a commit 394b6ff

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

tests/test_env.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1234,6 +1234,46 @@ def test_desired_omni_vel_no_goal(self, env_factory):
12341234
assert np.allclose(vel, np.zeros((2, 1)))
12351235

12361236

1237+
class TestAssignKeyboardAction:
1238+
"""Tests for _assign_keyboard_action with different kinematics."""
1239+
1240+
def test_omni_angular_keyboard_action(self, env_factory):
1241+
"""Test keyboard action conversion for omni_angular robot."""
1242+
env = env_factory("test_keyboard_control2.yaml")
1243+
# Temporarily set control mode to keyboard
1244+
original_mode = env._world_param.control_mode
1245+
env._world_param.control_mode = "keyboard"
1246+
env.keyboard.key_vel = np.array([[1.0], [0.5], [0.3]])
1247+
1248+
# Mock robot kinematics name
1249+
robot = env.robot_list[env.key_id]
1250+
original_kf_name = robot.kf.name if robot.kf else None
1251+
1252+
# Test omni_angular
1253+
if robot.kf:
1254+
robot.kf.name = "omni_angular"
1255+
action = [np.zeros((3, 1)) for _ in range(len(env.robot_list))]
1256+
result = env._assign_keyboard_action(action)
1257+
vel = result[env.key_id]
1258+
assert vel.shape == (3, 1)
1259+
assert vel[0, 0] == pytest.approx(1.0)
1260+
assert vel[1, 0] == pytest.approx(0.5)
1261+
assert vel[2, 0] == pytest.approx(0.3)
1262+
1263+
# Test omni
1264+
if robot.kf:
1265+
robot.kf.name = "omni"
1266+
action = [np.zeros((2, 1)) for _ in range(len(env.robot_list))]
1267+
result = env._assign_keyboard_action(action)
1268+
vel = result[env.key_id]
1269+
assert vel.shape == (2, 1)
1270+
1271+
# Restore
1272+
if robot.kf:
1273+
robot.kf.name = original_kf_name
1274+
env._world_param.control_mode = original_mode
1275+
1276+
12371277
class TestMidProcessEdgeCases:
12381278
"""Tests for ObjectBase.mid_process state padding/truncation."""
12391279

tests/test_keyboard.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,16 @@ def test_zc_adjust_ang_max(self, env_factory, mock_keyboard_key):
116116
env.keyboard._on_pynput_release(mock_keyboard_key("z"))
117117
assert env.keyboard.key_ang_max < prev_ang_max + 0.2
118118

119+
def test_shift_zc_adjust_lv_max(self, env_factory, mock_keyboard_key):
120+
"""Test Shift+Z/C (uppercase) keys adjust linear velocity max."""
121+
env = env_factory("test_keyboard_control.yaml")
122+
env.keyboard._active_only = False
123+
prev_lv_max = env.keyboard.key_lv_max
124+
env.keyboard._on_pynput_release(mock_keyboard_key("C"))
125+
assert env.keyboard.key_lv_max == pytest.approx(prev_lv_max + 0.2)
126+
env.keyboard._on_pynput_release(mock_keyboard_key("Z"))
127+
assert env.keyboard.key_lv_max == pytest.approx(prev_lv_max)
128+
119129
def test_r_key_sets_reset_flag(self, env_factory, mock_keyboard_key):
120130
"""Test 'r' key sets reset flag."""
121131
env = env_factory("test_keyboard_control.yaml")
@@ -320,6 +330,17 @@ def test_ang_max_adjustment(self, env_factory, mock_mpl_event):
320330
env.keyboard._on_mpl_release(mock_mpl_event("z"))
321331
assert env.keyboard.key_ang_max < prev_ang_max + 0.2
322332

333+
def test_shift_zc_lv_max_adjustment(self, env_factory, mock_mpl_event):
334+
"""Test Shift+Z/C keys adjust linear velocity max in mpl backend."""
335+
env = env_factory("test_keyboard_control2.yaml")
336+
337+
prev_lv_max = env.keyboard.key_lv_max
338+
env.keyboard._on_mpl_release(mock_mpl_event("shift+c"))
339+
assert env.keyboard.key_lv_max == pytest.approx(prev_lv_max + 0.2)
340+
341+
env.keyboard._on_mpl_release(mock_mpl_event("shift+z"))
342+
assert env.keyboard.key_lv_max == pytest.approx(prev_lv_max)
343+
323344
def test_space_pause_resume(self, env_factory, mock_mpl_event):
324345
"""Test space key toggles pause/resume in mpl backend."""
325346
env = env_factory("test_keyboard_control2.yaml")

0 commit comments

Comments
 (0)