aboutsummaryrefslogtreecommitdiffstats
path: root/solo-tool-project/test/solo_tool_controller_integrationtest.py
blob: c161c700948324e72782629d4ef3d0cbe530ee21 (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
76
77
78
79
80
81
82
83
84
85
86
import pathlib
import shutil
import pytest

from solo_tool.solo_tool_controller import SoloToolController
from solo_tool.solo_tool import SoloTool

@pytest.fixture
def prepared_tmp_path(tmp_path):
    testFiles = [
        "test.flac",
        "test.mp3",
        "test_session.json"
    ]
    for f in testFiles:
        shutil.copy(pathlib.Path(f), tmp_path)
    return tmp_path

@pytest.fixture
def soloTool(prepared_tmp_path):
    st = SoloTool()
    st.loadSession(prepared_tmp_path / "test_session.json")
    return st

@pytest.fixture
def uut(soloTool):
    return SoloToolController(soloTool)

def test_previousSong(uut, soloTool):
    called = False
    receivedValue = None
    def callback(value):
        nonlocal called, receivedValue
        called = True
        receivedValue = value

    soloTool.registerCurrentSongCallback(callback)
    
    soloTool.getCurrentSong() == None
    assert not called

    uut.previousSong()
    soloTool.getCurrentSong() == 0
    assert called
    assert receivedValue == 0
    called = False

    uut.previousSong()
    soloTool.getCurrentSong() == 0
    assert not called

    soloTool.setSong(1)
    uut.previousSong()
    soloTool.getCurrentSong() == 0
    assert called
    assert receivedValue == 0
    called = False

def test_nextSong(uut, soloTool):
    called = False
    receivedValue = None
    def callback(value):
        nonlocal called, receivedValue
        called = True
        receivedValue = value

    soloTool.registerCurrentSongCallback(callback)
    
    soloTool.getCurrentSong() == None
    assert not called

    uut.nextSong()
    soloTool.getCurrentSong() == 0
    assert called
    assert receivedValue == 0
    called = False

    uut.nextSong()
    soloTool.getCurrentSong() == 1
    assert called
    assert receivedValue == 1
    called = False

    uut.nextSong()
    soloTool.getCurrentSong() == 1
    assert not called