Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_dict_sysex_data():
msg = Message('sysex', data=(1, 2, 3))
data = msg.dict()
assert data == {'type': 'sysex', 'data': [1, 2, 3], 'time': 0}
assert isinstance(data['data'], list)
def test_copy_invalid_argument():
with raises(ValueError):
Message('note_on').copy(zzzzzzzzzzzz=2)
with raises(ValueError):
# note_on doesn't take program.
Message('note_on').copy(program=2)
def test_set_type():
"""Can't change the type of a message."""
with raises(AttributeError):
Message('note_on').type = 'note_off'
def test_encode_pitchwheel():
assert 'E0 00 00' == Message('pitchwheel', pitch=MIN_PITCHWHEEL).hex()
assert 'E0 00 40' == Message('pitchwheel', pitch=0).hex()
assert 'E0 7F 7F' == Message('pitchwheel', pitch=MAX_PITCHWHEEL).hex()
def test_from_dict_default_values():
msg = Message('note_on', channel=0, note=0, time=0)
data = {'type': 'note_on'}
assert Message.from_dict(data) == msg
def test_repr():
msg = Message('note_on', channel=1, note=2, time=3)
msg_eval = eval(repr(msg))
assert msg == msg_eval
def test_init_invalid_argument():
with raises(ValueError):
Message('note_on', zzzzzzzzzzzz=2)
with raises(ValueError):
# note_on doesn't take program.
Message('note_on', program=2)
def test_copy():
assert Message('start').copy(time=1) == Message('start', time=1)
def test_copy_can_have_same_type():
Message('start').copy(type='start')
def parse_string(text):
"""Parse a string of text and return a message.
The string can span multiple lines, but must contain
one full message.
Raises ValueError if the string could not be parsed.
"""
return Message.from_str(text)