| 37 | |
| 38 | |
| 39 | def test_static_array(): |
| 40 | ns = MessageNamespace() |
| 41 | ns.load_csv(['msgtype,test1,1', |
| 42 | 'msgdata,test1,test_arr,byte,4']) |
| 43 | ns.load_csv(['msgtype,test2,2', |
| 44 | 'msgdata,test2,test_arr,short_channel_id,4']) |
| 45 | |
| 46 | for test in [["test1 test_arr=00010203", bytes([0, 1] + [0, 1, 2, 3])], |
| 47 | ["test2 test_arr=[0x1x2,4x5x6,7x8x9,10x11x12]", |
| 48 | bytes([0, 2] |
| 49 | + [0, 0, 0, 0, 0, 1, 0, 2] |
| 50 | + [0, 0, 4, 0, 0, 5, 0, 6] |
| 51 | + [0, 0, 7, 0, 0, 8, 0, 9] |
| 52 | + [0, 0, 10, 0, 0, 11, 0, 12])]]: |
| 53 | m = Message.from_str(ns, test[0]) |
| 54 | assert m.to_str() == test[0] |
| 55 | buf = io.BytesIO() |
| 56 | m.write(buf) |
| 57 | assert buf.getvalue() == test[1] |
| 58 | assert Message.read(ns, io.BytesIO(test[1])).to_str() == test[0] |
| 59 | |
| 60 | |
| 61 | def test_subtype(): |