def test_netstring_extract(): raw_bytes = b'74:' + valid_msg1 + b',104:' + valid_msg2 + b',77:' + part_1 msg, raw_bytes = JSONFramingNetstring.extract_message(raw_bytes) assert msg == valid_msg1 msg, raw_bytes = JSONFramingNetstring.extract_message(raw_bytes) assert msg == valid_msg2 msg, raw_bytes = JSONFramingNetstring.extract_message(raw_bytes) assert msg is None assert raw_bytes == b'77:' + part_1
def test_netstring_extract_broken(): raw_bytes = b'104:' + valid_msg2 + b',23:' + valid_msg1 msg, raw_bytes = JSONFramingNetstring.extract_message(raw_bytes) assert msg == valid_msg2 with pytest.raises(FramingError): JSONFramingNetstring.extract_message(raw_bytes)