aboutsummaryrefslogtreecommitdiffstats
path: root/abcontroller_unittest.py
blob: 0ee155477258c259aecf753fc2f630febe06fb7b (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
from abcontroller import ABController
from collections import namedtuple

AB = namedtuple("AB", ["a", "b"])

def checkLimits(uut, aLimit, bLimit):
    Test = namedtuple("Test", ["currentPosition", "requestedPosition"])
    tests = [
        Test(aLimit - 0.1, None),
        Test(aLimit, None),
        Test(bLimit - 0.1, None),
        Test(bLimit, None),
        Test(bLimit + 0.1, aLimit)
    ]

    requestedPosition = None
    def callback(newPosition):
        nonlocal requestedPosition
        requestedPosition = newPosition
    
    originalCallback = uut.setPositionCallback
    uut.setPositionCallback = callback

    for t in tests:
        uut.positionChanged(t.currentPosition)
        assert requestedPosition == t.requestedPosition

    uut.setPositionCallback = originalCallback

def test_oneSetOfLimits():
    song = "/path/to/song"
    abLimits = AB(0.2, 0.4)

    uut = ABController()
    uut.setCurrentSong(song)
    uut.addLimits(abLimits.a, abLimits.b)
    uut.setCurrentLimits(0)

    checkLimits(uut, abLimits.a, abLimits.b)

def test_multipleSetsOfLimits():
    song = "/path/to/song"
    abLimits = [
        AB(0.2, 0.4),
        AB(0.3, 0.5),
        AB(0.0, 1.2)
    ]

    uut = ABController()
    uut.setCurrentSong(song)
    for l in abLimits:
        uut.addLimits(l.a, l.b)
    
    for i, l in enumerate(abLimits):
        uut.setCurrentLimits(i)
        checkLimits(uut, l.a, l.b)

def test_multipleSongs():
    # different limits in each song
    pass

def test_disableAbRepeat():
    pass

def test_addLimitsToSong():
    pass