def test_flatten(): 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)
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)
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)