From 182a14f4b9aec4722f7f94ab44bf57356c6d71aa Mon Sep 17 00:00:00 2001 From: Eddy Pedroni Date: Tue, 21 Dec 2021 08:16:55 +0100 Subject: Added AB controller with some tests, minor refactor to playlist --- abcontroller_unittest.py | 66 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 abcontroller_unittest.py (limited to 'abcontroller_unittest.py') 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 -- cgit v1.2.3