def test_MsgContext(): from genmsg.msg_loader import MsgContext, load_msg_from_file msg_context = MsgContext() assert not msg_context.is_registered('time') assert not msg_context.is_registered('duration') msg_context = MsgContext.create_default() # tripwires repr(msg_context) str(msg_context) assert msg_context.is_registered('time'), msg_context._registered_packages assert msg_context.is_registered('duration') assert not msg_context.is_registered('test_ros/TestString') assert not msg_context.is_registered('Header') # start loading stuff into context test_d = get_test_dir() test_ros_dir = os.path.join(test_d, 'test_ros', 'msg') test_string_path = os.path.join(test_ros_dir, 'TestString.msg') spec = load_msg_from_file(msg_context, test_string_path, 'test_ros/TestString') msg_context.register('test_ros/TestString', spec) assert msg_context.get_registered('test_ros/TestString') == spec try: msg_context.get_registered('bad/TestString') assert False, 'should have raised' except KeyError: pass assert msg_context.is_registered('test_ros/TestString') # test Header assert not msg_context.is_registered('Header') assert not msg_context.is_registered('std_msgs/Header') msg_context.register('std_msgs/Header', spec) assert msg_context.is_registered('std_msgs/Header')
print('Unable to import ROS1 tools. Please source a ROS1 installation first.', end='', file=sys.stderr) sys.exit(1) import argparse import copy import em import os import sys if sys.version_info[0] > 2: from io import StringIO as BufferIO else: from io import BytesIO as BufferIO g_msg_context = MsgContext() def get_type_components(full_type): if full_type == 'Header': return ('std_msgs', 'Header') components = full_type.split('/') if len(components) != 2: raise ValueError('Unexpected value for message type string: {}'.format(full_type)) package = components[0] end = components[1].find('[') if end == -1: type = components[1] else: