From e6851c85f1ca09cdd2d62ae93538f3e8a36e846f Mon Sep 17 00:00:00 2001 From: shalenikol Date: Tue, 20 May 2025 10:25:11 +0300 Subject: [PATCH] add package rbs_tests (with testing recording demo) --- rbs_tests/CMakeLists.txt | 12 ++++ .../integration_tests/integration_tests.py | 61 +++++++++++++++++++ rbs_tests/package.xml | 16 +++++ 3 files changed, 89 insertions(+) create mode 100644 rbs_tests/CMakeLists.txt create mode 100755 rbs_tests/integration_tests/integration_tests.py create mode 100644 rbs_tests/package.xml diff --git a/rbs_tests/CMakeLists.txt b/rbs_tests/CMakeLists.txt new file mode 100644 index 0000000..731cf0b --- /dev/null +++ b/rbs_tests/CMakeLists.txt @@ -0,0 +1,12 @@ +cmake_minimum_required(VERSION 3.10) +project(rbs_tests) + +find_package(ament_cmake REQUIRED) + +if(BUILD_TESTING) + find_package(rbs_utils REQUIRED) + find_package(launch_testing_ament_cmake) + add_launch_test(integration_tests/integration_tests.py) +endif() + +ament_package() diff --git a/rbs_tests/integration_tests/integration_tests.py b/rbs_tests/integration_tests/integration_tests.py new file mode 100755 index 0000000..0e0dc72 --- /dev/null +++ b/rbs_tests/integration_tests/integration_tests.py @@ -0,0 +1,61 @@ +#!/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) diff --git a/rbs_tests/package.xml b/rbs_tests/package.xml new file mode 100644 index 0000000..1ff18b4 --- /dev/null +++ b/rbs_tests/package.xml @@ -0,0 +1,16 @@ + + + + rbs_tests + 0.0.1 + Integration tests for the Robossembler-ROS2 + shalenikol + Apache-2.0 + + launch + launch_ros + rbs_utils + + launch_testing_ament_cmake + +