aboutsummaryrefslogtreecommitdiffstats
path: root/solo-tool-project/test/solo_tool_integrationtest.py
diff options
context:
space:
mode:
Diffstat (limited to 'solo-tool-project/test/solo_tool_integrationtest.py')
-rw-r--r--solo-tool-project/test/solo_tool_integrationtest.py469
1 files changed, 150 insertions, 319 deletions
diff --git a/solo-tool-project/test/solo_tool_integrationtest.py b/solo-tool-project/test/solo_tool_integrationtest.py
index 3a15e36..94d5cef 100644
--- a/solo-tool-project/test/solo_tool_integrationtest.py
+++ b/solo-tool-project/test/solo_tool_integrationtest.py
@@ -25,15 +25,6 @@ def prepared_tmp_path(tmp_path):
return tmp_path
-def checkLimit(uut, mockPlayer, aLimit, bLimit):
- mockPlayer.position = bLimit - 0.1
- uut.tick()
- assert mockPlayer.position == bLimit - 0.1
-
- mockPlayer.position = bLimit + 0.1
- uut.tick()
- assert mockPlayer.position == aLimit
-
def test_playerControls(uut, mockPlayer):
assert mockPlayer.state == MockPlayer.STOPPED
assert uut.isPlaying() == False
@@ -48,306 +39,189 @@ def test_playerControls(uut, mockPlayer):
assert uut.isPlaying() == False
assert mockPlayer.rate == 1.0
- uut.setPlaybackRate(0.5)
+ uut.rate = 0.5
assert mockPlayer.rate == 0.5
+ assert uut.rate == 0.5
assert mockPlayer.position == 0.0
- uut.setPlaybackPosition(0.5)
+ uut.position = 0.5
assert mockPlayer.position == 0.5
+ assert uut.position == 0.5
assert mockPlayer.volume == 1.0
- uut.setPlaybackVolume(0.5)
+ uut.volume = 0.5
assert mockPlayer.volume == 0.5
+ assert uut.volume == 0.5
-def test_addAndSetSongs(uut, mockPlayer):
- songs = [
- "test.flac",
- "test.mp3"
- ]
+def test_sanitizePlaybackRate(uut):
+ # Valid rates are > 0.0
+ with pytest.raises(ValueError):
+ uut.rate = -0.1
- for s in songs:
- uut.addSong(s)
- assert mockPlayer.currentSong == None
-
- for i, s in enumerate(songs):
- uut.song = i
- assert mockPlayer.currentSong == songs[i]
- assert uut.song == i
+ with pytest.raises(ValueError):
+ uut.rate = 0.0
-def test_addAndSetAbLimits(uut, mockPlayer):
- song = "test.flac"
- abLimits = [
- [0.2, 0.4],
- [0.1, 0.3]
- ]
+ uut.rate = 1.0
+ uut.rate = 150.0
- uut.addSong(song)
- uut.song = 0
+def test_sanitizePlaybackPosition(uut):
+ # Valid positions are in [0, 1)
+ with pytest.raises(ValueError):
+ uut.position = -0.1
- for ab in abLimits:
- uut.storeAbLimits(ab[0], ab[1])
+ uut.position = 0.0
+ uut.position = 0.999
- mockPlayer.position = 0.0
- uut.tick()
- assert mockPlayer.position == 0.0
+ with pytest.raises(ValueError):
+ uut.position = 1.0
- mockPlayer.position = 0.5
- uut.tick()
- assert mockPlayer.position == 0.5
+def test_sanitizePlaybackVolume(uut):
+ # Valid volumes are >= 0.0
+ with pytest.raises(ValueError):
+ uut.volume = -0.1
- uut.loadAbLimits(0)
+ uut.volume = 0.0
+ uut.volume = 1.0
+ uut.volume = 150.0
- uut.tick()
- assert mockPlayer.position == 0.5
+def test_addAndSelectSongs(uut, mockPlayer):
+ songs = [
+ "test.mp3",
+ "test.flac"
+ ]
- uut.setAbLimitEnable(True)
+ # Songs are added one by one
+ for song in songs:
+ uut.addSong(song)
- uut.tick()
- assert mockPlayer.position == 0.2
+ # Songs are not selected automatically
+ assert mockPlayer.currentSong == None
+ assert uut.song == None
- uut.tick()
- assert mockPlayer.position == 0.2
+ # Song order is preserved
+ assert uut.songs == songs
- uut.loadAbLimits(1)
- uut.tick()
- assert mockPlayer.position == 0.2
+ # Modifying the song list directly has no effect
+ uut.songs.append("something")
+ assert uut.songs == songs
- mockPlayer.position = 0.8
- uut.tick()
- assert mockPlayer.position == 0.1
+ # Songs are selected by index
+ for i, s in enumerate(uut.songs):
+ uut.song = i
+ assert mockPlayer.currentSong == uut.songs[i]
+ assert uut.song == i
-def test_abLimitEnabledGetter(uut):
- assert not uut.isAbLimitEnabled()
+ # The current song cannot be de-selected
+ with pytest.raises(ValueError):
+ uut.song = None
+ assert uut.song == len(uut.songs) - 1
- uut.setAbLimitEnable(True)
- assert uut.isAbLimitEnabled()
+ # Non-existent songs cannot be selected
+ with pytest.raises(ValueError):
+ uut.song = -1
+ assert uut.song == len(uut.songs) - 1
- uut.setAbLimitEnable(False)
- assert not uut.isAbLimitEnabled()
+ with pytest.raises(ValueError):
+ uut.song = 2
+ assert uut.song == len(uut.songs) - 1
-def test_multipleSongsAndAbLimits(uut, mockPlayer):
- songs = [
- "test.flac",
- "test.mp3"
- ]
- abLimits = [
- [0.2, 0.4],
- [0.5, 0.7]
- ]
-
- for s in songs:
- uut.addSong(s)
+def test_addAndJumpToKeyPoints(uut, mockPlayer):
+ uut.addSong("test.flac")
+ uut.addSong("test.mp3")
- for i, l in enumerate(abLimits):
- uut.song = i
- uut.storeAbLimits(l[0], l[1])
+ def checkJump(before, expectedAfter):
+ mockPlayer.position = before
+ uut.jump()
+ assert mockPlayer.position == expectedAfter
- uut.setAbLimitEnable(True)
-
- for i, l in enumerate(abLimits):
- uut.song = i
- uut.loadAbLimits(0)
+ # Key points are None as long as no song is selected
+ uut.keyPoints = [0.1, 0.2]
+ uut.keyPoint = 0.5
+ assert uut.keyPoints is None
+ assert uut.keyPoint is None
- mockPlayer.position = l[0]
- uut.tick()
- assert mockPlayer.position == l[0]
-
- mockPlayer.position = l[1] + 0.1
- uut.tick()
- assert mockPlayer.position == l[0]
-
-def test_storeAbLimitsWithoutSong(uut, mockPlayer):
- song = "test.flac"
- abLimit = [0.2, 0.4]
- overflow = abLimit[1] + 0.1
- default = 0.0
- mockPlayer.position = overflow
- uut.setAbLimitEnable(True)
-
- uut.storeAbLimits(abLimit[0], abLimit[1])
- uut.tick()
- assert mockPlayer.position == default
- mockPlayer.position = overflow
-
- uut.loadAbLimits(0)
- uut.tick()
- assert mockPlayer.position == default
- mockPlayer.position = overflow
+ uut.song = 0
- uut.addSong(song)
- uut.tick()
- assert mockPlayer.position == default
- mockPlayer.position = overflow
+ # Once a song is selected, jump to start by default
+ assert uut.keyPoint == 0.0
+ checkJump(0.5, 0.0)
- uut.loadAbLimits(0)
- uut.tick()
- assert mockPlayer.position == default
- mockPlayer.position = overflow
+ # By default songs have an empty list of key points
+ assert uut.keyPoints == []
- uut.song = 0
- uut.tick()
- assert mockPlayer.position == default
- mockPlayer.position = overflow
+ uut.keyPoints = [0.2, 0.4, 0.1, 0.2]
- uut.loadAbLimits(0)
- uut.tick()
- assert mockPlayer.position == default
- mockPlayer.position = overflow
+ # Added key points are not automatically selected
+ assert uut.keyPoint == 0.0
+ checkJump(0.1, 0.0)
- uut.storeAbLimits(abLimit[0], abLimit[1])
- uut.tick()
- assert mockPlayer.position == default
- mockPlayer.position = overflow
+ # Any key point can be selected
+ uut.keyPoint = uut.keyPoints[0]
+ checkJump(0.0, uut.keyPoints[0])
- uut.loadAbLimits(0)
- uut.tick()
- assert mockPlayer.position == abLimit[0]
+ uut.keyPoint = 0.5
+ checkJump(0.0, 0.5)
-def test_nextAndPreviousAbLimit(uut, mockPlayer):
+def test_sanitizeKeyPoint(uut):
song = "test.flac"
- abLimits = [
- [0.2, 0.4],
- [0.1, 0.3]
- ]
-
uut.addSong(song)
uut.song = 0
- uut.setAbLimitEnable(True)
+ uut.keyPoints = [0.2, 0.4, 0.1, 0.2, None, -0.5, 1.0, 1.5]
- for ab in abLimits:
- uut.storeAbLimits(ab[0], ab[1])
+ # Added key points are automatically de-duplicated, sanitized and sorted to ascending order
+ assert uut.keyPoints == [0.1, 0.2, 0.4]
- checkLimit(uut, mockPlayer, 0.0, 0.0) # default limits
+ # Key point and key point list cannot be none
+ uut.keyPoint = 0.5
- uut.nextStoredAbLimits()
- checkLimit(uut, mockPlayer, abLimits[0][0], abLimits[0][1])
+ with pytest.raises(ValueError):
+ uut.keyPoint = None
+ assert uut.keyPoint == 0.5
- uut.nextStoredAbLimits()
- checkLimit(uut, mockPlayer, abLimits[1][0], abLimits[1][1])
+ with pytest.raises(ValueError):
+ uut.keyPoints = None
+ assert uut.keyPoints == [0.1, 0.2, 0.4]
- uut.nextStoredAbLimits()
- checkLimit(uut, mockPlayer, abLimits[1][0], abLimits[1][1])
+ # Valid key points are in [0, 1)
+ with pytest.raises(ValueError):
+ uut.keyPoint = -0.1
- uut.previousStoredAbLimits()
- checkLimit(uut, mockPlayer, abLimits[0][0], abLimits[0][1])
+ with pytest.raises(ValueError):
+ uut.keyPoint = 1.0
- uut.previousStoredAbLimits()
- checkLimit(uut, mockPlayer, abLimits[0][0], abLimits[0][1])
+ uut.keyPoint = 0.999
-def test_abLimitsWhenChangingSongs(uut, mockPlayer):
+def test_keyPointsPerSong(uut, mockPlayer):
songs = [
- "test.flac",
- "test.mp3"
- ]
- abLimits = [
- [0.2, 0.4],
- [0.1, 0.3],
- [0.7, 0.8]
+ ("test.flac", [0.0, 0.5]),
+ ("test.mp3", [0.1])
]
- uut.setAbLimitEnable(True)
-
- for s in songs:
- uut.addSong(s)
-
- uut.song = 0
- for ab in abLimits:
- uut.storeAbLimits(ab[0], ab[1])
-
- uut.song = 1
- uut.storeAbLimits(abLimits[0][0], abLimits[0][1])
-
- uut.song = 0
- uut.loadAbLimits(len(abLimits) - 1)
- checkLimit(uut, mockPlayer, abLimits[-1][0], abLimits[-1][1])
-
- uut.song = 1
- checkLimit(uut, mockPlayer, abLimits[-1][0], abLimits[-1][1])
-
- uut.previousStoredAbLimits()
- checkLimit(uut, mockPlayer, abLimits[0][0], abLimits[0][1])
-def test_loadAndSaveSession(prepared_tmp_path):
- mockPlayer = MockPlayer()
- uut = SoloTool(mockPlayer)
-
- loadedSessionFile = prepared_tmp_path / "test_session.json"
- savedSessionFile = prepared_tmp_path / "test_session_save.json"
-
- uut.loadSession(loadedSessionFile)
- uut.saveSession(savedSessionFile)
+ # Key points list is set for the selected song
+ for i, (song, keyPoints) in enumerate(songs):
+ uut.addSong(song)
+ uut.song = i
+ uut.keyPoints = keyPoints
- import json
- with open(loadedSessionFile, "r") as f:
- loadedSession = json.loads(f.read())
-
- with open(savedSessionFile, "r") as f:
- savedSession = json.loads(f.read())
+ # Key points list is automatically loaded when the song selection changes
+ # Active key point is always reset to 0 when song selection changes
+ for i, (song, keyPoints) in enumerate(songs):
+ uut.keyPoint = 0.5
+ uut.song = i
+ assert uut.keyPoints == keyPoints
+ assert uut.keyPoint == 0.0
- assert loadedSession == savedSession
+ # Key points are copied, not stored by reference
+ for i, (song, keyPoints) in enumerate(songs):
+ uut.song = i
+ keyPoints.append(1.0)
+ assert 1.0 not in uut.keyPoints
-def test_addInexistentFile(uut, mockPlayer):
+def test_addInexistentSong(uut, mockPlayer):
song = "not/a/real/file"
- uut.addSong(song)
- uut.song = 0
-
- assert mockPlayer.currentSong == None
-
-def test_getters(uut, mockPlayer):
- song = "test.flac"
- abLimit = [0.2, 0.4]
-
- uut.addSong(song)
- uut.song = 0
- uut.storeAbLimits(abLimit[0], abLimit[1])
-
- assert uut.songList == [song]
-
- limits = uut.getStoredAbLimits()
- assert len(limits) == 1
- assert limits[0][0] == abLimit[0]
- assert limits[0][1] == abLimit[1]
-
- mockPlayer.position = 0.8
- assert uut.getPlaybackPosition() == 0.8
-
- mockPlayer.volume = 0.8
- assert uut.getPlaybackVolume() == 0.8
-
- mockPlayer.rate = 0.5
- assert uut.getPlaybackRate() == 0.5
-
-def test_setTemporaryLimits(uut, mockPlayer):
- song = "test.flac"
- abLimits = [
- [0.2, 0.4],
- [0.1, 0.4]
- ]
- overflow = 0.5
-
- uut.setAbLimitEnable(True)
- mockPlayer.position = overflow
- uut.addSong(song)
- uut.song = 0
- uut.storeAbLimits(abLimits[0][0], abLimits[0][1])
- uut.loadAbLimits(0)
-
- uut.setAbLimits(abLimits[1][0], abLimits[1][1])
- uut.tick()
- assert mockPlayer.position == abLimits[1][0]
-
-def test_jumpToA(uut, mockPlayer):
- abLimits = (0.2, 0.4)
- initialPosition = 0.8
-
- mockPlayer.position = initialPosition
-
- uut.jumpToA()
- assert mockPlayer.position == 0.0 # default AB controller A limit
-
- uut.setAbLimits(abLimits[0], abLimits[1])
- uut.jumpToA()
- assert mockPlayer.position == abLimits[0]
+ with pytest.raises(FileNotFoundError):
+ uut.addSong(song)
def test_playingStateNotification(uut, mockPlayer):
song = "test.flac"
@@ -404,16 +278,16 @@ def test_playbackVolumeNotification(uut, mockPlayer):
called = True
receivedValue = value
- uut.registerPlaybackVolumeCallback(callback)
+ uut.registerVolumeCallback(callback)
assert not called
- uut.setPlaybackVolume(0.3)
+ uut.volume = 0.3
assert called
assert receivedValue == 0.3
called = False
- uut.setPlaybackVolume(0.3)
+ uut.volume = 0.3
assert not called
def test_playbackRateNotification(uut, mockPlayer):
@@ -428,16 +302,16 @@ def test_playbackRateNotification(uut, mockPlayer):
called = True
receivedValue = value
- uut.registerPlaybackRateCallback(callback)
+ uut.registerRateCallback(callback)
assert not called
- uut.setPlaybackRate(0.5)
+ uut.rate = 0.5
assert called
assert receivedValue == 0.5
called = False
- uut.setPlaybackRate(0.5)
+ uut.rate = 0.5
assert not called
def test_currentSongNotification(uut):
@@ -455,9 +329,12 @@ def test_currentSongNotification(uut):
"test.flac",
"test.mp3"
]
+
+ # Adding a song does not trigger a notification
uut.addSong(songs[0])
assert not called
+ # Selecting a song for the first time triggers
uut.song = 0
assert called
assert receivedValue == 0
@@ -466,6 +343,7 @@ def test_currentSongNotification(uut):
uut.addSong(songs[1])
assert not called
+ # Selecting the same song does not trigger
uut.song = 0
assert not called
@@ -474,7 +352,7 @@ def test_currentSongNotification(uut):
assert receivedValue == 1
called = False
-def test_currentAbNotification(uut):
+def test_currentKeyPointNotification(uut):
called = False
receivedValue = None
def callback(value):
@@ -482,76 +360,29 @@ def test_currentAbNotification(uut):
called = True
receivedValue = value
- uut.registerCurrentAbLimitsCallback(callback)
+ uut.registerCurrentKeyPointCallback(callback)
assert not called
song = "test.flac"
uut.addSong(song)
uut.song = 0
- abLimits = [
- (0.2, 0.3),
- (0.4, 0.5)
- ]
- uut.storeAbLimits(abLimits[0][0], abLimits[0][1])
- assert not called
- uut.storeAbLimits(abLimits[1][0], abLimits[1][1])
- assert not called
-
- uut.loadAbLimits(0)
- assert called
- assert receivedValue == 0
- called = False
-
- uut.loadAbLimits(0)
- assert not called
-
- uut.loadAbLimits(1)
+ # Selecting a song for the first time sets the key point to 0.0
assert called
- assert receivedValue == 1
+ assert receivedValue == 0.0
called = False
- uut.previousStoredAbLimits()
+ # Changing the key point triggers a notification
+ uut.keyPoint = 0.5
assert called
- assert receivedValue == 0
- called = False
-
- uut.previousStoredAbLimits()
- assert not called
-
- uut.nextStoredAbLimits()
- assert called
- assert receivedValue == 1
- called = False
-
- uut.nextStoredAbLimits()
- assert not called
-
-def test_abLimitEnabledNotification(uut):
+ assert receivedValue == 0.5
called = False
- receivedValue = None
- def callback(value):
- nonlocal called, receivedValue
- called = True
- receivedValue = value
- uut.registerAbLimitEnabledCallback(callback)
+ # Adding list of key points does not trigger a notification
+ uut.keyPoints = [0.2, 0.4]
assert not called
- uut.setAbLimitEnable(False)
+ # Assigning the same key point again does not trigger a notification
+ uut.keyPoint = 0.5
assert not called
- assert receivedValue is None
- uut.setAbLimitEnable(True)
- assert called
- assert receivedValue == True
- called = False
- receivedValue = None
-
- uut.setAbLimitEnable(True)
- assert not called
- assert receivedValue is None
-
- uut.setAbLimitEnable(False)
- assert called
- assert receivedValue == False