aboutsummaryrefslogtreecommitdiffstats
path: root/playlist_unittest.py
diff options
context:
space:
mode:
authorEddy Pedroni <eddy@0xf7.com>2021-12-19 19:41:55 +0100
committerEddy Pedroni <eddy@0xf7.com>2021-12-19 19:41:55 +0100
commit931ddc7ec9a4c719d6aa08b0a1ac613a95d88b84 (patch)
tree31f50de465d011a5fc508ea982d28c2b6a8d2b25 /playlist_unittest.py
parentc6b5fa928719a05782de40a86fcb90feca92fce3 (diff)
Added architecture diagram, refactored playlist to match
Diffstat (limited to 'playlist_unittest.py')
-rw-r--r--playlist_unittest.py65
1 files changed, 65 insertions, 0 deletions
diff --git a/playlist_unittest.py b/playlist_unittest.py
new file mode 100644
index 0000000..685dcb0
--- /dev/null
+++ b/playlist_unittest.py
@@ -0,0 +1,65 @@
+from playlist import Playlist
+
+def test_addAndSelectOneSong():
+ songAddedByUser = "/path/to/song"
+ songSetByCallback = None
+
+ def testCallback(song):
+ nonlocal songSetByCallback
+ songSetByCallback = song
+
+ uut = Playlist(testCallback)
+ uut.addSong(songAddedByUser)
+ uut.setCurrentSong(0)
+
+ assert songAddedByUser == songSetByCallback
+
+def test_addTwoSongsAndSelectBoth():
+ songAddedByUser = ["/path/to/song", "/path/to/second/song"]
+ songSetByCallback = None
+
+ def testCallback(song):
+ nonlocal songSetByCallback
+ songSetByCallback = song
+
+ uut = Playlist(testCallback)
+ uut.addSong(songAddedByUser[0])
+ uut.addSong(songAddedByUser[1])
+
+ uut.setCurrentSong(0)
+ assert songAddedByUser[0] == songSetByCallback
+
+ uut.setCurrentSong(1)
+ assert songAddedByUser[1] == songSetByCallback
+
+def test_firstAddedSongIsSelected():
+ songAddedByUser = "/path/to/song"
+ songSetByCallback = None
+
+ def testCallback(song):
+ nonlocal songSetByCallback
+ songSetByCallback = song
+
+ uut = Playlist(testCallback)
+ uut.addSong(songAddedByUser)
+
+ assert songAddedByUser == songSetByCallback
+
+def test_invalidSongSelection():
+ songAddedByUser = "/path/to/song"
+ songSetByCallback = None
+
+ def testCallback(song):
+ nonlocal songSetByCallback
+ songSetByCallback = song
+
+ uut = Playlist(testCallback)
+ assert songSetByCallback == None
+
+ uut.setCurrentSong(10)
+ assert songSetByCallback == None
+
+ uut.addSong(songAddedByUser)
+ uut.setCurrentSong(10)
+ assert songSetByCallback == songAddedByUser
+