def test_empty_rgroups(self, spec): if 'FIX.4.4' not in spec.version and 'FIX5.' not in spec.version: # only relevant for fix 4.4 or above return codec = Codec(spec=spec, decode_as='UTF-8') msg = b'35=AJ;17807=11;232=2;233=bli;234=blu;' \ b'233=blih;234=bluh;555=0;10=000;' msg = codec.parse(msg, separator=';') assert {35: 'AJ', 17807: '11', 232: [ {233: 'bli', 234: 'blu'}, {233: 'blih', 234: 'bluh'} ], 555: [], 10: '000' } == msg lhs = tuple(codec._unmap(msg)) assert lhs == ((35, 'AJ'), (232, 2), (233, 'bli'), (234, 'blu'), (233, 'blih'), (234, 'bluh'), (555, 0), (17807, '11'), (10, '000') ) serialised = '35=AJ;232=2;233=bli;234=blu;233=blih;234=bluh;' \ '555=0;17807=11;10=000;'.replace(';', chr(1)).encode('UTF-8') assert serialised == codec.serialise(msg)
def test_nested_rgroup(self, spec): codec = Codec(spec=spec, decode_as='UTF-8') msg = b'35=AE;555=1;687=AA;683=2;688=1;689=1;' \ b'688=2;689=2;17807=11;10=000;' msg = codec.parse(msg, separator=';') assert { 35: 'AE', 555: [ dict(((687, 'AA'), (683, [ dict(((688, '1'), (689, '1'))), dict(((688, '2'), (689, '2'))) ]))) ], 17807: '11', 10: '000' } == msg lhs = tuple(codec._unmap(msg)) assert lhs == ((35, 'AE'), (555, 1), (683, 2), (688, '1'), (689, '1'), (688, '2'), (689, '2'), (687, 'AA'), (17807, '11'), (10, '000')) serialised = '35=AE;555=1;683=2;688=1;689=1;' \ '688=2;689=2;687=AA;17807=11;10=000;'.replace(';', chr(1)).encode('UTF-8') assert serialised == codec.serialise(msg)
def test_consecutive_rgroups(self, spec): codec = Codec(spec=spec, decode_as='UTF-8') msg = b'35=B;215=1;216=1;' \ b'146=2;55=EURUSD;55=EURGBP;10=000;' msg = codec.parse(msg, separator=';') assert {35: 'B', 215: [{216 : '1'}], 146: [{55 : 'EURUSD'}, {55 : 'EURGBP'}], 10: '000' } == msg lhs = tuple(codec._unmap(msg)) assert lhs == ((35, 'B'), (215, 1), (216, '1'), (146, 2), (55, 'EURUSD'), (55, 'EURGBP'), (10, '000') ) serialised = '35=B;215=1;216=1;' \ '146=2;55=EURUSD;55=EURGBP;10=000;'.replace(';', chr(1)).encode('UTF-8') assert serialised == codec.serialise(msg)