aboutsummaryrefslogtreecommitdiffstats
path: root/solo_tool_cli_integrationtest.py
blob: 25ef13166edf561701f239098bd16ccfc145a466 (plain)
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
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, soloTool):
        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(soloTool)

@pytest.fixture
def uut(soloTool, mockMidi):
    return SoloToolCLI("test_session.json", soloToolOverride=soloTool, midiOverride=mockMidi, tickEnable=False)

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