Files
status-indicators/tests/test_midi_witness.py
T

41 lines
1.4 KiB
Python
Raw Normal View History

"""midi_witness.py (2026-10-26, NA): the key changes Studio B really receives, through real CoreMIDI."""
import json
import os
import sys
import tempfile
import time
import unittest
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import coremidi # noqa: E402
import midi_witness as mw # noqa: E402
class TestWitness(unittest.TestCase):
def test_parses_a_packet(self):
self.assertEqual(mw.messages(bytes([0xC0, 7, 0xF8, 0x90, 60, 100, 0xF0, 1, 2, 0xF7, 0xC1, 4])),
[(0xC0, b"\x07"), (0x90, b"<d"), (0xC1, b"\x04")])
def test_writes_down_program_changes_it_really_receives(self):
src = coremidi.VirtualSource("witness-test")
out = os.path.join(tempfile.mkdtemp(), "w.json")
try:
w = mw.Witness(["witness-test"], out=out)
w.poll()
time.sleep(0.3)
src.send(bytes([0xC0, 7])) # Ebmaj
src.send(bytes([0x90, 60, 100]))
src.send(bytes([0xC2, 11]))
time.sleep(0.5)
w.save()
d = json.load(open(out))
self.assertTrue(d["sources"]["witness-test"]["connected"])
self.assertEqual([p[2:] for p in d["pcs"]], [[1, 7], [3, 11]])
self.assertEqual(d["sources"]["witness-test"]["count"], 3)
finally:
src.close()
if __name__ == "__main__":
unittest.main()