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