62 lines
2.1 KiB
Python
62 lines
2.1 KiB
Python
|
#!/usr/bin/env python3
|
||
|
# import os
|
||
|
import unittest
|
||
|
from unittest.mock import patch, MagicMock
|
||
|
|
||
|
# import rclpy
|
||
|
# from rclpy.executors import SingleThreadedExecutor
|
||
|
from rbs_utils.recording_demo import recording_demo, CommandType
|
||
|
|
||
|
import launch
|
||
|
import launch_ros
|
||
|
import launch_testing
|
||
|
import launch_testing.actions
|
||
|
# import launch_testing.asserts
|
||
|
import pytest
|
||
|
|
||
|
@pytest.mark.rostest
|
||
|
def generate_test_description():
|
||
|
test_node = launch_ros.actions.Node(
|
||
|
package="rbs_bt_executor",
|
||
|
executable="rbs_interface.py",
|
||
|
output="screen"
|
||
|
# parameters = [{"bt_path": skills_cfg_file},{"mode": mode},{"use_sim_time": True}]
|
||
|
)
|
||
|
|
||
|
return launch.LaunchDescription([
|
||
|
test_node,
|
||
|
launch_testing.actions.ReadyToTest(),
|
||
|
]), { 'test_node': test_node }
|
||
|
|
||
|
class TestRecordingDemo(unittest.TestCase):
|
||
|
|
||
|
def setUp(self):
|
||
|
# Предполагается, что ROS 2 окружение запущено
|
||
|
pass
|
||
|
|
||
|
def test_run_command_returns_bool(self):
|
||
|
with patch("rbs_utils.recording_demo.RbsActionClient") as MockClient:
|
||
|
mock_client_instance = MockClient.return_value
|
||
|
mock_client_instance.res_ok = True
|
||
|
mock_client_instance.send_goal = MagicMock()
|
||
|
|
||
|
result = recording_demo(CommandType.RUN)
|
||
|
self.assertTrue(result)
|
||
|
mock_client_instance.send_goal.assert_called_with(
|
||
|
sid=unittest.mock.ANY, action="RecordingDemo", command="rdConfigure")
|
||
|
|
||
|
def test_stop_and_cancel_triggers_stop(self):
|
||
|
with patch("rbs_utils.recording_demo.RbsActionClient") as MockClient:
|
||
|
mock_client_instance = MockClient.return_value
|
||
|
mock_client_instance.res_ok = True
|
||
|
mock_client_instance.send_goal = MagicMock()
|
||
|
|
||
|
result = recording_demo(CommandType.STOP_AND_CANCEL)
|
||
|
self.assertTrue(result)
|
||
|
mock_client_instance.send_goal.assert_called_with(
|
||
|
sid=unittest.mock.ANY, action="RecordingDemo", command="rdStop")
|
||
|
|
||
|
def test_invalid_command_returns_false(self):
|
||
|
result = recording_demo("nonexistent_command")
|
||
|
self.assertFalse(result)
|