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