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() uut = Playlist(mockPlayer) uut.addSong(songAddedByUser) uut.setCurrentSong(0) assert songAddedByUser == mockPlayer.songSetByCallback assert uut.getCurrentSong() == songAddedByUser assert uut.getSongs() == [songAddedByUser] def test_addTwoSongsAndSelectBoth(): songAddedByUser = ["/path/to/song", "/path/to/second/song"] mockPlayer = MockPlayer() uut = Playlist(mockPlayer) uut.addSong(songAddedByUser[0]) uut.addSong(songAddedByUser[1]) assert uut.getSongs() == songAddedByUser uut.setCurrentSong(0) assert songAddedByUser[0] == mockPlayer.songSetByCallback assert uut.getCurrentSong() == songAddedByUser[0] uut.setCurrentSong(1) assert songAddedByUser[1] == mockPlayer.songSetByCallback assert uut.getCurrentSong() == songAddedByUser[1] def test_firstAddedSongIsNotSelected(): songAddedByUser = "/path/to/song" mockPlayer = MockPlayer() uut = Playlist(mockPlayer) uut.addSong(songAddedByUser) assert mockPlayer.songSetByCallback == None assert uut.getCurrentSong() == None assert uut.getSongs() == [songAddedByUser] def test_invalidSongSelection(): songAddedByUser = "/path/to/song" mockPlayer = MockPlayer() uut = Playlist(mockPlayer) assert mockPlayer.songSetByCallback == None assert uut.getCurrentSong() == None uut.setCurrentSong(10) assert mockPlayer.songSetByCallback == None assert uut.getCurrentSong() == None uut.addSong(songAddedByUser) uut.setCurrentSong(10) assert mockPlayer.songSetByCallback == None assert uut.getCurrentSong() == None assert uut.getSongs() == [songAddedByUser]