diff options
author | Eddy Pedroni <eddy@0xf7.com> | 2021-12-21 08:16:55 +0100 |
---|---|---|
committer | Eddy Pedroni <eddy@0xf7.com> | 2021-12-21 08:16:55 +0100 |
commit | 182a14f4b9aec4722f7f94ab44bf57356c6d71aa (patch) | |
tree | c2c3a683184a53ddc141fe33e02fc934b793d196 /abcontroller_unittest.py | |
parent | 1ca1fbcc001e27f46fc033f44ad5459bd0351bc9 (diff) |
Added AB controller with some tests, minor refactor to playlist
Diffstat (limited to 'abcontroller_unittest.py')
-rw-r--r-- | abcontroller_unittest.py | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/abcontroller_unittest.py b/abcontroller_unittest.py new file mode 100644 index 0000000..0ee1554 --- /dev/null +++ b/abcontroller_unittest.py @@ -0,0 +1,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 |