1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
|
#!/usr/bin/env python
"""Tests for the error conditions."""
import unittest
import rtmidi
from rtmidi import InvalidPortError, InvalidUseError
class TestErrors(unittest.TestCase):
INVALID_PORT_NUMBER = 9999
INVALID_NAME_TYPES = (0, 666, 3.141, object)
def setUp(self):
self.midi_out = rtmidi.MidiOut()
self.midi_in = rtmidi.MidiIn()
def test_midiout_invalid_client_name_type(self):
for name in self.INVALID_NAME_TYPES:
with self.assertRaises(TypeError):
rtmidi.MidiOut(rtapi=rtmidi.API_RTMIDI_DUMMY, name=name)
def test_midiin_invalid_client_name_type(self):
for name in self.INVALID_NAME_TYPES:
with self.assertRaises(TypeError):
rtmidi.MidiIn(rtapi=rtmidi.API_RTMIDI_DUMMY, name=name)
def test_midiout_open_invalid_port(self):
with self.assertRaises(InvalidPortError):
self.midi_out.open_port(self.INVALID_PORT_NUMBER)
def test_midiin_open_invalid_port(self):
with self.assertRaises(InvalidPortError):
self.midi_in.open_port(self.INVALID_PORT_NUMBER)
def test_midiout_open_invalid_port_name_type(self):
for name in self.INVALID_NAME_TYPES:
with self.assertRaises(TypeError):
self.midi_out.open_port(name=name)
def test_midiin_open_invalid_port_name_type(self):
for name in self.INVALID_NAME_TYPES:
with self.assertRaises(TypeError):
self.midi_in.open_port(name=name)
def test_midiout_double_open_port(self):
self.midi_out.open_port()
with self.assertRaises(InvalidUseError):
self.midi_out.open_port()
def test_midiin_double_open_port(self):
self.midi_in.open_port()
with self.assertRaises(InvalidUseError):
self.midi_in.open_port()
def test_midiout_double_open_virtual_port(self):
self.midi_out.open_virtual_port()
with self.assertRaises(InvalidUseError):
self.midi_out.open_virtual_port()
def test_midiin_double_open_virtual_port(self):
self.midi_in.open_virtual_port()
with self.assertRaises(InvalidUseError):
self.midi_in.open_virtual_port()
if __name__ == '__main__':
unittest.main()
|