def test_smallsysex_bytes_type(self):
        s = SystemExclusive([0x1F], [100, 150, 200])

        self.assertIsInstance(s, SystemExclusive)
        self.assertEqual(s.manufacturer_id, bytes([0x1F]))
        self.assertIsInstance(s.manufacturer_id, bytes)

        # check this really is immutable (pylint also picks this up!)
        with self.assertRaises(TypeError):
            s.data[0] = 0  # pylint: disable=unsupported-assignment-operation

        self.assertEqual(s.data, bytes([100, 150, 200]))
        self.assertIsInstance(s.data, bytes)
    def test_smallsysex_between_notes(self):
        m = MIDI_mocked_both_loopback(3, 3)

        m.send([
            NoteOn("C4", 0x7F),
            SystemExclusive([0x1F], [1, 2, 3, 4, 5, 6, 7, 8]),
            NoteOff(60, 0x28),
        ])

        msg1 = m.receive()
        self.assertIsInstance(msg1, NoteOn)
        self.assertEqual(msg1.note, 60)
        self.assertEqual(msg1.velocity, 0x7F)
        self.assertEqual(msg1.channel, 3)

        msg2 = m.receive()
        self.assertIsInstance(msg2, SystemExclusive)
        self.assertEqual(msg2.manufacturer_id, bytes([0x1F]))
        self.assertEqual(msg2.data, bytes([1, 2, 3, 4, 5, 6, 7, 8]))
        self.assertEqual(msg2.channel, None)  # SysEx does not have a channel

        msg3 = m.receive()
        self.assertIsInstance(msg3, NoteOff)
        self.assertEqual(msg3.note, 60)
        self.assertEqual(msg3.velocity, 0x28)
        self.assertEqual(msg3.channel, 3)

        msg4 = m.receive()
        self.assertIsNone(msg4)
    def test_larger_than_buffer_sysex(self):
        c = 0
        monster_data_len = 500
        raw_data = (bytes(NoteOn("C5", 0x7F, channel=c)) + bytes(
            SystemExclusive([0x02],
                            [d & 0x7F for d in range(monster_data_len)])) +
                    bytes(NoteOn("D5", 0x7F, channel=c)))
        m = MIDI_mocked_receive(c, raw_data, [len(raw_data)])
        buffer_len = m._in_buf_size  # pylint: disable=protected-access
        self.assertTrue(
            monster_data_len > buffer_len,
            "checking our SysEx truly is larger than buffer",
        )

        msg1 = m.receive()
        self.assertIsInstance(msg1, NoteOn)
        self.assertEqual(msg1.note, 72)
        self.assertEqual(msg1.velocity, 0x7F)
        self.assertEqual(msg1.channel, c)

        # (Ab)using python's rounding down for negative division
        # pylint: disable=unused-variable
        for unused in range(-(-(1 + 1 + monster_data_len + 1) // buffer_len) -
                            1):
            msg2 = m.receive()
            self.assertIsNone(msg2)

        # The current implementation will read SysEx end status byte
        # and report it as an unknown
        msg3 = m.receive()
        self.assertIsInstance(msg3,
                              adafruit_midi.midi_message.MIDIUnknownEvent)
        self.assertEqual(msg3.status, 0xF7)
        self.assertIsNone(msg3.channel)

        # (msg4, channel4) = m.receive()
        # self.assertIsInstance(msg4, PitchBend)
        # self.assertEqual(msg4.pitch_bend, 72)
        # self.assertEqual(channel4, c)

        msg5 = m.receive()
        self.assertIsInstance(msg5, NoteOn)
        self.assertEqual(msg5.note, 74)
        self.assertEqual(msg5.velocity, 0x7F)
        self.assertEqual(msg5.channel, c)

        msg6 = m.receive()
        self.assertIsNone(msg6)