aboutsummaryrefslogtreecommitdiffstats
path: root/playlist_unittest.py
diff options
context:
space:
mode:
authorEddy Pedroni <eddy@0xf7.com>2021-12-21 19:32:11 +0100
committerEddy Pedroni <eddy@0xf7.com>2021-12-21 19:32:11 +0100
commitae8f0a04190c3d13292ad68548f5275507e5812e (patch)
tree1bc207715280e6e9a1b99a84f9435e98d15bda1b /playlist_unittest.py
parent9ee7ee992d468b4f354ac16c34747e0c31d7b656 (diff)
Added some integration tests, refactored playlist, updated diagram
Diffstat (limited to 'playlist_unittest.py')
-rw-r--r--playlist_unittest.py53
1 files changed, 22 insertions, 31 deletions
diff --git a/playlist_unittest.py b/playlist_unittest.py
index ff5a79c..06785cc 100644
--- a/playlist_unittest.py
+++ b/playlist_unittest.py
@@ -1,76 +1,67 @@
from playlist import Playlist
+class MockPlayer:
+ def __init__(self):
+ self.songSetByCallback = None
+
+ def setCurrentSong(self, path):
+ self.songSetByCallback = path
+
def test_addAndSelectOneSong():
songAddedByUser = "/path/to/song"
- songSetByCallback = None
-
- def testCallback(song):
- nonlocal songSetByCallback
- songSetByCallback = song
+ mockPlayer = MockPlayer()
- uut = Playlist(testCallback)
+ uut = Playlist(mockPlayer)
uut.addSong(songAddedByUser)
uut.setCurrentSong(0)
- assert songAddedByUser == songSetByCallback
+ assert songAddedByUser == mockPlayer.songSetByCallback
assert uut.getCurrentSong() == songAddedByUser
assert uut.getSongs() == [songAddedByUser]
def test_addTwoSongsAndSelectBoth():
songAddedByUser = ["/path/to/song", "/path/to/second/song"]
- songSetByCallback = None
+ mockPlayer = MockPlayer()
- def testCallback(song):
- nonlocal songSetByCallback
- songSetByCallback = song
-
- uut = Playlist(testCallback)
+ uut = Playlist(mockPlayer)
uut.addSong(songAddedByUser[0])
uut.addSong(songAddedByUser[1])
assert uut.getSongs() == songAddedByUser
uut.setCurrentSong(0)
- assert songAddedByUser[0] == songSetByCallback
+ assert songAddedByUser[0] == mockPlayer.songSetByCallback
assert uut.getCurrentSong() == songAddedByUser[0]
uut.setCurrentSong(1)
- assert songAddedByUser[1] == songSetByCallback
+ assert songAddedByUser[1] == mockPlayer.songSetByCallback
assert uut.getCurrentSong() == songAddedByUser[1]
def test_firstAddedSongIsNotSelected():
songAddedByUser = "/path/to/song"
- songSetByCallback = None
-
- def testCallback(song):
- nonlocal songSetByCallback
- songSetByCallback = song
+ mockPlayer = MockPlayer()
- uut = Playlist(testCallback)
+ uut = Playlist(mockPlayer)
uut.addSong(songAddedByUser)
- assert songSetByCallback == None
+ assert mockPlayer.songSetByCallback == None
assert uut.getCurrentSong() == None
assert uut.getSongs() == [songAddedByUser]
def test_invalidSongSelection():
songAddedByUser = "/path/to/song"
- songSetByCallback = None
-
- def testCallback(song):
- nonlocal songSetByCallback
- songSetByCallback = song
+ mockPlayer = MockPlayer()
- uut = Playlist(testCallback)
- assert songSetByCallback == None
+ uut = Playlist(mockPlayer)
+ assert mockPlayer.songSetByCallback == None
assert uut.getCurrentSong() == None
uut.setCurrentSong(10)
- assert songSetByCallback == None
+ assert mockPlayer.songSetByCallback == None
assert uut.getCurrentSong() == None
uut.addSong(songAddedByUser)
uut.setCurrentSong(10)
- assert songSetByCallback == None
+ assert mockPlayer.songSetByCallback == None
assert uut.getCurrentSong() == None
assert uut.getSongs() == [songAddedByUser]