Skip to content

Commit

Permalink
add test to check if ros node is loadable, if use python2 PYTHON_INTE…
Browse files Browse the repository at this point in the history
…RPRETER 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 .... #367
  • Loading branch information
k-okada committed May 11, 2023
1 parent 4eca2bb commit 50ae99c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
6 changes: 5 additions & 1 deletion ros_google_cloud_language/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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()
20 changes: 20 additions & 0 deletions ros_google_cloud_language/test/test_rospy_node.py
Original file line number Diff line number Diff line change
@@ -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)
3 changes: 3 additions & 0 deletions ros_google_cloud_language/test/test_rospy_node.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<launch>
<test pkg="ros_google_cloud_language" type="test_rospy_node.py" test-name="ros_rospy_node" />
</launch>

0 comments on commit 50ae99c

Please sign in to comment.