From 50ae99ca6e5a26ff3ed54e74b6d9c4d047dfd92a Mon Sep 17 00:00:00 2001 From: Kei Okada Date: Thu, 11 May 2023 15:57:27 +0900 Subject: [PATCH] add test to check if ros node is loadable, if use python2 PYTHON_INTERPRETER on 20.04, it fails to load rospy in /opt/ros/melodic. On 18.04 and use python3 PYTHON_INTERPRETER, python3 can load rospy in /opt/ros/noetic .... https://github.com/jsk-ros-pkg/jsk_3rdparty/pull/367 --- ros_google_cloud_language/CMakeLists.txt | 6 +++++- .../test/test_rospy_node.py | 20 +++++++++++++++++++ .../test/test_rospy_node.test | 3 +++ 3 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 ros_google_cloud_language/test/test_rospy_node.py create mode 100644 ros_google_cloud_language/test/test_rospy_node.test diff --git a/ros_google_cloud_language/CMakeLists.txt b/ros_google_cloud_language/CMakeLists.txt index 2503d2b25..234479268 100644 --- a/ros_google_cloud_language/CMakeLists.txt +++ b/ros_google_cloud_language/CMakeLists.txt @@ -52,7 +52,7 @@ catkin_generate_virtualenv( include_directories() -file(GLOB NODE_SCRIPTS_FILES node_scripts/*.py) +file(GLOB NODE_SCRIPTS_FILES node_scripts/*.py test/*.py) file(GLOB SCRIPTS_FILES scripts/*.py) catkin_install_python( PROGRAMS ${NODE_SCRIPTS_FILES} ${SCRIPTS_FILES} @@ -68,3 +68,7 @@ install(FILES requirements.txt DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION} ) +if(CATKIN_ENABLE_TESTING) + find_package(rostest REQUIRED) + add_rostest(test/test_rospy_node.test) +endif() diff --git a/ros_google_cloud_language/test/test_rospy_node.py b/ros_google_cloud_language/test/test_rospy_node.py new file mode 100644 index 000000000..6ece0335f --- /dev/null +++ b/ros_google_cloud_language/test/test_rospy_node.py @@ -0,0 +1,20 @@ +#!/usr/bin/env python + +import rospy +import os, sys, unittest, rostest + +class TestRospyNode(unittest.TestCase): + + def __init__(self, *args): + unittest.TestCase.__init__(self, *args) + + def test_rosnode(self): + __name__ = 'dummy' + scripts_dir = os.path.abspath(os.path.join(os.path.realpath(__file__), os.pardir, os.pardir, 'node_scripts')) + for filename in [f for f in map(lambda x: os.path.join(scripts_dir, x), os.listdir(scripts_dir)) if os.path.isfile(f)]: + print("Check if {} is loadable".format(filename)) + exec(open(filename).read()) in globals(), locals() + self.assertTrue(True) + +if __name__ == '__main__': + rostest.rosrun('test_rospy_node', 'ros_google_cloud_language', TestRospyNode, sys.argv) diff --git a/ros_google_cloud_language/test/test_rospy_node.test b/ros_google_cloud_language/test/test_rospy_node.test new file mode 100644 index 000000000..8efef5fac --- /dev/null +++ b/ros_google_cloud_language/test/test_rospy_node.test @@ -0,0 +1,3 @@ + + +