aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--midi_launchpad_mini_unittest.py101
1 files changed, 34 insertions, 67 deletions
diff --git a/midi_launchpad_mini_unittest.py b/midi_launchpad_mini_unittest.py
index 4ae5480..4601c8d 100644
--- a/midi_launchpad_mini_unittest.py
+++ b/midi_launchpad_mini_unittest.py
@@ -1,6 +1,8 @@
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):
@@ -23,62 +25,21 @@ class MidiWrapperMock:
msg = Message("note_on", note=note, velocity=velocity, channel=channel)
self.callback(msg)
-class SoloToolMock:
- STOPPED = 0
- PLAYING = 1
- PAUSED = 2
-
- def __init__(self):
- self.state = SoloToolMock.STOPPED
- self.position = 0.0
- self.currentAbLimit = (0.0, 0.0)
- self.currentLoadedAbLimitIndex = None
- self.currentSong = None
-
- def play(self):
- self.state = SoloToolMock.PLAYING
-
- def pause(self):
- self.state = SoloToolMock.PAUSED
-
- def stop(self):
- self.state = SoloToolMock.STOPPED
-
- def isPlaying(self):
- return self.state == SoloToolMock.PLAYING
-
- def jumpToA(self):
- self.position = self.currentAbLimit[0]
-
- def loadAbLimits(self, index):
- self.currentLoadedAbLimitIndex = index
-
- def setSong(self, index):
- self.currentSong = index
-
- def nextSong(self):
- if self.currentSong is None:
- self.currentSong = 0
- else:
- self.currentSong += 1
-
- def previousSong(self):
- if self.currentSong is None:
- self.currentSong = 0
- else:
- self.currentSong = max(self.currentSong - 1, 0)
+@pytest.fixture
+def playerMock():
+ return PlayerMock()
@pytest.fixture
-def soloToolMock():
- return SoloToolMock()
+def soloTool(playerMock):
+ return SoloTool(playerMock)
@pytest.fixture
def midiWrapperMock():
return MidiWrapperMock()
@pytest.fixture
-def uut(soloToolMock, midiWrapperMock):
- return MidiController(soloToolMock, midiWrapperMock)
+def uut(soloTool, midiWrapperMock):
+ return MidiController(soloTool, midiWrapperMock)
def test_connect(uut, midiWrapperMock):
expectedDevice = "Launchpad Mini MIDI 1"
@@ -86,57 +47,63 @@ def test_connect(uut, midiWrapperMock):
assert midiWrapperMock.connectedDevice == expectedDevice
-def test_startStopAndPauseButtons(uut, midiWrapperMock, soloToolMock):
+def test_startStopAndPauseButtons(uut, midiWrapperMock, playerMock):
playPauseButton = 112
stopButton = 96
uut.connect()
- assert soloToolMock.state == SoloToolMock.STOPPED
+ assert playerMock.state == PlayerMock.STOPPED
midiWrapperMock.simulateInput(playPauseButton)
- assert soloToolMock.state == SoloToolMock.PLAYING
+ assert playerMock.state == PlayerMock.PLAYING
midiWrapperMock.simulateInput(stopButton)
- assert soloToolMock.state == SoloToolMock.STOPPED
+ assert playerMock.state == PlayerMock.STOPPED
midiWrapperMock.simulateInput(playPauseButton)
midiWrapperMock.simulateInput(playPauseButton)
- assert soloToolMock.state == SoloToolMock.PAUSED
+ assert playerMock.state == PlayerMock.PAUSED
midiWrapperMock.simulateInput(playPauseButton)
- assert soloToolMock.state == SoloToolMock.PLAYING
+ assert playerMock.state == PlayerMock.PLAYING
midiWrapperMock.simulateInput(playPauseButton)
midiWrapperMock.simulateInput(stopButton)
- assert soloToolMock.state == SoloToolMock.STOPPED
+ assert playerMock.state == PlayerMock.STOPPED
-def test_jumpToAButton(uut, midiWrapperMock, soloToolMock):
+def test_jumpToAButton(uut, midiWrapperMock, soloTool, playerMock):
ab = (0.5, 0.6)
uut.connect()
- soloToolMock.currentAbLimit = (ab[0], ab[1])
- assert soloToolMock.position == 0.0
+ soloTool.setAbLimits(ab[0], ab[1])
+ assert playerMock.position == 0.0
midiWrapperMock.simulateInput(101)
- assert soloToolMock.position == ab[0]
-
-def test_previousAndNextSongButtons(uut, midiWrapperMock, soloToolMock):
+ 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 soloToolMock.currentSong == None
+ assert playerMock.currentSong == None
midiWrapperMock.simulateInput(119)
- assert soloToolMock.currentSong == 0
+ assert playerMock.currentSong == songs[0]
midiWrapperMock.simulateInput(119)
- assert soloToolMock.currentSong == 1
+ assert playerMock.currentSong == songs[1]
midiWrapperMock.simulateInput(118)
- assert soloToolMock.currentSong == 0
+ assert playerMock.currentSong == songs[0]
midiWrapperMock.simulateInput(118)
- assert soloToolMock.currentSong == 0
+ assert playerMock.currentSong == songs[0]
-def test_unprogrammedButton(uut, midiWrapperMock, soloToolMock):
+def test_unprogrammedButton(uut, midiWrapperMock):
unusedButton = 48
uut.connect()