From 8622638f99277b43d40b61029dc3c56164d06cae Mon Sep 17 00:00:00 2001 From: Eddy Pedroni Date: Sun, 26 Dec 2021 21:14:40 +0100 Subject: Changed default behaviour of AB controller --- abcontroller.py | 5 +++-- abcontroller_unittest.py | 29 +++++++++++++++++++++++++---- solo_tool_integrationtest.py | 22 +++++++++++++++------- 3 files changed, 43 insertions(+), 13 deletions(-) diff --git a/abcontroller.py b/abcontroller.py index 80f6a4d..b67d38a 100644 --- a/abcontroller.py +++ b/abcontroller.py @@ -7,7 +7,7 @@ class ABController: self._setPositionCallback = callback self._limits = dict() # dictionary of all songs self._songLimits = None # list of limits for selected song - self._currentLimits = None # a/b positions of selected limit + self._currentLimits = _AB(0.0, 0.0) # a/b positions of selected limit self._enabled = enabled def _ensureSongExists(self, path): @@ -17,7 +17,7 @@ class ABController: def setCurrentSong(self, path): self._ensureSongExists(path) self._songLimits = self._limits[path] - self._currentLimits = None + #self._currentLimits = None def storeLimits(self, aLimit, bLimit, song=None): if song is not None: @@ -42,6 +42,7 @@ class ABController: def positionChanged(self, position): if not self._currentLimits: return + print("No early return") if position > self._currentLimits.b and self._setPositionCallback and self._enabled: self._setPositionCallback(self._currentLimits.a) diff --git a/abcontroller_unittest.py b/abcontroller_unittest.py index 0e004ff..736ac6b 100644 --- a/abcontroller_unittest.py +++ b/abcontroller_unittest.py @@ -28,6 +28,27 @@ def checkLimits(uut, aLimit, bLimit, fail=False): uut._setPositionCallback = originalCallback +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 + def test_oneSetOfLimits(): song = "/path/to/song" @@ -107,7 +128,7 @@ def test_storeLimitsWithoutCurrentSong(): uut.storeLimits(abLimits.a, abLimits.b) uut.loadLimits(0) - checkLimits(uut, abLimits.a, abLimits.b, fail=True) + checkDefaultLimits(uut) def test_storeLimitsToSongWithoutCurrentSong(): song = "/path/to/song" @@ -115,11 +136,11 @@ def test_storeLimitsToSongWithoutCurrentSong(): uut.storeLimits(abLimits.a, abLimits.b, song) uut.loadLimits(0) - checkLimits(uut, abLimits.a, abLimits.b, fail=True) + checkDefaultLimits(uut) uut.setCurrentSong(song) - checkLimits(uut, abLimits.a, abLimits.b, fail=True) + checkDefaultLimits(uut) uut.loadLimits(0) @@ -131,7 +152,7 @@ def test_storeLimitsToCurrentSongButDoNotSetCurrentLimits(): uut.setCurrentSong(song) uut.storeLimits(abLimits.a, abLimits.b) - checkLimits(uut, abLimits.a, abLimits.b, fail=True) + checkDefaultLimits(uut) uut.loadLimits(0) diff --git a/solo_tool_integrationtest.py b/solo_tool_integrationtest.py index 2a2bd46..9321e89 100644 --- a/solo_tool_integrationtest.py +++ b/solo_tool_integrationtest.py @@ -165,6 +165,7 @@ def test_storeAbLimitsWithoutSong(): song = "test.flac" abLimit = [0.2, 0.4] overflow = abLimit[1] + 0.1 + default = 0.0 mockPlayer = MockPlayer() uut = SoloTool(mockPlayer) mockPlayer.position = overflow @@ -172,31 +173,38 @@ def test_storeAbLimitsWithoutSong(): uut.storeAbLimits(abLimit[0], abLimit[1]) uut.tick() - assert mockPlayer.position == overflow + assert mockPlayer.position == default + mockPlayer.position = overflow uut.setAbLimit(0) uut.tick() - assert mockPlayer.position == overflow + assert mockPlayer.position == default + mockPlayer.position = overflow uut.addSong(song) uut.tick() - assert mockPlayer.position == overflow + assert mockPlayer.position == default + mockPlayer.position = overflow uut.setAbLimit(0) uut.tick() - assert mockPlayer.position == overflow + assert mockPlayer.position == default + mockPlayer.position = overflow uut.setSong(0) uut.tick() - assert mockPlayer.position == overflow + assert mockPlayer.position == default + mockPlayer.position = overflow uut.setAbLimit(0) uut.tick() - assert mockPlayer.position == overflow + assert mockPlayer.position == default + mockPlayer.position = overflow uut.storeAbLimits(abLimit[0], abLimit[1]) uut.tick() - assert mockPlayer.position == overflow + assert mockPlayer.position == default + mockPlayer.position = overflow uut.setAbLimit(0) uut.tick() -- cgit v1.2.3