| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
from mido.messages.decode import decode_message |
| 6 |
from mido.messages.encode import encode_message |
| 7 |
from mido.messages.specs import SPEC_BY_STATUS |
| 8 |
|
| 9 |
|
| 10 |
def test_encode_decode_all(): |
| 11 |
"""Encode and then decode all messages on all channels. |
| 12 |
|
| 13 |
Each data byte is different so that the test will fail if the |
| 14 |
bytes are swapped during encoding or decoding. |
| 15 |
""" |
| 16 |
|
| 17 |
data_bytes = [1, 2, 3] |
| 18 |
|
| 19 |
for status_byte, spec in SPEC_BY_STATUS.items(): |
| 20 |
if status_byte == 0xf0: |
| 21 |
msg_bytes = [0xf0] + data_bytes + [0xf7] |
| 22 |
else: |
| 23 |
msg_bytes = [status_byte] + data_bytes[:spec['length'] - 1] |
| 24 |
|
| 25 |
assert encode_message(decode_message(msg_bytes)) == msg_bytes |