コード例 #1
0
ファイル: test_protomidi.py プロジェクト: ptone/protomidi
def test_serialize_and_parse():
    """
    Serialize a message and parse it. Should return the same message.
    """
    msg1 = protomidi.msg.note_on
    msg2 = protomidi.parse(protomidi.serialize(msg1))[0]
    assert msg2 == msg1
コード例 #2
0
ファイル: test_protomidi.py プロジェクト: ptone/protomidi
def test_parse_stray_data():
    """
    Stray data bytes (not inside a message) should be ignored.
    """
    ret = protomidi.parse(b'\x20\x30')

    assert ret == []
コード例 #3
0
ファイル: test_protomidi.py プロジェクト: ptone/protomidi
def test_parse_stray_data():
    """
    Stray data bytes (not inside a message) should be ignored.
    """
    ret = protomidi.parse(b'\x20\x30')

    assert ret == []
コード例 #4
0
ファイル: test_protomidi.py プロジェクト: ptone/protomidi
def test_parse():
    """
    Parse a note_on msg.
    """
    parsed = protomidi.parse(b'\x90\x4c\x20')[0]
    other = protomidi.msg.note_on(channel=0, note=76, velocity=32)
    assert parsed == other
コード例 #5
0
ファイル: test_protomidi.py プロジェクト: ptone/protomidi
def test_parse_random_bytes():
    data = bytearray(b"}kR\x87\xd6\xe0\xb2\x96\xe5\x18}\x1a{[\x0b\x0f\xa7\xc3\x13\r\xbd\xe4\x17\xca\xf3-\x05)\xf8\x1b\x16\x98/\x05\x1e.\xc2\x11;\x04K2cN\x9f-\'\xe2\xe7\xb5\xb6Y\x821\x99\x93\xa7m\xc0[b\xc34\xdbCd\x95\x8fdtOM5\xb5\xdb\xbb\xa6\x0e\xb2\x88\xfd\x15U=\x97\xdd\xd1F\x8b\xb0\x18\xee!}\xf4\x8f+\xde8\xb0")

    ret = protomidi.parse(data)

    # There should be 11 valid MIDI messages hiding in there.
    assert len(ret) == 11
コード例 #6
0
ファイル: test_protomidi.py プロジェクト: ptone/protomidi
def test_parse():
    """
    Parse a note_on msg.
    """
    parsed = protomidi.parse(b'\x90\x4c\x20')[0]
    other = protomidi.msg.note_on(channel=0, note=76, velocity=32)
    assert parsed == other
コード例 #7
0
ファイル: test_protomidi.py プロジェクト: ptone/protomidi
def test_serialize_and_parse():
    """
    Serialize a message and parse it. Should return the same message.
    """
    msg1 = protomidi.msg.note_on
    msg2 = protomidi.parse(protomidi.serialize(msg1))[0]
    assert msg2 == msg1
コード例 #8
0
ファイル: test_protomidi.py プロジェクト: ptone/protomidi
def test_parse_stray_opcodes():
    """
    Stray opcodes (opcode followed by too few data bytes)
    should be ignored.
    """
    ret = protomidi.parse(b'\x90\x90\xf0')

    assert ret == []
コード例 #9
0
ファイル: test_protomidi.py プロジェクト: ptone/protomidi
def test_parse_stray_opcodes():
    """
    Stray opcodes (opcode followed by too few data bytes)
    should be ignored.
    """
    ret = protomidi.parse(b'\x90\x90\xf0')

    assert ret == []
コード例 #10
0
ファイル: test_protomidi.py プロジェクト: ptone/protomidi
def test_pitchwheel_serialize_parse():
    """
    Check if pitchwheel with maximal value serializes correctly.
    """
    msg1 = protomidi.msg.pitchwheel(value=0)
    bytes = protomidi.serialize(msg1)
    msg2 = protomidi.parse(bytes)[0]

    assert msg1 == msg2
コード例 #11
0
ファイル: test_protomidi.py プロジェクト: ptone/protomidi
def test_pitchwheel_serialize_parse():
    """
    Check if pitchwheel with maximal value serializes correctly.
    """
    msg1 = protomidi.msg.pitchwheel(value=0)
    bytes = protomidi.serialize(msg1)
    msg2 = protomidi.parse(bytes)[0]

    assert msg1 == msg2
コード例 #12
0
ファイル: test_protomidi.py プロジェクト: ptone/protomidi
def test_parse_random_bytes():
    data = bytearray(
        b"}kR\x87\xd6\xe0\xb2\x96\xe5\x18}\x1a{[\x0b\x0f\xa7\xc3\x13\r\xbd\xe4\x17\xca\xf3-\x05)\xf8\x1b\x16\x98/\x05\x1e.\xc2\x11;\x04K2cN\x9f-\'\xe2\xe7\xb5\xb6Y\x821\x99\x93\xa7m\xc0[b\xc34\xdbCd\x95\x8fdtOM5\xb5\xdb\xbb\xa6\x0e\xb2\x88\xfd\x15U=\x97\xdd\xd1F\x8b\xb0\x18\xee!}\xf4\x8f+\xde8\xb0"
    )

    ret = protomidi.parse(data)

    # There should be 11 valid MIDI messages hiding in there.
    assert len(ret) == 11