aboutsummaryrefslogtreecommitdiffstats
path: root/abcontroller_unittest.py
diff options
context:
space:
mode:
authorEddy Pedroni <eddy@0xf7.com>2021-12-21 15:23:27 +0100
committerEddy Pedroni <eddy@0xf7.com>2021-12-21 15:23:27 +0100
commitc1bfcc6064b3a22c76b986d9339daf6cbd403c80 (patch)
tree1209bcf04f84c100cc6e8affc0cdd6c099f21bd4 /abcontroller_unittest.py
parent78e14031b50628566ef71666d37d538268678ba8 (diff)
Added more AB controller tests and features
Diffstat (limited to 'abcontroller_unittest.py')
-rw-r--r--abcontroller_unittest.py95
1 files changed, 82 insertions, 13 deletions
diff --git a/abcontroller_unittest.py b/abcontroller_unittest.py
index 0ee1554..839c88a 100644
--- a/abcontroller_unittest.py
+++ b/abcontroller_unittest.py
@@ -1,16 +1,17 @@
from abcontroller import ABController
from collections import namedtuple
+TCase = namedtuple("TCase", ["currentPosition", "requestedPosition"])
AB = namedtuple("AB", ["a", "b"])
+abLimits = AB(0.2, 0.4)
-def checkLimits(uut, aLimit, bLimit):
- Test = namedtuple("Test", ["currentPosition", "requestedPosition"])
+def checkLimits(uut, aLimit, bLimit, fail=False):
tests = [
- Test(aLimit - 0.1, None),
- Test(aLimit, None),
- Test(bLimit - 0.1, None),
- Test(bLimit, None),
- Test(bLimit + 0.1, aLimit)
+ TCase(aLimit - 0.1, None),
+ TCase(aLimit, None),
+ TCase(bLimit - 0.1, None),
+ TCase(bLimit, None),
+ TCase(bLimit + 0.1, aLimit if not fail else None)
]
requestedPosition = None
@@ -29,7 +30,6 @@ def checkLimits(uut, aLimit, bLimit):
def test_oneSetOfLimits():
song = "/path/to/song"
- abLimits = AB(0.2, 0.4)
uut = ABController()
uut.setCurrentSong(song)
@@ -56,11 +56,80 @@ def test_multipleSetsOfLimits():
checkLimits(uut, l.a, l.b)
def test_multipleSongs():
- # different limits in each song
- pass
+ songs = [
+ "/path/to/song",
+ "/path/to/another/song"
+ ]
+ abLimits = [
+ AB(0.2, 0.4),
+ AB(0.3, 0.5)
+ ]
+ uut = ABController()
+ for i, s in enumerate(songs):
+ uut.addLimits(abLimits[i].a, abLimits[i].b, s)
+
+ for i, s in enumerate(songs):
+ uut.setCurrentSong(s)
+ uut.setCurrentLimits(0)
+
+ checkLimits(uut, abLimits[i].a, abLimits[i].b)
def test_disableAbRepeat():
- pass
+ song = "/path/to/song"
+
+ uut = ABController()
+ uut.setCurrentSong(song)
+ uut.addLimits(abLimits.a, abLimits.b)
+ uut.setCurrentLimits(0)
+
+ uut.setEnable(False)
+ checkLimits(uut, abLimits.a, abLimits.b, fail=True)
+
+ uut.setEnable(True)
+ checkLimits(uut, abLimits.a, abLimits.b)
+
+def test_addLimitsToSpecificSong():
+ song = "/path/to/song"
+
+ uut = ABController()
+ uut.addLimits(abLimits.a, abLimits.b, song)
+ uut.setCurrentSong(song)
+ uut.setCurrentLimits(0)
+
+ checkLimits(uut, abLimits.a, abLimits.b)
+
+def test_addLimitsWithoutCurrentSong():
+ uut = ABController()
+ uut.addLimits(abLimits.a, abLimits.b)
+ uut.setCurrentLimits(0)
+
+ checkLimits(uut, abLimits.a, abLimits.b, fail=True)
+
+def test_addLimitsToSongWithoutCurrentSong():
+ song = "/path/to/song"
+ uut = ABController()
+ uut.addLimits(abLimits.a, abLimits.b, song)
+ uut.setCurrentLimits(0)
-def test_addLimitsToSong():
- pass
+ checkLimits(uut, abLimits.a, abLimits.b, fail=True)
+
+ uut.setCurrentSong(song)
+
+ checkLimits(uut, abLimits.a, abLimits.b, fail=True)
+
+ uut.setCurrentLimits(0)
+
+ checkLimits(uut, abLimits.a, abLimits.b)
+
+def test_addLimitsToCurrentSongButDoNotSetCurrentLimits():
+ song = "/path/to/song"
+ uut = ABController()
+ uut.setCurrentSong(song)
+ uut.addLimits(abLimits.a, abLimits.b)
+
+ checkLimits(uut, abLimits.a, abLimits.b, fail=True)
+
+ uut.setCurrentLimits(0)
+
+ checkLimits(uut, abLimits.a, abLimits.b)
+