当前位置: 首页>>代码示例>>Python>>正文


Python msg_loader.MsgContext类代码示例

本文整理汇总了Python中genmsg.msg_loader.MsgContext的典型用法代码示例。如果您正苦于以下问题:Python MsgContext类的具体用法?Python MsgContext怎么用?Python MsgContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了MsgContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_load_msg_depends_stamped

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)
开发者ID:kwc,项目名称:genmsg,代码行数:60,代码来源:test_genmsg_msg_loader.py

示例2: test_load_msg_depends

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)
开发者ID:kwc,项目名称:genmsg,代码行数:60,代码来源:test_genmsg_msg_loader.py

示例3: test_load_depends_msg

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)
开发者ID:2013-8-15,项目名称:ardupilot,代码行数:58,代码来源:test_genmsg_msg_loader.py

示例4: test_load_depends_msg

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)
开发者ID:kwc,项目名称:genmsg,代码行数:58,代码来源:test_genmsg_msg_loader.py

示例5: test_load_depends_srv

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
开发者ID:eitanme,项目名称:genmsg,代码行数:54,代码来源:test_genmsg_msg_loader.py

示例6: test_compute_import

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')
开发者ID:Nishida-Lab,项目名称:RCR,代码行数:31,代码来源:test_genpy_generator.py

示例7: test_load_msg_from_file

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
开发者ID:2013-8-15,项目名称:ardupilot,代码行数:30,代码来源:test_genmsg_msg_loader.py

示例8: test_load_msg_from_string

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'
开发者ID:2013-8-15,项目名称:ardupilot,代码行数:32,代码来源:test_genmsg_msg_loader.py

示例9: test_compute_constructor

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')
开发者ID:Nishida-Lab,项目名称:RCR,代码行数:28,代码来源:test_genpy_generator.py

示例10: test_array_serializer_generator_numpy

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)
开发者ID:Nishida-Lab,项目名称:RCR,代码行数:29,代码来源:test_genpy_generator.py

示例11: test_flatten

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)
开发者ID:Nishida-Lab,项目名称:RCR,代码行数:25,代码来源:test_genpy_generator.py

示例12: test_load_msg_from_string

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"
开发者ID:eitanme,项目名称:genmsg,代码行数:33,代码来源:test_genmsg_msg_loader.py

示例13: test_load_depends_srv

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
开发者ID:2013-8-15,项目名称:ardupilot,代码行数:45,代码来源:test_genmsg_msg_loader.py

示例14: test_get_registered_ex

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
开发者ID:Nishida-Lab,项目名称:RCR,代码行数:9,代码来源:test_genpy_generator.py

示例15: test_flatten_array_objects

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)
开发者ID:Nishida-Lab,项目名称:RCR,代码行数:11,代码来源:test_genpy_generator.py


注:本文中的genmsg.msg_loader.MsgContext类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。