|
9 | 9 |
|
10 | 10 | from __future__ import annotations |
11 | 11 |
|
12 | | -from types import SimpleNamespace |
13 | | -from unittest.mock import MagicMock, patch |
| 12 | +from unittest.mock import MagicMock |
14 | 13 |
|
15 | 14 | import isaaclab_teleop.device_selection as device_selection |
16 | 15 | import isaaclab_teleop.script_input as script_input |
17 | 16 | import pytest |
18 | | -from isaaclab_teleop.isaac_teleop_cfg import CLOUDXR_STANDALONE_ENV |
| 17 | +from isaaclab_teleop.isaac_teleop_cfg import CLOUDXR_STANDALONE_ENV, IsaacTeleopCfg |
19 | 18 | from isaaclab_teleop.script_input import open_teleop_device |
20 | 19 |
|
| 20 | +from isaaclab.devices import Se3KeyboardCfg |
| 21 | + |
21 | 22 | pytestmark = pytest.mark.unit |
22 | 23 |
|
23 | 24 |
|
24 | 25 | def test_without_isaacteleop_opening_a_device_raises(monkeypatch): |
25 | | - monkeypatch.setattr(device_selection, "_isaacteleop_available", lambda: False) |
| 26 | + monkeypatch.setattr(device_selection.importlib.util, "find_spec", lambda _: None) |
26 | 27 | with pytest.raises(ImportError, match="teleop extra"): |
27 | | - with open_teleop_device(SimpleNamespace(name="keyboard", sim_device="cpu")): |
| 28 | + with open_teleop_device(Se3KeyboardCfg(), visualizers=()): |
28 | 29 | pass |
29 | 30 |
|
30 | 31 |
|
31 | 32 | def test_with_isaacteleop_the_pipeline_runs_headset_free(monkeypatch): |
32 | | - monkeypatch.setattr(device_selection, "_isaacteleop_available", lambda: True) |
33 | | - monkeypatch.setattr(script_input, "pipeline_from_device_cfg", lambda cfg, sim_device: f"pipeline:{cfg.name}") |
| 33 | + cfg = IsaacTeleopCfg() |
| 34 | + monkeypatch.setattr(script_input, "select_teleop_cfg", lambda env_cfg, name, defaults, sim_device: cfg) |
34 | 35 | device = MagicMock() |
35 | 36 | device.__enter__.return_value = device |
36 | | - with patch("isaaclab_teleop.isaac_teleop_device.create_isaac_teleop_device", return_value=device) as create: |
37 | | - with open_teleop_device(SimpleNamespace(name="keyboard", sim_device="cpu")) as opened: |
38 | | - assert opened is device |
39 | | - device.request_start.assert_called_once() |
40 | | - device.__exit__.assert_not_called() |
| 37 | + create = MagicMock(return_value=device) |
| 38 | + monkeypatch.setattr(script_input, "create_teleop_device", create) |
| 39 | + visualizers = [object()] |
| 40 | + with open_teleop_device(Se3KeyboardCfg(), visualizers) as opened: |
| 41 | + assert opened is device |
| 42 | + device.request_start.assert_called_once() |
| 43 | + device.__exit__.assert_not_called() |
41 | 44 | create.assert_called_once_with( |
42 | | - "pipeline:keyboard", use_kit_xr_bridge=False, cloudxr_env_file=CLOUDXR_STANDALONE_ENV |
| 45 | + cfg, use_kit_xr_bridge=False, cloudxr_env_file=CLOUDXR_STANDALONE_ENV, visualizers=visualizers |
43 | 46 | ) |
44 | 47 | device.__exit__.assert_called_once() |
0 commit comments