本文整理汇总了Python中genmsg.msg_loader.MsgContext.create_default方法的典型用法代码示例。如果您正苦于以下问题:Python MsgContext.create_default方法的具体用法?Python MsgContext.create_default怎么用?Python MsgContext.create_default使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类genmsg.msg_loader.MsgContext
的用法示例。
在下文中一共展示了MsgContext.create_default方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_load_msg_depends_stamped
# 需要导入模块: from genmsg.msg_loader import MsgContext [as 别名]
# 或者: from genmsg.msg_loader.MsgContext import create_default [as 别名]
def test_load_msg_depends_stamped():
# TODO: should there just be a 'load_msg, implicit=True?'
from genmsg.msg_loader import MsgContext, load_msg_by_type, load_msg_depends
test_d = get_test_dir()
geometry_d = os.path.join(test_d, "geometry_msgs", "msg")
search_path = {
"test_ros": os.path.join(test_d, "test_ros", "msg"),
"std_msgs": os.path.join(test_d, "std_msgs", "msg"),
"geometry_msgs": geometry_d,
"sensor_msgs": os.path.join(test_d, "sensor_msgs", "msg"),
}
# Test with Stamped and deeper hierarchies, Header
msg_context = MsgContext.create_default()
root_spec = load_msg_by_type(msg_context, "geometry_msgs/PoseStamped", search_path)
load_msg_depends(msg_context, root_spec, search_path)
file_p = os.path.join(test_d, "geometry_msgs", "msg", "PoseStamped.msg")
assert file_p == msg_context.get_file("geometry_msgs/PoseStamped")
val = msg_context.get_depends("geometry_msgs/PoseStamped")
assert set(["std_msgs/Header", "geometry_msgs/Pose", "geometry_msgs/Point", "geometry_msgs/Quaternion"]) == set(
val
), val
for s in ["Header"]:
file_p = os.path.join(test_d, "std_msgs", "msg", "%s.msg" % s)
assert file_p == msg_context.get_file("std_msgs/%s" % s)
for s in ["Pose", "Point", "Quaternion"]:
file_p = os.path.join(geometry_d, "%s.msg" % s)
assert file_p == msg_context.get_file("geometry_msgs/%s" % s)
msg_context = MsgContext.create_default()
root_spec = load_msg_by_type(msg_context, "geometry_msgs/TwistWithCovarianceStamped", search_path)
load_msg_depends(msg_context, root_spec, search_path)
file_p = os.path.join(test_d, "geometry_msgs", "msg", "TwistWithCovarianceStamped.msg")
assert file_p == msg_context.get_file("geometry_msgs/TwistWithCovarianceStamped")
val = msg_context.get_depends("geometry_msgs/TwistWithCovarianceStamped")
assert set(
["std_msgs/Header", "geometry_msgs/TwistWithCovariance", "geometry_msgs/Twist", "geometry_msgs/Vector3"]
) == set(val), val
for s in ["Header"]:
file_p = os.path.join(test_d, "std_msgs", "msg", "%s.msg" % s)
assert file_p == msg_context.get_file("std_msgs/%s" % s)
for s in ["TwistWithCovariance", "Twist", "Vector3"]:
file_p = os.path.join(geometry_d, "%s.msg" % s)
assert file_p == msg_context.get_file("geometry_msgs/%s" % s)
msg_context = MsgContext.create_default()
root_spec = load_msg_by_type(msg_context, "sensor_msgs/Imu", search_path)
load_msg_depends(msg_context, root_spec, search_path)
file_p = os.path.join(test_d, "sensor_msgs", "msg", "Imu.msg")
assert file_p == msg_context.get_file("sensor_msgs/Imu")
val = msg_context.get_depends("sensor_msgs/Imu")
assert set(["std_msgs/Header", "geometry_msgs/Quaternion", "geometry_msgs/Vector3"]) == set(val), val
for s in ["Header"]:
file_p = os.path.join(test_d, "std_msgs", "msg", "%s.msg" % s)
assert file_p == msg_context.get_file("std_msgs/%s" % s)
for s in ["Quaternion", "Vector3"]:
file_p = os.path.join(geometry_d, "%s.msg" % s)
assert file_p == msg_context.get_file("geometry_msgs/%s" % s)
示例2: test_load_msg_depends
# 需要导入模块: from genmsg.msg_loader import MsgContext [as 别名]
# 或者: from genmsg.msg_loader.MsgContext import create_default [as 别名]
def test_load_msg_depends():
# TODO: should there just be a 'load_msg, implicit=True?'
from genmsg.msg_loader import MsgContext, load_msg_by_type, load_msg_depends, MsgNotFound
test_d = get_test_dir()
search_path = {
"test_ros": os.path.join(test_d, "test_ros", "msg"),
"std_msgs": os.path.join(test_d, "std_msgs", "msg"),
"geometry_msgs": os.path.join(test_d, "geometry_msgs", "msg"),
"sensor_msgs": os.path.join(test_d, "sensor_msgs", "msg"),
"invalid": os.path.join(test_d, "invalid", "msg"),
}
# Test not found
msg_context = MsgContext.create_default()
root_spec = load_msg_by_type(msg_context, "invalid/BadDepend", search_path)
try:
load_msg_depends(msg_context, root_spec, search_path)
assert False, "should have raised MsgNotFound"
except MsgNotFound:
pass
root_spec = load_msg_by_type(msg_context, "invalid/BadLocalDepend", search_path)
try:
load_msg_depends(msg_context, root_spec, search_path)
assert False, "should have raised MsgNotFound"
except MsgNotFound:
pass
msg_context = MsgContext.create_default()
root_spec = load_msg_by_type(msg_context, "std_msgs/Int32", search_path)
load_msg_depends(msg_context, root_spec, search_path)
file_p = os.path.join(test_d, "std_msgs", "msg", "Int32.msg")
assert file_p == msg_context.get_file("std_msgs/Int32")
assert [] == msg_context.get_depends("std_msgs/Int32")
msg_context = MsgContext.create_default()
root_spec = load_msg_by_type(msg_context, "std_msgs/Header", search_path)
load_msg_depends(msg_context, root_spec, search_path)
file_p = os.path.join(test_d, "std_msgs", "msg", "Header.msg")
assert file_p == msg_context.get_file("std_msgs/Header")
assert [] == msg_context.get_depends("std_msgs/Header")
msg_context = MsgContext.create_default()
root_spec = load_msg_by_type(msg_context, "Header", search_path)
load_msg_depends(msg_context, root_spec, search_path)
file_p = os.path.join(test_d, "std_msgs", "msg", "Header.msg")
assert file_p == msg_context.get_file("std_msgs/Header")
assert [] == msg_context.get_depends("std_msgs/Header")
msg_context = MsgContext.create_default()
root_spec = load_msg_by_type(msg_context, "std_msgs/Int32MultiArray", search_path)
load_msg_depends(msg_context, root_spec, search_path)
file_p = os.path.join(test_d, "std_msgs", "msg", "Int32MultiArray.msg")
assert file_p == msg_context.get_file("std_msgs/Int32MultiArray")
val = msg_context.get_depends("std_msgs/Int32MultiArray")
assert 2 == len(val)
assert set(["std_msgs/MultiArrayLayout", "std_msgs/MultiArrayDimension"]) == set(val), val
for s in ["MultiArrayLayout", "MultiArrayDimension"]:
file_p = os.path.join(test_d, "std_msgs", "msg", "%s.msg" % s)
assert file_p == msg_context.get_file("std_msgs/%s" % s)
示例3: test_load_depends_msg
# 需要导入模块: from genmsg.msg_loader import MsgContext [as 别名]
# 或者: from genmsg.msg_loader.MsgContext import create_default [as 别名]
def test_load_depends_msg():
from genmsg.msg_loader import MsgContext, load_msg_by_type, load_depends, MsgNotFound, load_srv_by_type
test_d = get_test_dir()
geometry_d = os.path.join(test_d, 'geometry_msgs', 'msg')
msg_search_path = {
'test_ros': [ os.path.join(test_d, 'test_ros', 'msg') ],
'std_msgs': [ os.path.join(test_d, 'std_msgs', 'msg') ],
'geometry_msgs': [ geometry_d ],
'sensor_msgs': [ os.path.join(test_d, 'sensor_msgs', 'msg') ],
'invalid': [ os.path.join(test_d, 'invalid', 'msg') ],
}
# Test not found
msg_context = MsgContext.create_default()
root_spec = load_msg_by_type(msg_context, 'invalid/BadDepend', msg_search_path)
try:
load_depends(msg_context, root_spec, msg_search_path)
assert False, "should have raised MsgNotFound"
except MsgNotFound:
pass
root_spec = load_msg_by_type(msg_context, 'invalid/BadLocalDepend', msg_search_path)
try:
load_depends(msg_context, root_spec, msg_search_path)
assert False, "should have raised MsgNotFound"
except MsgNotFound:
pass
# Test with msgs
msg_context = MsgContext.create_default()
root_spec = load_msg_by_type(msg_context, 'geometry_msgs/PoseStamped', msg_search_path)
load_depends(msg_context, root_spec, msg_search_path)
file_p = os.path.join(test_d, 'geometry_msgs', 'msg', 'PoseStamped.msg')
assert file_p == msg_context.get_file('geometry_msgs/PoseStamped')
val = msg_context.get_all_depends('geometry_msgs/PoseStamped')
assert set(['std_msgs/Header', 'geometry_msgs/Pose', 'geometry_msgs/Point', 'geometry_msgs/Quaternion']) == set(val), val
val = msg_context.get_depends('geometry_msgs/PoseStamped')
assert set(['std_msgs/Header', 'geometry_msgs/Pose']) == set(val), val
for s in ['Header']:
file_p = os.path.join(test_d, 'std_msgs', 'msg', '%s.msg'%s)
assert file_p == msg_context.get_file('std_msgs/%s'%s)
for s in ['Pose', 'Point', 'Quaternion']:
file_p = os.path.join(geometry_d, '%s.msg'%s)
assert file_p == msg_context.get_file('geometry_msgs/%s'%s)
msg_context = MsgContext.create_default()
root_spec = load_msg_by_type(msg_context, 'sensor_msgs/Imu', msg_search_path)
load_depends(msg_context, root_spec, msg_search_path)
file_p = os.path.join(test_d, 'sensor_msgs', 'msg', 'Imu.msg')
assert file_p == msg_context.get_file('sensor_msgs/Imu')
val = msg_context.get_depends('sensor_msgs/Imu')
assert set(['std_msgs/Header', 'geometry_msgs/Quaternion', 'geometry_msgs/Vector3']) == set(val), val
for s in ['Header']:
file_p = os.path.join(test_d, 'std_msgs', 'msg', '%s.msg'%s)
assert file_p == msg_context.get_file('std_msgs/%s'%s)
for s in ['Quaternion', 'Vector3']:
file_p = os.path.join(geometry_d, '%s.msg'%s)
assert file_p == msg_context.get_file('geometry_msgs/%s'%s)
示例4: test_load_depends_msg
# 需要导入模块: from genmsg.msg_loader import MsgContext [as 别名]
# 或者: from genmsg.msg_loader.MsgContext import create_default [as 别名]
def test_load_depends_msg():
from genmsg.msg_loader import MsgContext, load_msg_by_type, load_depends, MsgNotFound, load_srv_by_type
test_d = get_test_dir()
geometry_d = os.path.join(test_d, "geometry_msgs", "msg")
msg_search_path = {
"test_ros": os.path.join(test_d, "test_ros", "msg"),
"std_msgs": os.path.join(test_d, "std_msgs", "msg"),
"geometry_msgs": geometry_d,
"sensor_msgs": os.path.join(test_d, "sensor_msgs", "msg"),
"invalid": os.path.join(test_d, "invalid", "msg"),
}
# Test not found
msg_context = MsgContext.create_default()
root_spec = load_msg_by_type(msg_context, "invalid/BadDepend", msg_search_path)
try:
load_depends(msg_context, root_spec, msg_search_path)
assert False, "should have raised MsgNotFound"
except MsgNotFound:
pass
root_spec = load_msg_by_type(msg_context, "invalid/BadLocalDepend", msg_search_path)
try:
load_depends(msg_context, root_spec, msg_search_path)
assert False, "should have raised MsgNotFound"
except MsgNotFound:
pass
# Test with msgs
msg_context = MsgContext.create_default()
root_spec = load_msg_by_type(msg_context, "geometry_msgs/PoseStamped", msg_search_path)
load_depends(msg_context, root_spec, msg_search_path)
file_p = os.path.join(test_d, "geometry_msgs", "msg", "PoseStamped.msg")
assert file_p == msg_context.get_file("geometry_msgs/PoseStamped")
val = msg_context.get_depends("geometry_msgs/PoseStamped")
assert set(["std_msgs/Header", "geometry_msgs/Pose", "geometry_msgs/Point", "geometry_msgs/Quaternion"]) == set(
val
), val
for s in ["Header"]:
file_p = os.path.join(test_d, "std_msgs", "msg", "%s.msg" % s)
assert file_p == msg_context.get_file("std_msgs/%s" % s)
for s in ["Pose", "Point", "Quaternion"]:
file_p = os.path.join(geometry_d, "%s.msg" % s)
assert file_p == msg_context.get_file("geometry_msgs/%s" % s)
msg_context = MsgContext.create_default()
root_spec = load_msg_by_type(msg_context, "sensor_msgs/Imu", msg_search_path)
load_depends(msg_context, root_spec, msg_search_path)
file_p = os.path.join(test_d, "sensor_msgs", "msg", "Imu.msg")
assert file_p == msg_context.get_file("sensor_msgs/Imu")
val = msg_context.get_depends("sensor_msgs/Imu")
assert set(["std_msgs/Header", "geometry_msgs/Quaternion", "geometry_msgs/Vector3"]) == set(val), val
for s in ["Header"]:
file_p = os.path.join(test_d, "std_msgs", "msg", "%s.msg" % s)
assert file_p == msg_context.get_file("std_msgs/%s" % s)
for s in ["Quaternion", "Vector3"]:
file_p = os.path.join(geometry_d, "%s.msg" % s)
assert file_p == msg_context.get_file("geometry_msgs/%s" % s)
示例5: test_load_depends_srv
# 需要导入模块: from genmsg.msg_loader import MsgContext [as 别名]
# 或者: from genmsg.msg_loader.MsgContext import create_default [as 别名]
def test_load_depends_srv():
from genmsg.msg_loader import MsgContext, load_msg_by_type, load_depends, MsgNotFound, load_srv_by_type
test_d = get_test_dir()
geometry_d = os.path.join(test_d, "geometry_msgs", "msg")
msg_search_path = {
"test_ros": [os.path.join(test_d, "test_ros", "msg")],
"std_msgs": [os.path.join(test_d, "std_msgs", "msg")],
"geometry_msgs": [geometry_d],
"sensor_msgs": [os.path.join(test_d, "sensor_msgs", "msg")],
"invalid": [os.path.join(test_d, "invalid", "msg")],
}
# Test with srvs
srv_search_path = {
"test_ros": [os.path.join(test_d, "test_ros", "srv")],
"std_srvs": [os.path.join(test_d, "std_srvs", "srv")],
}
msg_context = MsgContext.create_default()
root_spec = load_srv_by_type(msg_context, "test_ros/AddTwoInts", srv_search_path)
load_depends(msg_context, root_spec, msg_search_path)
val = msg_context.get_depends("test_ros/AddTwoIntsRequest")
assert val == [], val
val = msg_context.get_depends("test_ros/AddTwoIntsResponse")
assert val == [], val
# test with srv that has depends
msg_context = MsgContext.create_default()
response_deps = [
"std_msgs/Header",
"geometry_msgs/Pose",
"geometry_msgs/PoseStamped",
"geometry_msgs/Point",
"geometry_msgs/Quaternion",
]
root_spec = load_srv_by_type(msg_context, "test_ros/GetPoseStamped", srv_search_path)
load_depends(msg_context, root_spec, msg_search_path)
for d in response_deps:
assert msg_context.is_registered(d)
val = msg_context.get_depends("test_ros/GetPoseStampedRequest")
assert val == [], val
val = msg_context.get_depends("test_ros/GetPoseStampedResponse")
assert val == ["geometry_msgs/PoseStamped"]
# Test with nonsense
class Foo(object):
pass
try:
load_depends(msg_context, Foo(), msg_search_path)
assert False, "should have raised"
except ValueError:
pass
示例6: test_compute_import
# 需要导入模块: from genmsg.msg_loader import MsgContext [as 别名]
# 或者: from genmsg.msg_loader.MsgContext import create_default [as 别名]
def test_compute_import():
import genpy.generator
msg_context = MsgContext.create_default()
assert [] == genpy.generator.compute_import(msg_context, 'foo', 'bar')
assert [] == genpy.generator.compute_import(msg_context, 'foo', 'int32')
msg_context.register('ci_msgs/Base', MsgSpec(['int8'], ['data'], [], 'int8 data\n', 'ci_msgs/Base'))
msg_context.register('ci2_msgs/Base2', MsgSpec(['ci_msgs/Base'], ['data2'], [], 'ci_msgs/Base data2\n', 'ci2_msgs/Base2'))
msg_context.register('ci3_msgs/Base3', MsgSpec(['ci2_msgs/Base2'], ['data3'], [], 'ci2_msgs/Base2 data3\n', 'ci3_msgs/Base3'))
msg_context.register('ci4_msgs/Base', MsgSpec(['int8'], ['data'], [], 'int8 data\n', 'ci4_msgs/Base'))
msg_context.register('ci4_msgs/Base4', MsgSpec(['ci2_msgs/Base2', 'ci3_msgs/Base3'],
['data4a', 'data4b'],
[], 'ci2_msgs/Base2 data4a\nci3_msgs/Base3 data4b\n', 'ci4_msgs/Base4'))
msg_context.register('ci5_msgs/Base', MsgSpec(['time'], ['data'], [], 'time data\n', 'ci5_msgs/Base'))
assert ['import ci_msgs.msg'] == genpy.generator.compute_import(msg_context, 'foo', 'ci_msgs/Base')
assert ['import ci_msgs.msg'] == genpy.generator.compute_import(msg_context, 'ci_msgs', 'ci_msgs/Base')
assert ['import ci2_msgs.msg', 'import ci_msgs.msg'] == genpy.generator.compute_import(msg_context, 'ci2_msgs', 'ci2_msgs/Base2')
assert ['import ci2_msgs.msg', 'import ci_msgs.msg'] == genpy.generator.compute_import(msg_context, 'foo', 'ci2_msgs/Base2')
assert ['import ci3_msgs.msg', 'import ci2_msgs.msg', 'import ci_msgs.msg'] == genpy.generator.compute_import(msg_context, 'ci3_msgs', 'ci3_msgs/Base3')
assert set(['import ci4_msgs.msg', 'import ci3_msgs.msg', 'import ci2_msgs.msg', 'import ci_msgs.msg']) == set(genpy.generator.compute_import(msg_context, 'foo', 'ci4_msgs/Base4'))
assert set(['import ci4_msgs.msg', 'import ci3_msgs.msg', 'import ci2_msgs.msg', 'import ci_msgs.msg']) == set(genpy.generator.compute_import(msg_context, 'ci4_msgs', 'ci4_msgs/Base4'))
assert ['import ci4_msgs.msg'] == genpy.generator.compute_import(msg_context, 'foo', 'ci4_msgs/Base')
assert ['import ci4_msgs.msg'] == genpy.generator.compute_import(msg_context, 'ci4_msgs', 'ci4_msgs/Base')
assert ['import ci4_msgs.msg'] == genpy.generator.compute_import(msg_context, 'ci4_msgs', 'Base')
assert ['import ci5_msgs.msg', 'import genpy'] == genpy.generator.compute_import(msg_context, 'foo', 'ci5_msgs/Base')
示例7: test_load_msg_from_file
# 需要导入模块: from genmsg.msg_loader import MsgContext [as 别名]
# 或者: from genmsg.msg_loader.MsgContext import create_default [as 别名]
def test_load_msg_from_file():
from genmsg.msgs import InvalidMsgSpec
from genmsg.msg_loader import load_msg_from_file, MsgContext
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')
msg_context = MsgContext.create_default()
spec = load_msg_from_file(msg_context, test_string_path, 'test_ros/TestString')
assert spec.full_name == 'test_ros/TestString'
assert spec.package == 'test_ros'
assert spec.short_name == 'TestString'
_validate_TestString(spec)
# test repeat
spec_2 = load_msg_from_file(msg_context, test_string_path, 'test_ros/TestString')
assert spec == spec_2
assert spec.package == spec_2.package
assert spec.short_name == spec_2.short_name
# test w/ bad file
test_bad_path = os.path.join(test_ros_dir, 'Bad.msg')
try:
load_msg_from_file(msg_context, test_bad_path, 'test_ros/Bad')
assert False, "should have raised"
except InvalidMsgSpec:
pass
# supposed to register
assert msg_context.is_registered('test_ros/TestString'), msg_context
示例8: test_load_msg_from_string
# 需要导入模块: from genmsg.msg_loader import MsgContext [as 别名]
# 或者: from genmsg.msg_loader.MsgContext import create_default [as 别名]
def test_load_msg_from_string():
# make sure Header -> std_msgs/Header conversion works
from genmsg.msgs import Constant
from genmsg.msg_loader import load_msg_from_string, MsgContext
context = MsgContext.create_default()
msgspec = load_msg_from_string(context, "Header header", 'test_pkg/HeaderTest')
print(msgspec)
assert msgspec.has_header()
assert msgspec.types == ['std_msgs/Header']
assert msgspec.names == ['header']
assert msgspec.constants == []
assert msgspec.short_name == 'HeaderTest'
assert msgspec.package == 'test_pkg'
assert msgspec.full_name == 'test_pkg/HeaderTest'
msgspec = load_msg_from_string(context, "int8 c=1\nHeader header\nint64 data", 'test_pkg/HeaderValsTest')
assert msgspec.has_header()
assert msgspec.types == ['std_msgs/Header', 'int64']
assert msgspec.names == ['header', 'data']
assert msgspec.constants == [Constant('int8', 'c', 1, '1')]
assert msgspec.short_name == 'HeaderValsTest'
assert msgspec.package == 'test_pkg'
assert msgspec.full_name == 'test_pkg/HeaderValsTest'
msgspec = load_msg_from_string(context, "string data\nint64 data2", 'test_pkg/ValsTest')
assert not msgspec.has_header()
assert msgspec.types == ['string', 'int64']
assert msgspec.names == ['data', 'data2']
assert msgspec.constants == []
assert msgspec.short_name == 'ValsTest'
assert msgspec.full_name == 'test_pkg/ValsTest'
示例9: test_compute_constructor
# 需要导入模块: from genmsg.msg_loader import MsgContext [as 别名]
# 或者: from genmsg.msg_loader.MsgContext import create_default [as 别名]
def test_compute_constructor():
from genpy.generator import compute_constructor
msg_context = MsgContext.create_default()
msg_context.register('fake_msgs/String', MsgSpec(['string'], ['data'], [], 'string data\n', 'fake_msgs/String'))
msg_context.register('fake_msgs/ThreeNums', MsgSpec(['int32', 'int32', 'int32'], ['x', 'y', 'z'], [], 'int32 x\nint32 y\nint32 z\n', 'fake_msgs/ThreeNums'))
# builtin specials
assert 'genpy.Time()' == compute_constructor(msg_context, 'roslib', 'time')
assert 'genpy.Duration()' == compute_constructor(msg_context, 'roslib', 'duration')
assert 'std_msgs.msg._Header.Header()' == compute_constructor(msg_context, 'std_msgs', 'Header')
assert 'genpy.Time()' == compute_constructor(msg_context, 'std_msgs', 'time')
assert 'genpy.Duration()' == compute_constructor(msg_context, 'std_msgs', 'duration')
# generic instances
# - unregistered type
assert None == compute_constructor(msg_context, "unknown_msgs", "unknown_msgs/Foo")
assert None == compute_constructor(msg_context, "unknown_msgs", "Foo")
# - wrong context
assert None == compute_constructor(msg_context, 'std_msgs', 'ThreeNums')
# - registered types
assert 'fake_msgs.msg.String()' == compute_constructor(msg_context, 'std_msgs', 'fake_msgs/String')
assert 'fake_msgs.msg.String()' == compute_constructor(msg_context, 'fake_msgs', 'fake_msgs/String')
assert 'fake_msgs.msg.String()' == compute_constructor(msg_context, 'fake_msgs', 'String')
assert 'fake_msgs.msg.ThreeNums()' == compute_constructor(msg_context, 'fake_msgs', 'fake_msgs/ThreeNums')
assert 'fake_msgs.msg.ThreeNums()' == compute_constructor(msg_context, 'fake_msgs', 'fake_msgs/ThreeNums')
assert 'fake_msgs.msg.ThreeNums()' == compute_constructor(msg_context, 'fake_msgs', 'ThreeNums')
示例10: test_array_serializer_generator_numpy
# 需要导入模块: from genmsg.msg_loader import MsgContext [as 别名]
# 或者: from genmsg.msg_loader.MsgContext import create_default [as 别名]
def test_array_serializer_generator_numpy():
is_numpy = True
from genpy.generator import array_serializer_generator
d = os.path.join(get_test_dir(), 'array')
# generator tests are mainly tripwires/coverage tests
#array_serializer_generator(msg_context, package, type_, name, serialize, is_numpy):
msg_context = MsgContext.create_default()
# permutations: var length, unint8
serialize = True
result = array_serializer_generator(msg_context, '', 'uint8[]', 'data', serialize, is_numpy)
compare_file(d, 'uint8_varlen_ser_np.txt', result)
result = array_serializer_generator(msg_context, '', 'int16[]', 'data', serialize, is_numpy)
compare_file(d, 'int16_varlen_ser_np.txt', result)
result = array_serializer_generator(msg_context, '', 'uint8[8]', 'data', serialize, is_numpy)
compare_file(d, 'uint8_fixed_ser_np.txt', result)
result = array_serializer_generator(msg_context, '', 'int16[10]', 'data', serialize, is_numpy)
compare_file(d, 'int16_fixed_ser_np.txt', result)
serialize = False
result = array_serializer_generator(msg_context, '', 'uint8[]', 'data', serialize, is_numpy)
compare_file(d, 'uint8_varlen_deser_np.txt', result)
result = array_serializer_generator(msg_context, '', 'int16[]', 'data', serialize, is_numpy)
compare_file(d, 'int16_varlen_deser_np.txt', result)
result = array_serializer_generator(msg_context, '', 'uint8[8]', 'data', serialize, is_numpy)
compare_file(d, 'uint8_fixed_deser_np.txt', result)
result = array_serializer_generator(msg_context, '', 'int16[10]', 'data', serialize, is_numpy)
compare_file(d, 'int16_fixed_deser_np.txt', result)
示例11: test_flatten
# 需要导入模块: from genmsg.msg_loader import MsgContext [as 别名]
# 或者: from genmsg.msg_loader.MsgContext import create_default [as 别名]
def test_flatten():
import genpy.generator
from genpy.generator import flatten
msg_context = MsgContext.create_default()
simple = MsgSpec(['string'], ['data'], [], 'string data\n', 'simple/String')
simple2 = MsgSpec(['string', 'int32'], ['data', 'data2'], [], 'string data\nint32 data2\n', 'simpe/Data2')
assert simple == flatten(msg_context, simple)
assert simple2 == flatten(msg_context, simple2)
b1 = MsgSpec(['int8'], ['data'], [], 'X', 'f_msgs/Base')
b2 = MsgSpec(['f_msgs/Base'], ['data'], [], 'X', 'f_msgs/Base2')
b3 = MsgSpec(['f_msgs/Base2', 'f_msgs/Base2'], ['data3', 'data4'], [], 'X', 'f_msgs/Base3')
b4 = MsgSpec(['f_msgs/Base3', 'f_msgs/Base3'], ['dataA', 'dataB'], [], 'X', 'f_msgs/Base4')
msg_context.register('f_msgs/Base', b1)
msg_context.register('f_msgs/Base2', b2)
msg_context.register('f_msgs/Base3', b3)
msg_context.register('f_msgs/Base4', b4)
assert MsgSpec(['int8'], ['data.data'], [], 'X', 'f_msgs/Base2') == flatten(msg_context, b2)
assert MsgSpec(['int8', 'int8'], ['data3.data.data', 'data4.data.data'], [], 'X', 'f_msgs/Base3') == flatten(msg_context, b3)
assert MsgSpec(['int8', 'int8', 'int8', 'int8'],
['dataA.data3.data.data', 'dataA.data4.data.data', 'dataB.data3.data.data', 'dataB.data4.data.data'],
[], 'X', 'f_msgs/Base4') == flatten(msg_context, b4)
示例12: test_load_msg_from_string
# 需要导入模块: from genmsg.msg_loader import MsgContext [as 别名]
# 或者: from genmsg.msg_loader.MsgContext import create_default [as 别名]
def test_load_msg_from_string():
# make sure Header -> std_msgs/Header conversion works
from genmsg.msgs import Constant
from genmsg.msg_loader import load_msg_from_string, MsgContext
context = MsgContext.create_default()
msgspec = load_msg_from_string(context, "Header header", "test_pkg/HeaderTest")
print msgspec
assert msgspec.has_header()
assert msgspec.types == ["std_msgs/Header"]
assert msgspec.names == ["header"]
assert msgspec.constants == []
assert msgspec.short_name == "HeaderTest"
assert msgspec.package == "test_pkg"
assert msgspec.full_name == "test_pkg/HeaderTest"
msgspec = load_msg_from_string(context, "int8 c=1\nHeader header\nint64 data", "test_pkg/HeaderValsTest")
assert msgspec.has_header()
assert msgspec.types == ["std_msgs/Header", "int64"]
assert msgspec.names == ["header", "data"]
assert msgspec.constants == [Constant("int8", "c", 1, "1")]
assert msgspec.short_name == "HeaderValsTest"
assert msgspec.package == "test_pkg"
assert msgspec.full_name == "test_pkg/HeaderValsTest"
msgspec = load_msg_from_string(context, "string data\nint64 data2", "test_pkg/ValsTest")
assert not msgspec.has_header()
assert msgspec.types == ["string", "int64"]
assert msgspec.names == ["data", "data2"]
assert msgspec.constants == []
assert msgspec.short_name == "ValsTest"
assert msgspec.full_name == "test_pkg/ValsTest"
示例13: test_load_depends_srv
# 需要导入模块: from genmsg.msg_loader import MsgContext [as 别名]
# 或者: from genmsg.msg_loader.MsgContext import create_default [as 别名]
def test_load_depends_srv():
from genmsg.msg_loader import MsgContext, load_msg_by_type, load_depends, MsgNotFound, load_srv_by_type
test_d = get_test_dir()
geometry_d = os.path.join(test_d, 'geometry_msgs', 'msg')
msg_search_path = {
'test_ros': [ os.path.join(test_d, 'test_ros', 'msg') ],
'std_msgs': [ os.path.join(test_d, 'std_msgs', 'msg') ],
'geometry_msgs': [ geometry_d ],
'sensor_msgs': [ os.path.join(test_d, 'sensor_msgs', 'msg') ],
'invalid': [ os.path.join(test_d, 'invalid', 'msg') ],
}
# Test with srvs
srv_search_path = {
'test_ros': [ os.path.join(test_d, 'test_ros', 'srv') ],
'std_srvs': [ os.path.join(test_d, 'std_srvs', 'srv') ],
}
msg_context = MsgContext.create_default()
root_spec = load_srv_by_type(msg_context, 'test_ros/AddTwoInts', srv_search_path)
load_depends(msg_context, root_spec, msg_search_path)
val = msg_context.get_depends('test_ros/AddTwoIntsRequest')
assert val == [], val
val = msg_context.get_depends('test_ros/AddTwoIntsResponse')
assert val == [], val
# test with srv that has depends
msg_context = MsgContext.create_default()
response_deps = ['std_msgs/Header', 'geometry_msgs/Pose', 'geometry_msgs/PoseStamped', 'geometry_msgs/Point', 'geometry_msgs/Quaternion']
root_spec = load_srv_by_type(msg_context, 'test_ros/GetPoseStamped', srv_search_path)
load_depends(msg_context, root_spec, msg_search_path)
for d in response_deps:
assert msg_context.is_registered(d)
val = msg_context.get_depends('test_ros/GetPoseStampedRequest')
assert val == [], val
val = msg_context.get_depends('test_ros/GetPoseStampedResponse')
assert val == ['geometry_msgs/PoseStamped']
# Test with nonsense
class Foo(object): pass
try:
load_depends(msg_context, Foo(), msg_search_path)
assert False, "should have raised"
except ValueError:
pass
示例14: test_get_registered_ex
# 需要导入模块: from genmsg.msg_loader import MsgContext [as 别名]
# 或者: from genmsg.msg_loader.MsgContext import create_default [as 别名]
def test_get_registered_ex():
import genpy.generator
msg_context = MsgContext.create_default()
s = MsgSpec(['string'], ['data'], [], 'string data\n', 'tgr_msgs/String')
msg_context.register('tgr_msgs/String', s)
assert s == genpy.generator.get_registered_ex(msg_context, 'tgr_msgs/String')
try:
genpy.generator.get_registered_ex(msg_context, 'bad_msgs/String')
except genpy.generator.MsgGenerationException: pass
示例15: test_flatten_array_objects
# 需要导入模块: from genmsg.msg_loader import MsgContext [as 别名]
# 或者: from genmsg.msg_loader.MsgContext import create_default [as 别名]
def test_flatten_array_objects():
# make sure array of types don't flatten
from genpy.generator import flatten
msg_context = MsgContext.create_default()
b1 = MsgSpec(['int8'], ['data'], [], 'X', 'f_msgs/Base')
b5 = MsgSpec(['f_msgs/Base[]'], ['data'], [], 'X', 'f_msgs/Base5')
msg_context.register('f_msgs/Base', b1)
msg_context.register('f_msgs/Base5', b5)
assert b5 == flatten(msg_context, b5)