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 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
|
#!/usr/bin/env python
"""Unit tests for the rtmidi module."""
import gc
import unittest
import rtmidi
class TestDelete(unittest.TestCase):
def setUp(self):
self.midiout = rtmidi.MidiOut()
self.midiin = rtmidi.MidiIn()
def test_midiin_delete(self):
midiin_ports = self.midiin.get_ports()
print("Input ports:")
print(midiin_ports)
ports_init = self.midiout.get_ports()
print("output ports initially:")
print(ports_init)
if midiin_ports:
self.midiin.open_port(0)
else:
self.midiin.open_virtual_port("My virtual output")
ports_before = self.midiout.get_ports()
self.assertEqual(len(ports_before), len(ports_init) + 1)
print("Output ports BEFORE deleting MidiIn instance:")
print(ports_before)
self.midiin.delete()
ports_after = self.midiout.get_ports()
print("Output ports AFTER deleting MidiIn instance:")
print(ports_after)
self.assertEqual(set(ports_init), set(ports_after))
def test_midiout_delete(self):
midiout_ports = self.midiout.get_ports()
print("Output ports:")
print(midiout_ports)
ports_init = self.midiin.get_ports()
print("Input ports initially:")
print(ports_init)
if midiout_ports:
self.midiout.open_port(0)
else:
self.midiout.open_virtual_port("My virtual output")
ports_before = self.midiin.get_ports()
self.assertEqual(len(ports_before), len(ports_init) + 1)
print("Input ports BEFORE deleting MidiOut instance:")
print(ports_before)
self.midiout.delete()
ports_after = self.midiin.get_ports()
print("Input ports AFTER deleting MidiOut instance:")
print(ports_after)
self.assertEqual(set(ports_init), set(ports_after))
def test_double_delete(self):
self.assertFalse(self.midiout.is_deleted)
self.midiout.delete()
self.assertTrue(self.midiout.is_deleted)
self.midiout.delete()
self.assertTrue(self.midiout.is_deleted)
def test_del_after_delete(self):
self.midiout.delete()
self.assertTrue(self.midiout.is_deleted)
self.assertTrue(hasattr(self, 'midiout'))
del self.midiout
gc.collect()
self.assertFalse(hasattr(self, 'midiout'))
if __name__ == '__main__':
unittest.main()
|