diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index abf7bd4c3f102f40f22b09b85c5334b87ae41cb4..0074c360ccabe08fb5b64a4b0b09e4ddd467fba5 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,15 +1,43 @@ -# See https://pre-commit.com for more information -# See https://pre-commit.com/hooks.html for more hooks +ci: + autoupdate_branch: 'devel' repos: - repo: https://github.com/pre-commit/mirrors-clang-format - rev: v14.0.6 + rev: v15.0.7 hooks: - id: clang-format args: [--style=Google] - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v3.2.0 + rev: v4.4.0 hooks: - - id: trailing-whitespace - - id: end-of-file-fixer - - id: check-yaml - id: check-added-large-files + - id: check-ast + - id: check-executables-have-shebangs + - id: check-json + - id: check-merge-conflict + - id: check-symlinks + - id: check-toml + - id: check-yaml + - id: debug-statements + - id: destroyed-symlinks + - id: detect-private-key + - id: end-of-file-fixer + - id: fix-byte-order-marker + - id: mixed-line-ending + - id: trailing-whitespace +- repo: https://github.com/psf/black + rev: 22.12.0 + hooks: + - id: black +- repo: https://github.com/charliermarsh/ruff-pre-commit + rev: v0.0.259 + hooks: + - id: ruff + args: [--fix, --exit-non-zero-on-fix] +- repo: https://github.com/cheshirekow/cmake-format-precommit + rev: v0.6.13 + hooks: + - id: cmake-format +- repo: https://github.com/PyCQA/isort + rev: 5.12.0 + hooks: + - id: isort diff --git a/CMakeLists.txt b/CMakeLists.txt index c813255bd299c1652d5568909c8588f0709863c9..7112bcbc68970b89f15260f79b6dc97843bb04cb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,9 +31,9 @@ include(cmake/ros.cmake) compute_project_args(PROJECT_ARGS LANGUAGES CXX) project(${PROJECT_NAME} ${PROJECT_ARGS}) -#if(NOT CMAKE_CXX_STANDARD) +# if(NOT CMAKE_CXX_STANDARD) set(CMAKE_CXX_STANDARD 17) -#endif() +# endif() cmake_policy(SET CMP0057 NEW) find_package(ament_cmake REQUIRED) @@ -83,5 +83,5 @@ install(DIRECTORY include/ DESTINATION include) # Install package information install(FILES package.xml DESTINATION share/${PROJECT_NAME}) -#ROS 2 packaging +# ROS 2 packaging ament_package() diff --git a/README.md b/README.md index 128c5ac7ef41b43a12d13c5a2db7f6f24c7b9964..c2f1ad09a59474e9a8a11efb35e4639cc009e03f 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,7 @@ dynamic-graph bindings [](https://travis-ci.org/stack-of-tasks/dynamic_graph_bridge) [](https://gitlab.laas.fr/stack-of-tasks/dynamic_graph_bridge/commits/master) [](http://projects.laas.fr/gepetto/doc/stack-of-tasks/dynamic_graph_bridge/master/coverage/) +[](https://github.com/charliermarsh/ruff) This ROS package binds together the ROS framework with the dynamic-graph real-time control architecture. diff --git a/include/dynamic_graph_bridge/sot_loader.hh b/include/dynamic_graph_bridge/sot_loader.hh index d2f3c68ab3eede858085f504da6683d4b86ee697..3b0ed29896166e259fa877065083c3c27e09ce7d 100644 --- a/include/dynamic_graph_bridge/sot_loader.hh +++ b/include/dynamic_graph_bridge/sot_loader.hh @@ -28,7 +28,7 @@ #include <thread> // ROS includes -//#include "ros/ros.h" +// #include "ros/ros.h" #include <tf2_ros/transform_broadcaster.h> #include <sensor_msgs/msg/joint_state.hpp> diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000000000000000000000000000000000000..f8f79ada1f0775a746fed7ba5a74030bec1dcd45 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,11 @@ +[tool.black] +exclude = "cmake" + +[tool.ruff] +exclude = ["cmake"] +extend-ignore = ["D203", "D213"] +extend-select = ["A", "B", "C", "COM", "D", "EM", "EXE", "G", "N", "PTH", "RET", "RUF", "UP", "W", "YTT"] +target-version = "py310" + +[tool.isort] +profile = "black" diff --git a/scripts/remote_python_client.py b/scripts/remote_python_client.py old mode 100644 new mode 100755 index 9732f36ac6deb587f5cfb1689ba05a726ab63124..2fb0432e77aa5c017dd8aaf4ab36d0646bb65dc8 --- a/scripts/remote_python_client.py +++ b/scripts/remote_python_client.py @@ -1,6 +1,6 @@ #!/usr/bin/env python -"""@package dynamic_graph_bridge +"""@package dynamic_graph_bridge. @file @license License BSD-3-Clause @@ -11,15 +11,18 @@ embeded terminal. """ +import atexit +import code + # Standard import. import optparse -import os.path -import code import os -import sys +import os.path import readline -import atexit import signal +import sys +from pathlib import Path + import rclpy # Used to connect to ROS services @@ -28,9 +31,7 @@ from dynamic_graph_bridge_cpp_bindings import RosPythonInterpreterClient def signal_handler(sig, frame): - """ - Catch Ctrl+C and quit. - """ + """Catch Ctrl+C and quit.""" print("") print("You pressed Ctrl+C! Closing ros client and shell.") rclpy.try_shutdown() @@ -38,34 +39,33 @@ def signal_handler(sig, frame): # Command history, auto-completetion and keyboard management -python_history = os.path.join(os.environ["HOME"], ".dg_python_history") +python_history = Path.join(os.environ["HOME"], ".dg_python_history") readline.parse_and_bind("tab: complete") readline.set_history_length(100000) def save_history(histfile): - """ Write the history of the user command in a file """ + """Write the history of the user command in a file.""" readline.write_history_file(histfile) """ -Read the current history if it exists and program its save upon the program end. +Read the current history if it exists and program +its save upon the program end. """ if hasattr(readline, "read_history_file"): try: readline.read_history_file(python_history) - except IOError: + except OSError: pass atexit.register(save_history, python_history) class DynamicGraphInteractiveConsole(code.InteractiveConsole): - """ - For the subtilities please read https://docs.python.org/3/library/code.html - """ + """For the subtilities please read https://docs.python.org/3/library/code.html.""" def __init__(self): - + """Create interpreter in ROS for DG interactive console.""" # Create the python terminal code.InteractiveConsole.__init__(self) @@ -78,19 +78,19 @@ class DynamicGraphInteractiveConsole(code.InteractiveConsole): readline.set_completer(self.dg_completer.complete) def runcode(self, code): - """ - Inherited from code.InteractiveConsole + """Inherited from code.InteractiveConsole. - We execute the code pushed in the cache `self.lines_pushed`. The code is - pushed whenever the user press enter during the interactive session. + We execute the code pushed in the cache `self.lines_pushed`. + The code is pushed whenever the user press enter during the + interactive session. see https://docs.python.org/3/library/code.html """ try: # we copy the line in a tmp var code_string = self.lines_pushed[:-1] - result = self.ros_python_interpreter.run_python_command( - code_string - ) + rpi = self.ros_python_interpreter + result = rpi.run_python_command(code_string) + self.write(result) if not result.endswith("\n"): self.write("\n") @@ -101,8 +101,7 @@ class DynamicGraphInteractiveConsole(code.InteractiveConsole): return False def runsource(self, source, filename="<input>", symbol="single"): - """ - Inherited from code.InteractiveConsole + """Inherited from code.InteractiveConsole. see https://docs.python.org/3/library/code.html """ @@ -110,8 +109,7 @@ class DynamicGraphInteractiveConsole(code.InteractiveConsole): c = code.compile_command(source, filename, symbol) if c: return self.runcode(c) - else: - return True + return True except SyntaxError: self.showsyntaxerror() self.lines_pushed = "" @@ -123,11 +121,9 @@ class DynamicGraphInteractiveConsole(code.InteractiveConsole): return False def push(self, line): - """ - Upon pressing enter in the interactive shell the user "push" a string. - This method is then called with the string pushed. - We catch the string to send it via the rosservice. - """ + """Upon pressing enter in the interactive shell the user "push" a string.""" + """This method is then called with the string pushed. + We catch the string to send it via the rosservice.""" self.lines_pushed += line + "\n" return code.InteractiveConsole.push(self, line) @@ -142,14 +138,9 @@ if __name__ == "__main__": if args[:]: infile = args[0] - response = dg_console.ros_python_interpreter.run_python_script( - os.path.abspath(infile) - ) - print( - dg_console.ros_python_interpreter.run_python_command( - "print('File parsed')" - ) - ) + rpi = dg_console.ros_python_interpreter + response = rpi.run_python_script(Path.abspath(infile)) + print(rpi.run_python_command("print('File parsed')")) signal.signal(signal.SIGINT, signal_handler) dg_console.interact("Interacting with remote python server.") diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000000000000000000000000000000000000..15656840ec973b675dfc5cea3d568beb55c9cdcc --- /dev/null +++ b/setup.cfg @@ -0,0 +1,4 @@ +[flake8] +exclude = cmake +max-line-length = 88 +extend-ignore = E203 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 222aa75f1552c1210fd052287ed58abda1d3241e..41a1402c498fa7588326f4ca1b9a01acfeba3d26 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -20,7 +20,8 @@ set(${PROJECT_NAME}_SOURCES ) add_library(ros_bridge SHARED ${${PROJECT_NAME}_SOURCES} ${${PROJECT_NAME}_HEADERS}) -target_include_directories(ros_bridge +target_include_directories( + ros_bridge PUBLIC $<INSTALL_INTERFACE:include> PRIVATE ${PROJECT_SOURCE_DIR}/include) target_link_libraries( @@ -52,19 +53,21 @@ endif(NOT INSTALL_PYTHON_INTERFACE_ONLY) set(plugins ros_publish ros_subscribe) foreach(plugin ${plugins}) get_filename_component(plugin_library_name ${plugin} NAME) - add_library(${plugin_library_name} SHARED - ${PROJECT_SOURCE_DIR}/src/${plugin}.cpp # - ${PROJECT_SOURCE_DIR}/src/${plugin}.hpp # + add_library( + ${plugin_library_name} SHARED ${PROJECT_SOURCE_DIR}/src/${plugin}.cpp # + ${PROJECT_SOURCE_DIR}/src/${plugin}.hpp # ) if(SUFFIX_SO_VERSION) set_target_properties(${plugin_library_name} PROPERTIES SOVERSION - ${PROJECT_VERSION}) + ${PROJECT_VERSION}) endif(SUFFIX_SO_VERSION) target_link_libraries( - ${plugin_library_name} ${${plugin_library_name}_deps} ${catkin_LIBRARIES} ros_bridge + ${plugin_library_name} ${${plugin_library_name}_deps} ${catkin_LIBRARIES} + ros_bridge dynamic_graph_bridge_msgs::dynamic_graph_bridge_msgs__rosidl_typesupport_cpp ) - target_include_directories(${plugin_library_name} + target_include_directories( + ${plugin_library_name} PUBLIC $<INSTALL_INTERFACE:include> PRIVATE ${PROJECT_SOURCE_DIR}/include) if(NOT INSTALL_PYTHON_INTERFACE_ONLY) @@ -86,7 +89,8 @@ foreach(plugin ${plugins}) ${PROJECT_NAME}-${PYTHON_LIBRARY_NAME}-wrap MODULE_HEADER "${CMAKE_CURRENT_SOURCE_DIR}/${plugin}-python.hh") endif() - target_include_directories(${PROJECT_NAME}-${PYTHON_LIBRARY_NAME}-wrap + target_include_directories( + ${PROJECT_NAME}-${PYTHON_LIBRARY_NAME}-wrap PUBLIC $<INSTALL_INTERFACE:include> PRIVATE ${PROJECT_SOURCE_DIR}/include) endif(BUILD_PYTHON_INTERFACE) @@ -100,10 +104,11 @@ endif(BUILD_PYTHON_INTERFACE) # Sot loader library add_library(sot_loader sot_loader.cpp sot_loader_basic.cpp) - target_link_libraries( +target_link_libraries( sot_loader Boost::program_options ${catkin_LIBRARIES} ros_bridge dynamic_graph_bridge_msgs::dynamic_graph_bridge_msgs__rosidl_typesupport_cpp) -target_include_directories(sot_loader +target_include_directories( + sot_loader PUBLIC $<INSTALL_INTERFACE:include> PRIVATE ${PROJECT_SOURCE_DIR}/include) install( @@ -114,10 +119,15 @@ install( # Stand alone embedded intepreter with a robot controller. add_executable(geometric_simu programs/geometric_simu.cpp) target_link_libraries( - geometric_simu Boost::program_options ${CMAKE_DL_LIBS} ${catkin_LIBRARIES} - ros_bridge sot_loader + geometric_simu + Boost::program_options + ${CMAKE_DL_LIBS} + ${catkin_LIBRARIES} + ros_bridge + sot_loader dynamic_graph_bridge_msgs::dynamic_graph_bridge_msgs__rosidl_typesupport_cpp) -target_include_directories(geometric_simu +target_include_directories( + geometric_simu PUBLIC $<INSTALL_INTERFACE:include> PRIVATE ${PROJECT_SOURCE_DIR}/include) install(TARGETS geometric_simu DESTINATION lib/${PROJECT_NAME}) diff --git a/src/dynamic_graph/ros/__init__.py b/src/dynamic_graph/ros/__init__.py index 12ef9f7ed354606843d8e7a74c0a74659fd24904..f91e239768014bdb4efa309104eecdd397abc61c 100644 --- a/src/dynamic_graph/ros/__init__.py +++ b/src/dynamic_graph/ros/__init__.py @@ -1,4 +1,4 @@ -"""@package dynamic_graph_bridge +"""@package dynamic_graph_bridge. @file __init__.py @author Maximilien Naveau (maximilien.naveau@gmail.com) diff --git a/src/dynamic_graph/ros/dgcompleter.py b/src/dynamic_graph/ros/dgcompleter.py index 7c4070893f7de0e86923c108234669f1beb3f8b7..d85e4bb0b0b06c3635eac4e05d8e613bb027422a 100644 --- a/src/dynamic_graph/ros/dgcompleter.py +++ b/src/dynamic_graph/ros/dgcompleter.py @@ -11,8 +11,8 @@ Tip: to use the tab key as the completion key, call readline.parse_and_bind("tab: complete") -Notes: - +Notes +----- - Exceptions raised by the completer function are *ignored* (and generally cause the completion to fail). This is a feature -- since readline sets the tty device in raw (or cbreak) mode, printing a traceback wouldn't work well @@ -35,13 +35,14 @@ its input. """ -import ast from dynamic_graph_bridge_cpp_bindings import RosPythonInterpreterClient __all__ = ["DGCompleter"] class DGCompleter: + """Auto completion for the embedded interpreter.""" + def __init__(self, ros_python_interpreter_client=None): """Create a new completer for the command line. @@ -66,7 +67,7 @@ class DGCompleter: " local_completer=Completer()\n" " import readline\n" " readline.set_completer(local_completer.complete)\n" - ' readline.parse_and_bind("tab: complete")' + ' readline.parse_and_bind("tab: complete")', ] for python_command in cmd: @@ -76,7 +77,9 @@ class DGCompleter: self.buffer = [] def complete(self, text, state): - """Return the next possible completion for 'text'.readline.parse_and_bind("tab: complete") + """Return the next possible completion.""" + """ It returns the next possible completion + for 'text'.readline.parse_and_bind("tab: complete"). This is called successively with state == 0, 1, 2, ... until it returns None. The completion should begin with 'text'. diff --git a/src/dynamic_graph/ros/ros.py b/src/dynamic_graph/ros/ros.py index ca9c4959dd66688e4b21fc482f11a5a51d0ab2cb..70cc2ccaecbae7d1db5882ed1bf7bb76b119a1ed 100644 --- a/src/dynamic_graph/ros/ros.py +++ b/src/dynamic_graph/ros/ros.py @@ -1,4 +1,4 @@ -"""@package dynamic_graph_bridge +"""@package dynamic_graph_bridge. @file ros.py @author Maximilien Naveau (maximilien.naveau@gmail.com) @@ -11,21 +11,20 @@ between ROS and the dynamic graph """ -from dynamic_graph import plug -from dynamic_graph_bridge.dynamic_graph.ros_entities import RosPublish -from dynamic_graph_bridge.dynamic_graph.ros_entities import RosSubscribe +from dynamic_graph_bridge.dynamic_graph.ros_entities import RosPublish, RosSubscribe -class Ros(object): +class Ros: + """Store ros_publish and ros_subscribe.""" + def __init__(self, device, suffix=""): + """Store objects needed for ROS.""" self.device = device self.ros_publish = RosPublish("ros_publish" + suffix) self.ros_subscribe = RosSubscribe("ros_subscribe" + suffix) # make sure that the publishing is done by plugging the refresh # (trigger) to the device periodic call system - self.device.after.addDownsampledSignal( - self.ros_publish.name + ".trigger", 1 - ) + self.device.after.addDownsampledSignal(self.ros_publish.name + ".trigger", 1) # not needed for self.ros_subscribe and self.ros_subscribe as they get # the information from ROS, they do not have output signals diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 9d4a98d76cd1588244fbb9b98f36e4e8f07d2f49..720c139e1c87ef7632ca9d5cb934c35eaf331f61 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -11,23 +11,13 @@ if(BUILD_TESTING) ament_lint_auto_find_test_dependencies() # Library for sot_external_interface - add_library(impl_test_library - SHARED - impl_test_sot_external_interface.cpp - impl_test_sot_mock_device.cpp) + add_library(impl_test_library SHARED impl_test_sot_external_interface.cpp + impl_test_sot_mock_device.cpp) - target_include_directories(impl_test_library - PUBLIC include - ) - target_link_libraries(impl_test_library - PUBLIC sot-core::sot-core - ) - ament_target_dependencies(impl_test_library PUBLIC - dynamic_graph_bridge_msgs - rclcpp - rcl_interfaces - std_srvs - ) + target_include_directories(impl_test_library PUBLIC include) + target_link_libraries(impl_test_library PUBLIC sot-core::sot-core) + ament_target_dependencies(impl_test_library PUBLIC dynamic_graph_bridge_msgs + rclcpp rcl_interfaces std_srvs) # Executable for SotLoaderBasic test add_executable(test_sot_loader_basic test_sot_loader_basic.cpp) target_include_directories( diff --git a/tests/launch/launching_test_sot_loader.py b/tests/launch/launching_test_sot_loader.py index 10a97f5a8fe19e31a70b8c3995e3518d852670ad..cb713bc1cd455ffd70122b1e5e12886455a4a11b 100644 --- a/tests/launch/launching_test_sot_loader.py +++ b/tests/launch/launching_test_sot_loader.py @@ -11,29 +11,25 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +"""Module to test sot_loader.""" -import os -import sys import unittest - -import ament_index_python +from pathlib import Path import launch import launch.actions - import launch_testing import launch_testing.actions -from launch.substitutions import PathJoinSubstitution - +import pytest +from ament_index_python.packages import get_package_share_directory from launch import LaunchDescription +from launch.substitutions import PathJoinSubstitution from launch_ros.actions import Node -from ament_index_python.packages import get_package_share_directory - -import pytest @pytest.mark.launch_test def generate_test_description(): + """Load a simple urdf, parameters and the library.""" ld = LaunchDescription() robot_description_content_path = PathJoinSubstitution( @@ -41,10 +37,11 @@ def generate_test_description(): get_package_share_directory("dynamic_graph_bridge"), "urdf", "dgb_minimal_robot.urdf", - ] + ], ) - robot_description_content = open( - robot_description_content_path.perform(None) + + robot_description_content = Path.open( + robot_description_content_path.perform(None), ).read() params = { @@ -66,20 +63,24 @@ def generate_test_description(): terminating_process, launch_testing.util.KeepAliveProc(), launch_testing.actions.ReadyToTest(), - ] + ], ), locals(), ) class TestSotLoaderBasic(unittest.TestCase): + """Loads the sot_loader.""" + def test_termination(self, terminating_process, proc_info): + """Calls the decorator generate_test_description.""" proc_info.assertWaitForShutdown(process=terminating_process, timeout=(10)) @launch_testing.post_shutdown_test() class TestProcessOutput(unittest.TestCase): + """Handle the test result.""" + def test_exit_code(self, proc_info): - # Check that all processes in the launch (in this case, there's just one) exit - # with code 0 + """Check that all processes in the launch exit with code 0.""" launch_testing.asserts.assertExitCodes(proc_info) diff --git a/tests/launch/launching_test_sot_loader_basic.py b/tests/launch/launching_test_sot_loader_basic.py old mode 100755 new mode 100644 index 0d0b3b8876fa3e94e925bac7c45b8a974083fba8..5a6eba4d557d7748fb1e41453de9981fae5643b2 --- a/tests/launch/launching_test_sot_loader_basic.py +++ b/tests/launch/launching_test_sot_loader_basic.py @@ -11,32 +11,38 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +"""Module to charge a urdf and run a sot_loader_basic class.""" -from pathlib import Path import unittest +from pathlib import Path + import launch import launch.actions import launch_testing import launch_testing.actions -from launch.substitutions import PathJoinSubstitution +import pytest +from ament_index_python.packages import get_package_share_directory from launch import LaunchDescription +from launch.substitutions import PathJoinSubstitution from launch_ros.actions import Node -from ament_index_python.packages import get_package_share_directory -import pytest @pytest.mark.launch_test def generate_test_description(): + """Run a node in dynamic_graph_bridge package. + + It also set parameters state_vector_map and robot_description + """ ld = LaunchDescription() robot_description_content_path = ( - Path(get_package_share_directory("dynamic_graph_bridge")) / - "urdf" / - "dgb_minimal_robot.urdf" + Path(get_package_share_directory("dynamic_graph_bridge")) + / "urdf" + / "dgb_minimal_robot.urdf" ) - assert(robot_description_content_path.exists()) - robot_description_content = open( - PathJoinSubstitution(str(robot_description_content_path)).perform(None) + assert robot_description_content_path.exists() + robot_description_content = Path.open( + PathJoinSubstitution(str(robot_description_content_path)).perform(None), ).read() terminating_process = Node( package="dynamic_graph_bridge", @@ -55,20 +61,24 @@ def generate_test_description(): terminating_process, launch_testing.util.KeepAliveProc(), launch_testing.actions.ReadyToTest(), - ] + ], ), locals(), ) class TestSotLoaderBasic(unittest.TestCase): + """Main class to start the test.""" + def test_termination(self, terminating_process, proc_info): + """Runs the generate_test_description() function.""" proc_info.assertWaitForShutdown(process=terminating_process, timeout=(10)) @launch_testing.post_shutdown_test() class TestProcessOutput(unittest.TestCase): + """Class to handle the test result.""" + def test_exit_code(self, proc_info): - # Check that all processes in the launch (in this case, there's just one) exit - # with code 0 + """Check that all processes in the launch exit with code 0.""" launch_testing.asserts.assertExitCodes(proc_info) diff --git a/tests/python_scripts/simple_add.py b/tests/python_scripts/simple_add.py index 5d8b44e217dbbf707b6964198c7f2a5b719a783c..2cb34e111213fe46a7ded3babdf34d67be9bf6ec 100644 --- a/tests/python_scripts/simple_add.py +++ b/tests/python_scripts/simple_add.py @@ -1 +1,3 @@ -a = 1 + 1 +1 +"""Simple addition test.""" + +a = 1 + 1 + 1 diff --git a/tests/python_scripts/simple_ros_publish.py b/tests/python_scripts/simple_ros_publish.py index 93768af9ce38b83c70dc0d3500531976e9069b6e..3bdc9c80d838d7009e0bbd378be89dced2f21226 100644 --- a/tests/python_scripts/simple_ros_publish.py +++ b/tests/python_scripts/simple_ros_publish.py @@ -1,10 +1,14 @@ +"""Simple module to test interaction with the ROS 2 world.""" + +from dynamic_graph import plug from dynamic_graph.ros.ros_publish import RosPublish +from dynamic_graph.ros.tests.impl_test_sot_mock_device import ImplTestSotMockDevice # Create a topic from the SoT to the ROS world ros_publish = RosPublish("rosPublish") -name="control" +name = "control" ros_publish.add("vector", name + "_ros", name) -device_sot_mock= ImplTestSotMockDevice("device_sot_mock") -plug(device_sot_mock.control, ros_import.signal(name + "_ros")) +device_sot_mock = ImplTestSotMockDevice("device_sot_mock") +plug(device_sot_mock.control, ros_publish.signal(name + "_ros")) diff --git a/tests/test_import.py b/tests/test_import.py index b9195659641eac1ef888bfb8659ee812379ed5c0..461f6f296c2fc50ffa78323c45309871837cabd2 100755 --- a/tests/test_import.py +++ b/tests/test_import.py @@ -1,26 +1,27 @@ #!/usr/bin/env python +"""Test import and simple addition.""" from dynamic_graph.ros import RosImport -ri = RosImport('rosimport') +ri = RosImport("rosimport") -ri.add('double', 'doubleS', 'doubleT') -ri.add('vector', 'vectorS', 'vectorT') -ri.add('matrix', 'matrixS', 'matrixT') +ri.add("double", "doubleS", "doubleT") +ri.add("vector", "vectorS", "vectorT") +ri.add("matrix", "matrixS", "matrixT") -ri.doubleS.value = 42. +ri.doubleS.value = 42.0 ri.vectorS.value = ( - 42., - 42., + 42.0, + 42.0, ) ri.matrixS.value = ( ( - 42., - 42., + 42.0, + 42.0, ), ( - 42., - 42., + 42.0, + 42.0, ), ) diff --git a/tests/test_ros_interpreter.cpp b/tests/test_ros_interpreter.cpp index 0dfc919d861758248ade6909c71d7dd775374348..5ad5523143a2c8d79993b7841c2dab6b1997cd8b 100644 --- a/tests/test_ros_interpreter.cpp +++ b/tests/test_ros_interpreter.cpp @@ -204,10 +204,23 @@ TEST_F(TestRosInterpreter, test_call_run_command_standarderror) { rpi.start_ros_service(); // Create and call the clients. - std::string cmd = "a"; + std::string cmd = "import sys;print(sys.path)"; std::string result = ""; std::string standarderror = ""; std::string standardoutput = ""; + start_run_python_command_ros_service(cmd, result, standarderror, + standardoutput); + std::cout << "standard output:" << standardoutput << std::endl; + + // Create and call the clients. + // std::string + cmd = "a"; + // std::string + result = ""; + // std::string + standarderror = ""; + // std::string + standardoutput = ""; start_run_python_command_ros_service(cmd, result, standarderror, standardoutput); @@ -267,6 +280,8 @@ TEST_F(TestRosInterpreter, test_call_run_script_ros_publish) { std::string file_name = TEST_CONFIG_PATH + std::string("simple_ros_publish.py"); std::string result = ""; + std::string standard_output = ""; + std::string standard_error = ""; start_run_python_script_ros_service(file_name, result); /* Tests. */