def test_unpublish(self): node_proxy = xmlrpclib.ServerProxy(rospy.get_node_uri()) _, _, pubs = node_proxy.getPublications('/foo') pubs = [p for p in pubs if p[0] != '/rosout'] self.assert_(not pubs, pubs) print "Publishing ", PUBTOPIC pub = rospy.Publisher(PUBTOPIC, String) topic = rospy.resolve_name(PUBTOPIC) _, _, pubs = node_proxy.getPublications('/foo') pubs = [p for p in pubs if p[0] != '/rosout'] self.assertEquals([[topic, String._type]], pubs, "Pubs were %s" % pubs) # publish about 10 messages for fun for i in xrange(0, 10): pub.publish(String("hi [%s]" % i)) time.sleep(0.1) # begin actual test by unsubscribing pub.unregister() # make sure no new messages are received in the next 2 seconds timeout_t = time.time() + 2.0 while timeout_t < time.time(): time.sleep(1.0) self.assert_(_last_callback is None) # verify that close cleaned up master and node state _, _, pubs = node_proxy.getPublications('/foo') pubs = [p for p in pubs if p[0] != '/rosout'] self.assert_(not pubs, "Node still has pubs: %s" % pubs) n = rospy.get_caller_id() self.assert_(not rostest.is_publisher(topic, n), "publication is still active on master")
def test_unpublish(self): node_proxy = ServerProxy(rospy.get_node_uri()) _, _, pubs = node_proxy.getPublications('/foo') pubs = [p for p in pubs if p[0] != '/rosout'] self.assert_(not pubs, pubs) print("Publishing ", PUBTOPIC) pub = rospy.Publisher(PUBTOPIC, String) topic = rospy.resolve_name(PUBTOPIC) _, _, pubs = node_proxy.getPublications('/foo') pubs = [p for p in pubs if p[0] != '/rosout'] self.assertEquals([[topic, String._type]], pubs, "Pubs were %s"%pubs) # publish about 10 messages for fun for i in range(0, 10): pub.publish(String("hi [%s]"%i)) time.sleep(0.1) # begin actual test by unsubscribing pub.unregister() # make sure no new messages are received in the next 2 seconds timeout_t = time.time() + 2.0 while timeout_t < time.time(): time.sleep(1.0) self.assert_(_last_callback is None) # verify that close cleaned up master and node state _, _, pubs = node_proxy.getPublications('/foo') pubs = [p for p in pubs if p[0] != '/rosout'] self.assert_(not pubs, "Node still has pubs: %s"%pubs) n = rospy.get_caller_id() self.assert_(not rostest.is_publisher(topic, n), "publication is still active on master")
def test_is_display_publisher_connected(self): assert rostest.is_publisher(rospy.resolve_name(_DISPLAY_TOPIC), rospy.resolve_name(_GUI_NODE)) test_display_subscriber = rospy.Subscriber( _DISPLAY_TOPIC, Display, callback=self.display_subscriber_callback)
def test_is_face_publisher_connected(self): assert rostest.is_publisher(rospy.resolve_name(_PLAY_FACE_TOPIC), rospy.resolve_name(_MANAGER_NODE)) test_face_subscriber = rospy.Subscriber( _PLAY_FACE_TOPIC, FaceRequest, callback=self.face_subscriber_callback)
def test_is_wav_file_publisher_connected(self): assert rostest.is_publisher(rospy.resolve_name(_PLAY_WAV_FILE_TOPIC), rospy.resolve_name(_MANAGER_NODE)) test_wav_file_subscriber = rospy.Subscriber( _PLAY_WAV_FILE_TOPIC, String, callback=self.wave_file_subscriber_callback)
def test_is_prompt_publisher_connected(self): assert rostest.is_publisher(rospy.resolve_name(_USER_PROMPTED_TOPIC), rospy.resolve_name(_GUI_NODE)) test_display_subscriber = rospy.Subscriber( _USER_PROMPTED_TOPIC, Empty, callback=self.display_subscriber_callback)
def test_subscribe_to_multiple_publishers(self): # wait so that all connections are established time.sleep(1.0) # ensure that publishers are publishing for i in range(1, NUMBER_OF_TALKERS + 1): self.assert_(rostest.is_publisher( rospy.resolve_name(TOPIC), rospy.resolve_name(TALKER_NODE % i)), 'talker node %d is not up' % i) # ensure that subscriber is subscribed self.assert_(rostest.is_subscriber( rospy.resolve_name(TOPIC), rospy.resolve_name(LISTENER_NODE)), 'listener node is not up') # check number of connections from subscriber to the topic connections = 0 master = rosgraph.Master(NAME) node_api = master.lookupNode(LISTENER_NODE) if not node_api: self.assert_(False, 'cannot contact [%s]: unknown node' % LISTENER_NODE) socket.setdefaulttimeout(5.0) node = xmlrpclib.ServerProxy(node_api) code, _, businfo = node.getBusInfo(NAME) if code != 1: self.assert_(False, 'cannot get node information') if businfo: for info in businfo: topic = info[4] if len(info) > 5: connected = info[5] else: connected = True # backwards compatibility if connected: if topic == TOPIC: connections += 1 self.assert_(connections == NUMBER_OF_TALKERS, 'Found only %d connections instead of %d' % (connections, NUMBER_OF_TALKERS))
def test_is_idle_publisher_connected(self): assert rostest.is_publisher(rospy.resolve_name(_IS_FACE_IDLE_TOPIC), rospy.resolve_name(_MANAGER_NODE)) test_is_idle_subscriber = rospy.Subscriber( _PLAY_GESTURE_TOPIC, String, self.gesture_subscriber_callback)
def test_message_publisher(self): assert rostest.is_publisher( rospy.resolve_name(_MESSAGE_TOPIC), rospy.resolve_name(_PUBLISHER_NODE) )