def test_mocknode_topics_detect_throttled(): """ Testing that the mocknode detection of topics is throttled properly :return: """ mockn = PyrosMock() assert_false(mockn.is_alive()) assert_true(hasattr(mockn, 'topics')) mockn.update_interval = 5 # we wait 5 seconds between each update_throttled call mockn.start( ) # one update will be triggered, and then nothing for the next 10 seconds try: assert_true(mockn.is_alive()) print("Discovering setup Service...") setup = zmp.discover("setup", 3) # we wait a bit to let it time to start assert_false(setup is None) assert_equal(len(setup.providers), 1) setup.call(kwargs={ 'services': [], 'topics': ['test_topic'], 'params': [] }) with mock_topic_remote('test_topic', statusecho_topic): print("Discovering topics Service...") topics = zmp.discover("topics", 3) # we wait a bit to let it time to start assert_false(topics is None) assert_equal(len(topics.providers), 1) # topic is very likely not detected yet ( we didn't wait after creating and exposing it ) res = topics.call() assert_true(not 'test_topic' in res) time.sleep(mockn.update_interval + 1) # make sure we let update time to kick in # topic has to be detected now res = topics.call() assert_true('test_topic' in res) finally: # to make sure we clean up on failure mockn.shutdown() assert_false(mockn.is_alive())
def test_service_comm_to_double_sub_self(self): print("\n" + inspect.currentframe().f_code.co_name) assert_false(self.hwnode.is_alive()) self.hwnode.magic_number = 42 self.hwnode.start() assert_true(self.hwnode.is_alive()) assert_false(self.hwnodeextra.is_alive()) self.hwnodeextra.magic_number = 79 self.hwnodeextra.start() assert_true(self.hwnodeextra.is_alive()) print "Discovering getlucky Service..." getlucky = zmp.discover( "getlucky", 5, 2) # make sure we get both providers. we need them. assert_true(getlucky is not None) # to make sure we get a service provided assert_equal(len(getlucky.providers), 2) resp = getlucky.call() print "42 || 79 ? -> {0}".format(resp) assert_true(resp == 42 or resp == 79) resp = getlucky.call(node=self.hwnode.name) print "42 ? -HNode-> {0}".format(resp) assert_true(resp == 42) resp = getlucky.call(node=self.hwnodeextra.name) print "79 ? -HNodeExtra-> {0}".format(resp) assert_true(resp == 79) self.hwnode.shutdown() assert_false(self.hwnode.is_alive()) self.hwnodeextra.shutdown() assert_false(self.hwnodeextra.is_alive())
def test_service_double_comm_to_sub_self(self): print("\n" + inspect.currentframe().f_code.co_name) assert_false(self.hwnode.is_alive()) self.hwnode.magic_number = 42 self.hwnode.start() assert_true(self.hwnode.is_alive()) print "Discovering getlucky Service..." getlucky = zmp.discover("getlucky", 5) assert_true(getlucky is not None) # to make sure we get a service provided def callit(): getlucky = zmp.discover("getlucky", 5) return getlucky.call() c = multiprocessing.Process(name="Client", target=callit) assert_false(c.is_alive()) c.start() assert_true(c.is_alive()) resp = getlucky.call() print "42 ? -> {0}".format(resp) assert_true(resp == 42) resp = getlucky.call(node=self.hwnode.name) print "42 ? -HNode-> {0}".format(resp) assert_true(resp == 42) c.join() assert_false(c.is_alive()) self.hwnode.shutdown() assert_false(self.hwnode.is_alive())
def test_service_discover_timeout(self): print("\n" + inspect.currentframe().f_code.co_name) assert_false(self.hwnode.is_alive()) print "Discovering helloworld Service..." helloworld = zmp.discover("helloworld") assert_true( helloworld is None) # service not provided until node starts print "Discovering helloworld Service..." helloworld = zmp.discover("helloworld", 1) # check timeout actually times out assert_true(helloworld is None) print "Discovering helloworld Service..." helloworld = zmp.discover("helloworld", 1, 2) assert_true(helloworld is None)
def test_mocknode_topics_detect_setup( ): # Here we check that this node actually detects a topic upon setup mockn = PyrosMock() assert_false(mockn.is_alive()) assert_true(hasattr(mockn, 'topics')) mockn.start() try: assert_true(mockn.is_alive()) with mock_topic_remote('test_topic', statusecho_topic): print("Discovering topics Service...") topics = zmp.discover("topics", 3) # we wait a bit to let it time to start assert_false(topics is None) assert_equal(len(topics.providers), 1) res = topics.call() assert_true( not 'test_topic' in res ) # topic not detected since not in list of exposed topics print("Discovering setup Service...") setup = zmp.discover("setup", 3) # we wait a bit to let it time to start assert_false(setup is None) assert_equal(len(setup.providers), 1) setup.call(kwargs={ 'services': [], 'topics': ['test_topic'], 'params': [] }) time.sleep(mockn.update_interval + 1) # waiting for update to kick in res = topics.call() assert_true('test_topic' in res) finally: mockn.shutdown() assert_false(mockn.is_alive())
def test_service_discover_multiple_queue(self): print("\n" + inspect.currentframe().f_code.co_name) assert_false(self.hwnode.is_alive()) print "Discovering helloworld Service..." helloworld = zmp.discover("helloworld") assert_true( helloworld is None) # service not provided until node starts # Start two nodes queue process self.hwnodeextra.start() assert_true(self.hwnodeextra.is_alive()) print "Discovering helloworld Service..." helloworld = zmp.discover("helloworld", 5) # we wait a bit to let it time to start assert_false(helloworld is None) assert_equal(len(helloworld.providers), 1) self.hwnode.start() assert_true(self.hwnode.is_alive()) print "Discovering helloworld Service..." helloworld = zmp.discover( "helloworld", 5, 2) # we wait until we get 2 providers ( or timeout ) assert_false(helloworld is None) assert_equal(len(helloworld.providers), 2) self.hwnodeextra.shutdown() assert_false(self.hwnodeextra.is_alive()) print "Discovering helloworld Service..." helloworld = zmp.discover("helloworld", 5) # we wait a bit to let it time to start assert_false(helloworld is None) assert_equal(len(helloworld.providers), 1) self.hwnode.shutdown() assert_false(self.hwnode.is_alive())
def test_service_discover(self): print("\n" + inspect.currentframe().f_code.co_name) assert_false(self.hwnode.is_alive()) print "Discovering helloworld Service..." helloworld = zmp.discover("helloworld") assert_true( helloworld is None) # service not provided until node starts self.hwnode.start() assert_true(self.hwnode.is_alive()) print "Discovering helloworld Service..." helloworld = zmp.discover("helloworld", 5) # we wait a bit to let it time to start assert_false(helloworld is None) assert_equal(len(helloworld.providers), 1) self.hwnode.shutdown() assert_false(self.hwnode.is_alive()) print "Discovering helloworld Service..." helloworld = zmp.discover("helloworld") assert_true(helloworld is None)
def test_mocknode_topics_detect( ): # Here we check that this node actually detects a topic mockn = PyrosMock(kwargs={ 'services': [], 'topics': ['test_topic'], 'params': [] }) assert_false(mockn.is_alive()) assert_true(hasattr(mockn, 'topics')) # starting the node mockn.start() # checking interface is still None here ( instantiated in child only ) assert_true(mockn.interface is None) # Services are initialized in run() method of zmp.Node, after interface has been initialized try: assert_true(mockn.is_alive()) with mock_topic_remote('test_topic', statusecho_topic): # asserting the mock system has done its job from our point of view at least assert_true('test_topic' in topics_available_remote) assert_equal(topics_available_type_remote['test_topic'], statusecho_topic) # Getting topics list from child process print("Discovering topics Service...") topics = zmp.discover("topics", 3) # we wait a bit to let it time to start assert_false(topics is None) assert_equal(len(topics.providers), 1) time.sleep(mockn.update_interval + 1) # make sure we let update time to kick in res = topics.call(recv_timeout=6000000) # the mock system should have done its job from the other process perspective too # via multiprocess manager list assert_true( 'test_topic' in res) # topic detected since in list of exposed topics finally: mockn.shutdown() assert_false(mockn.is_alive())
def test_service_except_from_sub(self): print("\n" + inspect.currentframe().f_code.co_name) assert_false(self.hwnode.is_alive()) self.hwnode.start() assert_true(self.hwnode.is_alive()) print "Discovering breakworld Service..." breakworld = zmp.discover("breakworld", 5) assert_true(breakworld is not None) # to make sure we get a service provided with assert_raises(Exception) as cm: resp = breakworld.call(args=("Hello", )) self.hwnode.shutdown() assert_false(self.hwnode.is_alive())
def test_service_params_comm_to_sub(self): print("\n" + inspect.currentframe().f_code.co_name) assert_false(self.hwnode.is_alive()) self.hwnode.start() assert_true(self.hwnode.is_alive()) print "Discovering add Service..." add = zmp.discover("add", 5) assert_true(add is not None) # to make sure we get a service provided resp = add.call(args=(17, 25)) print " 17 + 25 -> {0}".format(resp) assert_true(resp == 17 + 25) self.hwnode.shutdown() assert_false(self.hwnode.is_alive())
def test_service_comm_to_sub_self(self): print("\n" + inspect.currentframe().f_code.co_name) assert_false(self.hwnode.is_alive()) self.hwnode.magic_number = 42 self.hwnode.start() assert_true(self.hwnode.is_alive()) print "Discovering getlucky Service..." getlucky = zmp.discover("getlucky", 5) assert_true(getlucky is not None) # to make sure we get a service provided resp = getlucky.call() print "42 ? -> {0}".format(resp) assert_true(resp == 42) self.hwnode.shutdown() assert_false(self.hwnode.is_alive())
def test_service_comm_to_sub(self): print("\n" + inspect.currentframe().f_code.co_name) assert_false(self.hwnode.is_alive()) self.hwnode.start() assert_true(self.hwnode.is_alive()) print "Discovering helloworld Service..." helloworld = zmp.discover("helloworld", 5) assert_true(helloworld is not None) # to make sure we get a service provided resp = helloworld.call(args=("Hello", )) print "Hello -> {0}".format(resp) assert_true(resp == "Hello! I am HNode") resp = helloworld.call(args=("Hallo", )) print "Hallo -> {0}".format(resp) assert_true(resp == "...") self.hwnode.shutdown() assert_false(self.hwnode.is_alive())
def test_service_except_from_node_no_service(self): print("\n" + inspect.currentframe().f_code.co_name) assert_false(self.hwnode.is_alive()) self.hwnode.start() assert_true(self.hwnode.is_alive()) print "Discovering breakworld Service..." breakworld = zmp.discover("breakworld", 5) assert_true(breakworld is not None) # to make sure we get a service provided # messing around even if we should not breakworld.name = "NOT_EXISTING" with assert_raises(zmp.UnknownServiceException) as cm: resp = breakworld.call(args=("Hello", )) self.hwnode.shutdown() assert_false(self.hwnode.is_alive())
def test_service_comm_to_double_sub(self): print("\n" + inspect.currentframe().f_code.co_name) assert_false(self.hwnode.is_alive()) self.hwnode.start() assert_true(self.hwnode.is_alive()) assert_false(self.hwnodeextra.is_alive()) self.hwnodeextra.start() assert_true(self.hwnodeextra.is_alive()) print "Discovering helloworld Service..." helloworld = zmp.discover( "helloworld", 5, 2) # make sure we get both providers. we need them. assert_true(helloworld is not None) # to make sure we get a service provided assert_equal(len(helloworld.providers), 2) resp = helloworld.call(args=("Hello", )) print "Hello -> {0}".format(resp) assert_true(resp == "Hello! I am HNode" or resp == "Hello! I am HNodeExtra") resp = helloworld.call(args=("Hallo", )) print "Hallo -> {0}".format(resp) assert_true(resp == "...") resp = helloworld.call(args=("Hello", ), node=self.hwnode.name) print "Hello -HNode-> {0}".format(resp) assert_true(resp == "Hello! I am HNode") resp = helloworld.call(args=("Hello", ), node=self.hwnodeextra.name) print "Hello -HNodeExtra-> {0}".format(resp) assert_true(resp == "Hello! I am HNodeExtra") self.hwnode.shutdown() assert_false(self.hwnode.is_alive()) self.hwnodeextra.shutdown() assert_false(self.hwnodeextra.is_alive())
def test_service_double_comm_to_sub(self): print("\n" + inspect.currentframe().f_code.co_name) assert_false(self.hwnode.is_alive()) self.hwnode.start() assert_true(self.hwnode.is_alive()) print "Discovering helloworld Service..." helloworld = zmp.discover("helloworld", 5) assert_true(helloworld is not None) # to make sure we get a service provided def callit(): hw = zmp.discover("helloworld", 5) return hw.call(args=("Hello", )) c = multiprocessing.Process(name="Client", target=callit) assert_false(c.is_alive()) c.start() assert_true(c.is_alive()) resp = helloworld.call(args=("Hello", )) print "Hallo -> {0}".format(resp) assert_true(resp == "Hello! I am HNode") resp = helloworld.call(args=("Hallo", )) print "Hallo -> {0}".format(resp) assert_true(resp == "...") resp = helloworld.call(args=("Hello", ), node=self.hwnode.name) print "Hello -HNode-> {0}".format(resp) assert_true(resp == "Hello! I am HNode") c.join() assert_false(c.is_alive()) self.hwnode.shutdown() assert_false(self.hwnode.is_alive())
def callit(): getlucky = zmp.discover("getlucky", 5) return getlucky.call()
def test_mocknode_provide_services( ): # Here we check that this node actually provides all the services mockn = PyrosMock() assert_false(mockn.is_alive()) assert_true(hasattr(mockn, 'msg_build')) assert_true(hasattr(mockn, 'topic')) assert_true(hasattr(mockn, 'topics')) assert_true(hasattr(mockn, 'service')) assert_true(hasattr(mockn, 'services')) assert_true(hasattr(mockn, 'param')) assert_true(hasattr(mockn, 'params')) assert_true(hasattr(mockn, 'setup')) mockn.start() try: assert_true(mockn.is_alive()) print("Discovering msg_build Service...") msg_build = zmp.discover("msg_build", 5) # we wait a bit to let it time to start assert_false(msg_build is None) assert_equal(len(msg_build.providers), 1) print("Discovering topic Service...") topic = zmp.discover("topic", 5) # we wait a bit to let it time to start assert_false(topic is None) assert_equal(len(topic.providers), 1) print("Discovering topics Service...") topic_list = zmp.discover("topics", 5) # we wait a bit to let it time to start assert_false(topic_list is None) assert_equal(len(topic_list.providers), 1) print("Discovering service Service...") service = zmp.discover("service", 5) # we wait a bit to let it time to start assert_false(service is None) assert_equal(len(service.providers), 1) print("Discovering services Service...") service_list = zmp.discover("services", 5) # we wait a bit to let it time to start assert_false(service_list is None) assert_equal(len(service_list.providers), 1) print("Discovering param Service...") param = zmp.discover("param", 5) # we wait a bit to let it time to start assert_false(param is None) assert_equal(len(param.providers), 1) print("Discovering params Service...") param_list = zmp.discover("params", 5) # we wait a bit to let it time to start assert_false(param_list is None) assert_equal(len(param_list.providers), 1) print("Discovering setup Service...") param_list = zmp.discover("setup", 5) # we wait a bit to let it time to start assert_false(param_list is None) assert_equal(len(param_list.providers), 1) finally: mockn.shutdown() assert_false(mockn.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 = zmp.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 = zmp.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 = zmp.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 = zmp.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 = zmp.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 = zmp.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 = zmp.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 = zmp.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())
def callit(): hw = zmp.discover("helloworld", 5) return hw.call(args=("Hello", ))
def test_rosnode_topics( self): # Here we check that this node actually discovers topics # Starting underlying system before rospy.set_param('/string_pub/topic_name', '~test_str_topic' ) # private topic name to not mess things up too much rospy.set_param('/string_pub/test_message', 'testing topic discovery') string_pub_node = roslaunch.core.Node('pyros_test', 'string_pub_node.py', name='string_pub') string_pub_process = self.launch.launch(string_pub_node) try: # Starting PyrosROS with preconfigured topics, # disabling dynamic_reconf to avoid override asynchronously on start(). rosn = PyrosROS( kwargs={ 'topics': ['/string_pub/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 topics Service...") topics = zmp.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]) start = time.time() timeout = 15 # should be enough to let the node start (?) res = topics.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 while time.time( ) - start < timeout and not '/string_pub/test_str_topic' in res.keys( ): rospy.rostime.wallsleep(1) res = topics.call() nose.tools.assert_true( '/string_pub/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_pub_process is not None and string_pub_process.is_alive( ): string_pub_process.stop() nose.tools.assert_true(not string_pub_process.is_alive())
def test_rosnode_topics_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 topics Service...") topics = zmp.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]) res = topics.call() nose.tools.assert_true('test_topic' not in res.keys( )) # test_topic has not been created, detected or exposed print("Discovering setup Service...") setup = zmp.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_pub/topic_name', '~test_str_topic') rospy.set_param('/string_pub/test_message', 'testing topic discovery') string_pub_node = roslaunch.core.Node('pyros_test', 'string_pub_node.py', name='string_pub') string_pub_process = self.launch.launch(string_pub_node) try: new_config = setup.call( kwargs={ 'services': [], 'topics': ['/string_pub/test_str_topic'], '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 start = time.time() timeout = 15 # should be enough to let the node start (?) res = topics.call() while time.time( ) - start < timeout and not '/string_pub/test_str_topic' in res.keys( ): rospy.rostime.wallsleep(1) res = topics.call() nose.tools.assert_true( '/string_pub/test_str_topic' in res.keys( )) # test_topic has been created, detected and exposed finally: # finishing all processes if string_pub_process is not None and string_pub_process.is_alive( ): string_pub_process.stop() nose.tools.assert_true(not string_pub_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 topics # 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 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 = zmp.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_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 = zmp.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 = zmp.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())