def test_rosnode_subscribers( self): # Here we check that this node actually discovers topics # Starting underlying system before rospy.set_param('/string_sub/topic_name', '~test_str_topic' ) # private topic name to not mess things up too much rospy.set_param('/string_sub/test_message', 'testing topic discovery') string_sub_node = roslaunch.core.Node('pyros_test', 'string_sub_node.py', name='string_sub') string_sub_process = self.launch.launch(string_sub_node) try: # Starting PyrosROS with preconfigured subscribers, rosn = PyrosROS( kwargs={ 'subscribers': ['/string_sub/test_str_topic'], 'enable_cache': self.enable_cache }) # careful assuming the topic fullname here try: nose.tools.assert_true(not rosn.is_alive()) rosn.start() nose.tools.assert_true(rosn.is_alive()) print("Discovering subscribers Service...") subscribers = pyzmp.discover( "subscribers", 5) # we wait a bit to let it time to start nose.tools.assert_true(subscribers is not None) print("subscribers providers : {svc}".format( svc=subscribers.providers)) nose.tools.assert_equal(len(subscribers.providers), 1) nose.tools.assert_true( rosn.name in [p[0] for p in subscribers.providers]) res = subscribers.call() # What we get here is non deterministic # however we can wait for topic to be detected to make sure we get it after some time with Timeout(15) as t: while not t.timed_out and not '/string_sub/test_str_topic' in res.keys( ): rospy.rostime.wallsleep(1) res = subscribers.call() nose.tools.assert_true( '/string_sub/test_str_topic' in res.keys( )) # test_topic has been created, detected and exposed finally: # finishing PyrosROS process if rosn is not None and rosn.is_alive(): rosn.shutdown() nose.tools.assert_true(not rosn.is_alive()) finally: # finishing string_pub_process if string_sub_process is not None and string_sub_process.is_alive( ): string_sub_process.stop() nose.tools.assert_true(not string_sub_process.is_alive())
def test_rosnode_creation_termination(self): rosn = PyrosROS() nose.tools.assert_true(not rosn.is_alive()) try: rosn.start() nose.tools.assert_true(rosn.is_alive()) finally: # finishing PyrosROS process if rosn is not None and rosn.is_alive(): rosn.shutdown() nose.tools.assert_true(not rosn.is_alive())
def test_rosnode_services_setup( self ): # Here we check that this node actually provides all the services rosn = PyrosROS() try: nose.tools.assert_true(not rosn.is_alive()) rosn.start() nose.tools.assert_true(rosn.is_alive()) print("Discovering services Service...") services = pyzmp.discover( "services", 5) # we wait a bit to let it time to start nose.tools.assert_true(services is not None) print("services providers : {svc}".format(svc=services.providers)) nose.tools.assert_equal(len(services.providers), 1) nose.tools.assert_true( rosn.name in [p[0] for p in services.providers]) res = services.call() nose.tools.assert_true('echo_service' not in res.keys( )) # test_topic has not been created, detected or exposed print("Discovering setup Service...") setup = pyzmp.discover("setup", 5) # we wait a bit to let it time to start nose.tools.assert_true(setup is not None) print("setup providers : {svc}".format(svc=setup.providers)) nose.tools.assert_equal(len(setup.providers), 1) nose.tools.assert_true( rosn.name in [p[0] for p in setup.providers]) rospy.set_param( '/string_echo/topic_name', '~topic') # private names to not mess things up too much rospy.set_param('/string_echo/echo_topic_name', '~echo_topic') rospy.set_param('/string_echo/echo_service_name', '~echo_service') string_echo_node = roslaunch.core.Node('pyros_test', 'echo.py', name='string_echo') string_echo_process = self.launch.launch(string_echo_node) try: new_config = setup.call( kwargs={ 'services': ['/string_echo/echo_service'], 'topics': [], 'params': [], 'enable_cache': self.enable_cache, }) # What we get here is non deterministic # however we can wait for topic to be detected to make sure we get it after some time res = services.call() with Timeout(5) as t: while not t.timed_out and not '/string_echo/echo_service' in res.keys( ): rospy.rostime.wallsleep(1) res = services.call() nose.tools.assert_true('/string_echo/echo_service' in res.keys( )) # test_topic has been created, detected and exposed finally: # finishing all processes if string_echo_process is not None and string_echo_process.is_alive( ): string_echo_process.stop() nose.tools.assert_true(not string_echo_process.is_alive()) finally: # finishing PyrosROS process if rosn is not None and rosn.is_alive(): rosn.shutdown() nose.tools.assert_true(not rosn.is_alive())
def test_rosnode_services( self): # Here we check that this node actually discovers services # Starting underlying system before rospy.set_param( '/string_echo/topic_name', '~topic') # private names to not mess things up too much rospy.set_param('/string_echo/echo_topic_name', '~echo_topic') rospy.set_param('/string_echo/echo_service_name', '~echo_service') string_echo_node = roslaunch.core.Node('pyros_test', 'echo.py', name='string_echo') try: string_echo_process = self.launch.launch(string_echo_node) except roslaunch.RLException as rlexc: logging.error( "pyros_test is needed to run this test. Please verify that it is installed in your ROS environment" ) raise try: # Starting PyrosROS with preconfigured services to expose rosn = PyrosROS( kwargs={ 'services': ['/string_echo/echo_service'], 'enable_cache': self.enable_cache }) # careful assuming the service fullname here try: nose.tools.assert_true(not rosn.is_alive()) rosn.start() nose.tools.assert_true(rosn.is_alive()) print("Discovering services Service...") services = pyzmp.discover( "services", 5) # we wait a bit to let it time to start nose.tools.assert_true(services is not None) print("services providers : {svc}".format( svc=services.providers)) nose.tools.assert_equal(len(services.providers), 1) nose.tools.assert_true( rosn.name in [p[0] for p in services.providers]) res = services.call() # What we get here is non deterministic # however we can wait for service to be detected to make sure we get it after some time with Timeout(5) as t: while not t.timed_out and not '/string_echo/echo_service' in res.keys( ): rospy.rostime.wallsleep(1) res = services.call() nose.tools.assert_true('/string_echo/echo_service' in res.keys( )) # echo_service has been created, detected and exposed finally: # finishing PyrosROS process if rosn is not None and rosn.is_alive(): rosn.shutdown() nose.tools.assert_true(not rosn.is_alive()) finally: # finishing string_pub_process if string_echo_process is not None and string_echo_process.is_alive( ): string_echo_process.stop() nose.tools.assert_true(not string_echo_process.is_alive())
def test_rosnode_provide_services( self ): # Here we check that this node actually provides all the services rosn = PyrosROS() nose.tools.assert_true(not rosn.is_alive()) try: rosn.start() nose.tools.assert_true(rosn.is_alive()) print("Discovering msg_build Service...") msg_build = pyzmp.discover( "msg_build", 5) # we wait a bit to let it time to start nose.tools.assert_true(msg_build is not None) print( "msg_build providers : {svc}".format(svc=msg_build.providers)) nose.tools.assert_equal(len(msg_build.providers), 1) nose.tools.assert_true( rosn.name in [p[0] for p in msg_build.providers]) print("Discovering topic Service...") topic = pyzmp.discover("topic", 5) # we wait a bit to let it time to start nose.tools.assert_true(topic is not None) print("topic providers : {svc}".format(svc=topic.providers)) nose.tools.assert_equal(len(topic.providers), 1) nose.tools.assert_true( rosn.name in [p[0] for p in topic.providers]) print("Discovering topics Service...") topics = pyzmp.discover("topics", 5) # we wait a bit to let it time to start nose.tools.assert_true(topics is not None) print("topics providers : {svc}".format(svc=topics.providers)) nose.tools.assert_equal(len(topics.providers), 1) nose.tools.assert_true( rosn.name in [p[0] for p in topics.providers]) print("Discovering service Service...") service = pyzmp.discover( "service", 5) # we wait a bit to let it time to start nose.tools.assert_true(service is not None) print("service providers : {svc}".format(svc=service.providers)) nose.tools.assert_equal(len(service.providers), 1) nose.tools.assert_true( rosn.name in [p[0] for p in service.providers]) print("Discovering services Service...") services = pyzmp.discover( "services", 5) # we wait a bit to let it time to start nose.tools.assert_true(services is not None) print("services providers : {svc}".format(svc=services.providers)) nose.tools.assert_equal(len(services.providers), 1) nose.tools.assert_true( rosn.name in [p[0] for p in services.providers]) print("Discovering param Service...") param = pyzmp.discover("param", 5) # we wait a bit to let it time to start nose.tools.assert_true(param is not None) print("param providers : {svc}".format(svc=param.providers)) nose.tools.assert_equal(len(param.providers), 1) nose.tools.assert_true( rosn.name in [p[0] for p in param.providers]) print("Discovering params Service...") params = pyzmp.discover("params", 5) # we wait a bit to let it time to start nose.tools.assert_true(params is not None) print("params providers : {svc}".format(svc=params.providers)) nose.tools.assert_equal(len(params.providers), 1) nose.tools.assert_true( rosn.name in [p[0] for p in params.providers]) print("Discovering setup Service...") setup = pyzmp.discover("setup", 5) # we wait a bit to let it time to start nose.tools.assert_true(setup is not None) print("setup providers : {svc}".format(svc=setup.providers)) nose.tools.assert_equal(len(setup.providers), 1) nose.tools.assert_true( rosn.name in [p[0] for p in setup.providers]) finally: # finishing PyrosROS process if rosn is not None and rosn.is_alive(): rosn.shutdown() nose.tools.assert_true(not rosn.is_alive())