# wait for node to be started node_api = None with Timeout(5) as t: while not t.timed_out and node_api is None: node_api = rosnode.get_api_uri(rospy.get_master(), 'connection_cache') assert node_api is not None # make sure the connection cache node is started before moving on. self.connection_cache = connection_cache_proxy_create() def tearDown(self): self.publisher_if_pool = None self.connection_cache_proc.stop() while self.connection_cache_proc.is_alive(): time.sleep(0.2) # waiting for cache node to die assert not self.connection_cache_proc.is_alive() time.sleep(1) # TODO : investigate : we shouldnt need this if __name__ == '__main__': # Note : Tests should be able to run with nosetests, or rostest ( which will launch nosetest here ) rostest_nose.rostest_or_nose_main('test_publisher_if_pool_no_cache', 'test_all', TestRosInterface1NoCache) # Note : Tests should be able to run with nosetests, or rostest ( which will launch nosetest here ) rostest_nose.rostest_or_nose_main('test_publisher_if_pool_cache', 'test_all', TestRosInterfaceCache)
assert self.connection_cache_proc.is_alive() # wait for node to be started node_api = None with Timeout(5) as t: while not t.timed_out and node_api is None: node_api = rosnode.get_api_uri(rospy.get_master(), 'connection_cache') assert node_api is not None # make sure the connection cache node is started before moving on. self.connection_cache = connection_cache_proxy_create() def tearDown(self): self.service_if_pool = None self.connection_cache_proc.stop() while self.connection_cache_proc.is_alive(): time.sleep(0.2) # waiting for cache node to die assert not self.connection_cache_proc.is_alive() time.sleep(1) # TODO : investigate : we shouldnt need this if __name__ == '__main__': # Note : Tests should be able to run with nosetests, or rostest ( which will launch nosetest here ) rostest_nose.rostest_or_nose_main('test_service_if_pool_no_cache', 'test_all', TestRosInterface1NoCache) # Note : Tests should be able to run with nosetests, or rostest ( which will launch nosetest here ) rostest_nose.rostest_or_nose_main('test_service_if_pool_cache', 'test_all', TestRosInterfaceCache)
# Assert there is no difference assert_true( len( set(six.iteritems(resp)) ^ set(six.iteritems({'response': self.test_message}))) == 0) except KeyboardInterrupt: self.fail("Test Interrupted !") #TODO # def test_slow_service_timeout(self): # # try: # self.logPoint() # # print("calling : {msg} on service {service}".format(msg=self.test_message, service=self.slow_service.name)) # with self.assertRaises(TypeError): # resp = self.slow_service.call(self.slow_service.rostype_req(self.test_message)) # self.assertIn(resp.response, [self.test_message]) # # except KeyboardInterrupt: # self.fail("Test Interrupted !") if __name__ == '__main__': print("ARGV : %r", sys.argv) # Note : Tests should be able to run with nosetests, or rostest ( which will launch nosetest here ) rostest_nose.rostest_or_nose_main('pyros', 'testService', TestService, sys.argv)
# Topics are up. Use them. print("sending : {msg} on topic {topic}".format( msg=self.test_message, topic=self.pub_topic.name)) msg = pub_topic_class() # TODO : better serialization populate_instance({'data': self.test_message}, msg) if isinstance(msg, pub_topic_class): self.pub_topic.publish( msg ) # This should return False if publisher not fully setup yet # CAREFUL the return spec of rospy's publish is not consistent print("waiting for : {msg} on topic {topic}".format( msg={'data': self.test_message}, topic=self.pub_if.name)) msg = self.msg_wait({'data': self.test_message}, self.pub_if) # We assert there is no difference assert_true( len( set(six.iteritems(msg)) ^ set(six.iteritems({'data': self.test_message}))) == 0) except KeyboardInterrupt: self.fail("Test Interrupted !") if __name__ == '__main__': print("ARGV : %r", sys.argv) # Note : Tests should be able to run with nosetests, or rostest ( which will launch nosetest here ) rostest_nose.rostest_or_nose_main('pyros', 'testStringPublisher', TestStringPublisher, sys.argv)
# note we cannot test cleanup here. Assuming rostest does it properly. # Tests Needed to validate that tests written for nose with pyros can also work with rostest # if called from usual rostest testCase def test_import_after_delay_setup_teardown_module(self): test_import_after_delay_setup_teardown_module() def test_import_before_delay_setup_teardown_module(self): test_import_before_delay_setup_teardown_module() if __name__ == '__main__': print("Running with ROStest if launched with rostest...") # testing rostest to validate rostests will still work. from pyros_utils import rostest_nose rostest_nose.rostest_or_nose_main('pyros_utils', 'testRosTest', testRosTest, sys.argv) if rostest_nose.is_rostest_enabled(): print("Force running with nose even if launched with rostest...") # Needed to validate that rostest_nose.rostest_or_nose_main will work fine if calling nose # we need to remove options that nose doesnt know #print(sys.argv) for opt in sys.argv[1:]: # we keep argv[0] if opt.startswith("--gtest_output") or opt.startswith("__name") or opt.startswith("__log") or opt.startswith("--text"): sys.argv.remove(opt) #print(sys.argv) rostest_nose.rostest_enabled = False # as well as nose
self.sub_if = SubscriberBack(self.sub_topic_name, sub_topic_type) # Making sure the topic interface is ready to be used just after creation # by checking the number of connections on the actual subscriber subs_connected = self.sub_topic.impl.get_num_connections( ) # no local subs assert_true(subs_connected == 1) # Topics are up. Use them. print("sending : {msg} on topic {topic}".format( msg=self.test_message, topic=self.sub_if.name)) assert_true(self.sub_if.publish({'data': self.test_message})) print("waiting for : {msg} on topic {topic}".format( msg={'data': self.test_message}, topic=self.sub_topic.name)) msg = self.msg_wait({'data': self.test_message}, self.sub_topic) # We assert there is no difference assert_true( len( set(six.iteritems(msg)) ^ set(six.iteritems({'data': self.test_message}))) == 0) except KeyboardInterrupt: self.fail("Test Interrupted !") if __name__ == '__main__': print("ARGV : %r", sys.argv) # Note : Tests should be able to run with nosetests, or rostest ( which will launch nosetest here ) rostest_nose.rostest_or_nose_main('pyros', 'testStringSubscriber', TestStringSubscriber, sys.argv)