fix: 完善 MuJoCo 退出与测试环境
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
"""让 ROS2 系统 pytest 复用项目固定 XR 环境中的 MuJoCo。"""
|
||||
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
XR_SITE_PACKAGES = Path(
|
||||
"/home/robot/miniconda3/envs/xr/lib/python3.10/site-packages"
|
||||
)
|
||||
if XR_SITE_PACKAGES.is_dir():
|
||||
sys.path.append(str(XR_SITE_PACKAGES))
|
||||
@@ -80,7 +80,8 @@ def test_main_closes_viewer_cleanly_on_keyboard_interrupt(monkeypatch) -> None:
|
||||
node.close_viewer = lambda: close_viewer(node)
|
||||
init = Mock()
|
||||
spin = Mock(side_effect=KeyboardInterrupt)
|
||||
sleep = Mock()
|
||||
sleep = Mock(side_effect=[KeyboardInterrupt, None])
|
||||
monotonic = Mock(side_effect=[0.0, 0.0, 0.04])
|
||||
shutdown = Mock()
|
||||
|
||||
monkeypatch.setattr(simulator_module, "DualArmSimulator", lambda: node)
|
||||
@@ -88,6 +89,7 @@ def test_main_closes_viewer_cleanly_on_keyboard_interrupt(monkeypatch) -> None:
|
||||
monkeypatch.setattr(simulator_module.rclpy, "spin", spin)
|
||||
monkeypatch.setattr(simulator_module.rclpy, "ok", lambda: True)
|
||||
monkeypatch.setattr(simulator_module.time, "sleep", sleep)
|
||||
monkeypatch.setattr(simulator_module.time, "monotonic", monotonic)
|
||||
monkeypatch.setattr(simulator_module.rclpy, "shutdown", shutdown)
|
||||
|
||||
simulator_module.main(["--test"])
|
||||
@@ -95,7 +97,9 @@ def test_main_closes_viewer_cleanly_on_keyboard_interrupt(monkeypatch) -> None:
|
||||
init.assert_called_once_with(args=["--test"])
|
||||
spin.assert_called_once_with(node)
|
||||
viewer.close.assert_called_once_with()
|
||||
sleep.assert_called_once_with(0.1)
|
||||
assert [call.args[0] for call in sleep.call_args_list] == pytest.approx(
|
||||
[0.1, 0.06]
|
||||
)
|
||||
node.destroy_node.assert_called_once_with()
|
||||
shutdown.assert_called_once_with()
|
||||
assert node._viewer is None
|
||||
|
||||
Reference in New Issue
Block a user