Debian Codegraph @

tests/messages/test_decode.py

raw symbols SCIP
1 # SPDX-FileCopyrightText: 2017 Ole Martin Bjorndalen <[email protected]>
2 #
3 # SPDX-License-Identifier: MIT
4
5 from pytest import raises
6
7 from mido.messages.decode import decode_message
8
9
10 def sysex(data):
11 """Make sysex data."""
12 return [0xf0] + list(data) + [0xf7]
13
14
15 def test_sysex():
16 data = b'\xf0\x01\x02\x03\xf7'
17 msg = {'type': 'sysex', 'data': (1, 2, 3), 'time': 0}
18 assert decode_message(data) == msg
19
20
21 def test_channel():
22 assert decode_message(b'\x91\x00\x00')['channel'] == 1
23
24
25 def test_sysex_end():
26 with raises(ValueError):
27 decode_message(b'\xf0\x00\x12')
28
29
30 def test_zero_bytes():
31 with raises(ValueError):
32 decode_message(b'')
33
34
35 def test_too_few_bytes():
36 with raises(ValueError):
37 decode_message(b'\x90')
38
39
40 def test_too_many_bytes():
41 with raises(ValueError):
42 decode_message(b'\x90\x00\x00\x00')
43
44
45 def test_invalid_status():
46 with raises(ValueError):
47 decode_message(b'\x00')
48
49
50 def test_sysex_without_stop_byte():
51 with raises(ValueError):
52 decode_message([0xf0])
53
54 with raises(ValueError):
55 decode_message([0xf0, 0])