aboutsummaryrefslogtreecommitdiffstats
path: root/midi_launchpad_mini_integrationtest.py
diff options
context:
space:
mode:
authorEddy Pedroni <eddy@0xf7.com>2022-01-01 16:35:43 +0100
committerEddy Pedroni <eddy@0xf7.com>2022-01-01 16:35:43 +0100
commitb04c158210b816af3ad423a3a823c5a25591ac78 (patch)
tree3472955e6f316c76b3eb4140334803c57d156c88 /midi_launchpad_mini_integrationtest.py
parent53cba69b1cdafbb169372c88b051876881c583ae (diff)
Renamed launchpad test file
Diffstat (limited to 'midi_launchpad_mini_integrationtest.py')
-rw-r--r--midi_launchpad_mini_integrationtest.py111
1 files changed, 111 insertions, 0 deletions
diff --git a/midi_launchpad_mini_integrationtest.py b/midi_launchpad_mini_integrationtest.py
new file mode 100644
index 0000000..4601c8d
--- /dev/null
+++ b/midi_launchpad_mini_integrationtest.py
@@ -0,0 +1,111 @@
+import pytest
+
+from midi_controller_launchpad_mini import MidiController
+from solo_tool import SoloTool
+from player_mock import Player as PlayerMock
+
+class MidiWrapperMock:
+ def __init__(self):
+ self.callback = None
+ self.connectedDevice = None
+ self.lastMessageSent = None
+
+ def setCallback(self, callback):
+ self.callback = callback
+
+ def connect(self, deviceName):
+ self.connectedDevice = deviceName
+
+ def sendMessage(self, note, velocity=127, channel=0):
+ pass
+
+ def simulateInput(self, note, velocity=127, channel=0):
+ if self.callback is not None:
+ from mido import Message
+ msg = Message("note_on", note=note, velocity=velocity, channel=channel)
+ self.callback(msg)
+
+@pytest.fixture
+def playerMock():
+ return PlayerMock()
+
+@pytest.fixture
+def soloTool(playerMock):
+ return SoloTool(playerMock)
+
+@pytest.fixture
+def midiWrapperMock():
+ return MidiWrapperMock()
+
+@pytest.fixture
+def uut(soloTool, midiWrapperMock):
+ return MidiController(soloTool, midiWrapperMock)
+
+def test_connect(uut, midiWrapperMock):
+ expectedDevice = "Launchpad Mini MIDI 1"
+ uut.connect()
+
+ assert midiWrapperMock.connectedDevice == expectedDevice
+
+def test_startStopAndPauseButtons(uut, midiWrapperMock, playerMock):
+ playPauseButton = 112
+ stopButton = 96
+ uut.connect()
+
+ assert playerMock.state == PlayerMock.STOPPED
+
+ midiWrapperMock.simulateInput(playPauseButton)
+ assert playerMock.state == PlayerMock.PLAYING
+
+ midiWrapperMock.simulateInput(stopButton)
+ assert playerMock.state == PlayerMock.STOPPED
+
+ midiWrapperMock.simulateInput(playPauseButton)
+ midiWrapperMock.simulateInput(playPauseButton)
+ assert playerMock.state == PlayerMock.PAUSED
+
+ midiWrapperMock.simulateInput(playPauseButton)
+ assert playerMock.state == PlayerMock.PLAYING
+
+ midiWrapperMock.simulateInput(playPauseButton)
+ midiWrapperMock.simulateInput(stopButton)
+ assert playerMock.state == PlayerMock.STOPPED
+
+def test_jumpToAButton(uut, midiWrapperMock, soloTool, playerMock):
+ ab = (0.5, 0.6)
+ uut.connect()
+
+ soloTool.setAbLimits(ab[0], ab[1])
+ assert playerMock.position == 0.0
+
+ midiWrapperMock.simulateInput(101)
+ assert playerMock.position == ab[0]
+
+def test_previousAndNextSongButtons(uut, midiWrapperMock, soloTool, playerMock):
+ songs = [
+ "test.flac",
+ "test.mp3"
+ ]
+ for s in songs:
+ soloTool.addSong(s)
+ uut.connect()
+
+ assert playerMock.currentSong == None
+ midiWrapperMock.simulateInput(119)
+ assert playerMock.currentSong == songs[0]
+
+ midiWrapperMock.simulateInput(119)
+ assert playerMock.currentSong == songs[1]
+
+ midiWrapperMock.simulateInput(118)
+ assert playerMock.currentSong == songs[0]
+
+ midiWrapperMock.simulateInput(118)
+ assert playerMock.currentSong == songs[0]
+
+def test_unprogrammedButton(uut, midiWrapperMock):
+ unusedButton = 48
+ uut.connect()
+
+ # expect no crash
+ midiWrapperMock.simulateInput(48)