aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEddy Pedroni <eddy@0xf7.com>2022-01-07 18:17:07 +0100
committerEddy Pedroni <eddy@0xf7.com>2022-01-07 18:26:22 +0100
commit192100c0590dfbe2db498b356fbd1e1e19eace2c (patch)
tree22bd749baaa307e178160cf4cc8cb6976df44aff
parent97f3c945fe2e1369c2e21cef4a474fac3ce4d8db (diff)
Added very based CLI
-rw-r--r--solo_tool_cli.py34
-rw-r--r--solo_tool_cli_integrationtest.py75
2 files changed, 109 insertions, 0 deletions
diff --git a/solo_tool_cli.py b/solo_tool_cli.py
new file mode 100644
index 0000000..b6e7817
--- /dev/null
+++ b/solo_tool_cli.py
@@ -0,0 +1,34 @@
+from solo_tool import SoloTool
+from midi_controller_launchpad_mini import MidiController
+
+class SoloToolCLI:
+ def __init__(self, sessionJson, soloToolOverride=None, midiOverride=None):
+ self._soloTool = SoloTool() if soloToolOverride is None else soloToolOverride
+ self._soloTool.loadSession(sessionJson)
+ self._midiController = MidiController() if midiOverride is None else midiOverride
+ self._commands = {
+ "song" : self._song,
+ "midi" : self._midi
+ }
+
+ def input(self, commandString):
+ split = commandString.strip().split(" ")
+ if split[0] in self._commands:
+ self._commands[split[0]](split[1:])
+
+ def _song(self, args):
+ if len(args) > 0:
+ self._soloTool.setSong(int(args[0]))
+ else:
+ songs = self._soloTool.getSongs()
+ print("Songs:")
+ for i, s in enumerate(songs):
+ print(f" {i} {s}")
+
+ def _midi(self, args):
+ if len(args) > 0 and args[0] == "connect":
+ print("Connecting to MIDI device...")
+ self._midiController.connect()
+ else:
+ print("Supported device: Novation Launchpad Mini MkII")
+
diff --git a/solo_tool_cli_integrationtest.py b/solo_tool_cli_integrationtest.py
new file mode 100644
index 0000000..ae007a3
--- /dev/null
+++ b/solo_tool_cli_integrationtest.py
@@ -0,0 +1,75 @@
+import pytest
+import io
+from contextlib import redirect_stdout
+
+from solo_tool_cli import SoloToolCLI
+from solo_tool import SoloTool
+from player_mock import Player
+
+class MockMidiController:
+ def __init__(self):
+ self.connected = False
+
+ def connect(self):
+ self.connected = True
+
+@pytest.fixture
+def mockPlayer():
+ return Player()
+
+@pytest.fixture
+def soloTool(mockPlayer):
+ return SoloTool(playerOverride=mockPlayer)
+
+@pytest.fixture
+def mockMidi(soloTool):
+ return MockMidiController()
+
+@pytest.fixture
+def uut(soloTool, mockMidi):
+ return SoloToolCLI("test_session.json", soloToolOverride=soloTool, midiOverride=mockMidi)
+
+def test_songSelection(uut, soloTool, mockPlayer):
+ expectedOutput = """\
+Songs:
+ 0 test.flac
+ 1 test.mp3
+Songs:
+ 0 test.flac
+ 1 test.mp3
+Songs:
+ 0 test.flac
+ 1 test.mp3
+"""
+
+ with io.StringIO() as buf, redirect_stdout(buf):
+ uut.input("song")
+ assert mockPlayer.currentSong == None
+
+ uut.input("song 0")
+ assert mockPlayer.currentSong == "test.flac"
+
+ uut.input("song ")
+
+ uut.input("song 1")
+ assert mockPlayer.currentSong == "test.mp3"
+
+ uut.input("song")
+
+
+ assert buf.getvalue() == expectedOutput
+
+def test_connectMidi(uut, mockMidi):
+ expectedOutput = """\
+Supported device: Novation Launchpad Mini MkII
+Connecting to MIDI device...
+"""
+
+ with io.StringIO() as buf, redirect_stdout(buf):
+ uut.input("midi")
+ assert not mockMidi.connected
+
+ uut.input("midi connect")
+ assert mockMidi.connected
+
+ assert buf.getvalue() == expectedOutput