aboutsummaryrefslogtreecommitdiffstats
path: root/abcontroller_unittest.py
diff options
context:
space:
mode:
authorEddy Pedroni <eddy@0xf7.com>2021-12-27 09:15:17 +0100
committerEddy Pedroni <eddy@0xf7.com>2021-12-27 09:19:33 +0100
commitf52e40f899567d5d67a4cb2dcd75872ee038aaf8 (patch)
treeb2fe7847b9932837f9753771a7fe268dce2471c5 /abcontroller_unittest.py
parentc90623ebcd16070aafc5f8ad4cf76b5aa2b1e49f (diff)
Minor refactoring to AB controller unit tests
Diffstat (limited to 'abcontroller_unittest.py')
-rw-r--r--abcontroller_unittest.py36
1 files changed, 12 insertions, 24 deletions
diff --git a/abcontroller_unittest.py b/abcontroller_unittest.py
index 6e6e779..fbe7ae1 100644
--- a/abcontroller_unittest.py
+++ b/abcontroller_unittest.py
@@ -5,15 +5,7 @@ TCase = namedtuple("TCase", ["currentPosition", "requestedPosition"])
AB = namedtuple("AB", ["a", "b"])
abLimits = AB(0.2, 0.4)
-def checkLimits(uut, aLimit, bLimit, fail=False):
- tests = [
- 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)
- ]
-
+def _checkLimits(uut, tests):
requestedPosition = None
def callback(newPosition):
nonlocal requestedPosition
@@ -28,26 +20,23 @@ def checkLimits(uut, aLimit, bLimit, fail=False):
uut._setPositionCallback = originalCallback
+def checkLimits(uut, aLimit, bLimit, fail=False):
+ tests = [
+ 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)
+ ]
+ _checkLimits(uut, tests)
+
def checkDefaultLimits(uut):
tests = [
TCase(0.0, None),
TCase(0.1, 0.0),
TCase(0.5, 0.0)
]
-
- 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
+ _checkLimits(uut, tests)
def test_oneSetOfLimits():
song = "/path/to/song"
@@ -210,7 +199,6 @@ def test_setTemporaryLimitsWithCurrentSong():
uut.setLimits(l.a, l.b)
checkLimits(uut, l.a, l.b)
-
def test_defaultBehaviour():
uut = ABController()
checkDefaultLimits(uut)