本文整理汇总了Python中genmsg.msg_loader.MsgContext.register方法的典型用法代码示例。如果您正苦于以下问题:Python MsgContext.register方法的具体用法?Python MsgContext.register怎么用?Python MsgContext.register使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类genmsg.msg_loader.MsgContext
的用法示例。
在下文中一共展示了MsgContext.register方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_MsgContext
# 需要导入模块: from genmsg.msg_loader import MsgContext [as 别名]
# 或者: from genmsg.msg_loader.MsgContext import register [as 别名]
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")
示例2: test_MsgContext
# 需要导入模块: from genmsg.msg_loader import MsgContext [as 别名]
# 或者: from genmsg.msg_loader.MsgContext import register [as 别名]
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')