From 663970d0165e226147d95fb92c617714dfbd7553 Mon Sep 17 00:00:00 2001 From: Eddy Pedroni Date: Tue, 21 Dec 2021 20:26:05 +0100 Subject: Rolled back some refactorings, added some integration tests --- playlist_unittest.py | 53 ++++++++++++++++++++++++++++++---------------------- 1 file changed, 31 insertions(+), 22 deletions(-) (limited to 'playlist_unittest.py') diff --git a/playlist_unittest.py b/playlist_unittest.py index 06785cc..ff5a79c 100644 --- a/playlist_unittest.py +++ b/playlist_unittest.py @@ -1,67 +1,76 @@ 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" - mockPlayer = MockPlayer() + songSetByCallback = None + + def testCallback(song): + nonlocal songSetByCallback + songSetByCallback = song - uut = Playlist(mockPlayer) + uut = Playlist(testCallback) uut.addSong(songAddedByUser) uut.setCurrentSong(0) - assert songAddedByUser == mockPlayer.songSetByCallback + assert songAddedByUser == songSetByCallback assert uut.getCurrentSong() == songAddedByUser assert uut.getSongs() == [songAddedByUser] def test_addTwoSongsAndSelectBoth(): songAddedByUser = ["/path/to/song", "/path/to/second/song"] - mockPlayer = MockPlayer() + songSetByCallback = None - uut = Playlist(mockPlayer) + def testCallback(song): + nonlocal songSetByCallback + songSetByCallback = song + + uut = Playlist(testCallback) uut.addSong(songAddedByUser[0]) uut.addSong(songAddedByUser[1]) assert uut.getSongs() == songAddedByUser uut.setCurrentSong(0) - assert songAddedByUser[0] == mockPlayer.songSetByCallback + assert songAddedByUser[0] == songSetByCallback assert uut.getCurrentSong() == songAddedByUser[0] uut.setCurrentSong(1) - assert songAddedByUser[1] == mockPlayer.songSetByCallback + assert songAddedByUser[1] == songSetByCallback assert uut.getCurrentSong() == songAddedByUser[1] def test_firstAddedSongIsNotSelected(): songAddedByUser = "/path/to/song" - mockPlayer = MockPlayer() + songSetByCallback = None + + def testCallback(song): + nonlocal songSetByCallback + songSetByCallback = song - uut = Playlist(mockPlayer) + uut = Playlist(testCallback) uut.addSong(songAddedByUser) - assert mockPlayer.songSetByCallback == None + assert songSetByCallback == None assert uut.getCurrentSong() == None assert uut.getSongs() == [songAddedByUser] def test_invalidSongSelection(): songAddedByUser = "/path/to/song" - mockPlayer = MockPlayer() + songSetByCallback = None + + def testCallback(song): + nonlocal songSetByCallback + songSetByCallback = song - uut = Playlist(mockPlayer) - assert mockPlayer.songSetByCallback == None + uut = Playlist(testCallback) + assert songSetByCallback == None assert uut.getCurrentSong() == None uut.setCurrentSong(10) - assert mockPlayer.songSetByCallback == None + assert songSetByCallback == None assert uut.getCurrentSong() == None uut.addSong(songAddedByUser) uut.setCurrentSong(10) - assert mockPlayer.songSetByCallback == None + assert songSetByCallback == None assert uut.getCurrentSong() == None assert uut.getSongs() == [songAddedByUser] -- cgit v1.2.3