class PlaylistTest(unittest.TestCase): def setUp(self): self.my_song = Song("Solder Of Frortune", "Deep Purple", "Stormbringer", "3:14") self.second_song = Song("I Stand Alone", "Godsmack", "Awake", "4:30") self.rock = Playlist("Rock songs", True) self.songs = [self.my_song, self.second_song] self.rock.add_songs(self.songs) def test_playlist_constructor(self): self.assertTrue(isinstance(self.rock, Playlist)) def test_add_song(self): self.assertEqual(self.rock.playlist, self.songs) def test_remove_song(self): self.rock.remove_song(self.my_song) self.assertEqual(self.rock.playlist, [self.second_song]) def test_remove_song_fail(self): self.rock.remove_song(self.my_song) with self.assertRaises(NoSuchSong): self.rock.remove_song(self.my_song) def test_add_songs(self): self.assertEqual(self.rock.playlist, self.songs) def test_total_length(self): self.assertEqual(self.rock.total_length(), "0:07:44") def test_artists(self): histogram = {"Deep Purple": 1, "Godsmack": 1} self.assertEqual(self.rock.artists(), histogram) def test_repeat(self): self.assertEqual(self.rock.next_song(), self.my_song) self.assertEqual(self.rock.next_song(), self.second_song) self.assertEqual(self.rock.next_song(), self.my_song) def test_no_more_songs(self): self.rock.change_repeat(False) self.assertEqual(self.rock.next_song(), self.my_song) self.assertEqual(self.rock.next_song(), self.second_song) with self.assertRaises(NoMoreSongs): self.rock.next_song() self.rock.change_shuffle(True) self.rock.next_song() self.rock.next_song() with self.assertRaises(NoMoreSongs): self.rock.next_song() def test_shuffle(self): self.rock.change_shuffle(True) bard = Song("The Bard's Song", "Blind Guardian", "Somwhere Far Beyond", "3:28") self.rock.add_song(bard) a = self.rock.next_song() b = self.rock.next_song() c = self.rock.next_song() self.assertTrue(a != b and c != a and c != b)
def test_the_function_artists_of_a_playlist_then_return_dictionary_where_keys_are_the_artists_and_values_are_the_numbers_of_the_songs(self): song = Song(title="Odin", artist="Manowar1", album="The Sons of Odin", length="3:44") song2 = Song(title="Odin", artist="Manowar2", album="The Sons of Odin", length="3:44") song3 = Song(title="Odin", artist="Manowar3", album="The Sons of Odin", length="3:44") playlist = Playlist(name="Code", repeat=True, shuffle=True) playlist.add_songs([song, song2, song3]) expected_result = {'Manowar1': 1, 'Manowar2': 1, 'Manowar3': 1} self.assertEqual(playlist.artists(), expected_result)
def test_playlist_artists_works_as_expected(self): my_playlist = Playlist(name="Code", repeat=True, shuffle=True) test = Song(title="Odin", artist="Manowar", album="The Sons of Odin", length="3:44") my_playlist.add_song(test) self.assertEqual(my_playlist.artists(), {'Manowar': 1})
def test_class_Playlist_method_artist(self): song2 = Song(artist="Metalica", album="metalica", length=385, song_name="Nothing else matters") song3 = Song( artist="Metalica", album="metalica", length=385, song_name="The Unforgiven") song4 = Song(artist="Iron Maiden", album="Power Slave", length=385, song_name="Fear of the dark") song5 = Song( artist="Iron Maiden", album="Power Slave", length=385, song_name="Acces High") song6 = Song(artist="Qvkata DLG", album="Човека който се смее", length=385, song_name="Екстра а ти ?") songs = [song2, song3, song4, song5, song6] pl = Playlist("rado") pl.add_songs(songs) self.assertTrue(pl.artists()["Metalica"] == 2) self.assertTrue(pl.artists()["Iron Maiden"] == 2) self.assertTrue(pl.artists()["Qvkata DLG"] == 1)
class TestPlaylist(unittest.TestCase): def setUp(self): self.code_songs = Playlist(name="Code", repeat=True, shuffle=True) def test_initialisation(self): self.assertTrue(isinstance(self.code_songs, Playlist)) def test_add_remove_song(self): a = Song() self.assertFalse(a in self.code_songs.song_list) self.code_songs.add_song(a) self.assertTrue(a in self.code_songs.song_list) self.code_songs.remove_song(a) self.assertTrue(a not in self.code_songs.song_list) def test_add_songs(self): a = Song() b = Song(title="Pesho's song", artist="Pesho", album="Pesho/'s album", length="23:22:12") l = [] l.append(a) l.append(b) self.code_songs.add_songs(l) self.assertTrue(a in self.code_songs.song_list) self.assertTrue(b in self.code_songs.song_list) def test_artists_histogram(self): a = Song(title="alaba", artist="Rihanna", album="Nqkoi", length="12:02") b = Song(title="Pesho's song", artist="Pesho", album="Pesho/'s album", length="23:22:12") c = Song(title="PeshosOtherSong", artist="Pesho", album="blaa", length="22:12") self.code_songs.song_list.append(a) self.code_songs.song_list.append(b) self.code_songs.song_list.append(c) dicta = {} dicta['Pesho'] = 2 dicta['Rihanna'] = 1 self.assertEqual(dicta, self.code_songs.artists()) def test_total_length(self): a = Song(title="alaba", artist="Rihanna", album="Nqkoi", length="12:02") b = Song(title="Pesho's song", artist="Pesho", album="Pesho/'s album", length="23:22:12") c = Song(title="PeshosOtherSong", artist="Pesho", album="blaa", length="22:12") self.code_songs.song_list.append(a) self.code_songs.song_list.append(b) self.code_songs.song_list.append(c) self.assertEqual(self.code_songs.total_length(), '23:56:26')
class MusicPlayerTest(unittest.TestCase): def setUp(self): self.song = Song("Odin", "Manowar", "The Sons of Odin", "3:44") self.playlist = Playlist("The sex and the city") def test_str(self): self.assertEqual(str( self.song), "Manowar - Odin (The Sons of Odin) : 3:44") def test_adding_song_in_playlist(self): self.playlist.add_song(self.song) self.assertTrue(self.playlist.has_song(self.song)) def test_removing_song(self): self.playlist.add_song(self.song) self.playlist.remove_song(self.song) self.assertFalse(self.playlist.has_song(self.song)) def test_total_length(self): song = Song("Baby", "J.Beiber", "Gay Album", "3:50") self.playlist.add_songs([self.song, song]) self.assertEqual(self.playlist.total_length(), "0:07:34") def test_artists(self): song = Song("Baby", "J.Beiber", "Gay Album", "3:50") self.playlist.add_songs([self.song, song]) self.assertEqual( self.playlist.artists(), {'Manowar': 1, "J.Beiber": 1}) def test_play_next_song_in_empty_playlist(self): with self.assertRaises(Exception): self.playlist.next_song() def test_play_next_song_if_there_is_only_one_with_repeat_False(self): self.playlist.add_song(self.song) with self.assertRaises(Exception): self.playlist.next_song() def test_next_songs_with_repeat_False(self): random_song = Song("Random", "Manowar", "The Sons of Odin", "1:30:44") another_song = Song("Anther", "Manowar", "The Sons of Odin", "1:30:44") self.playlist.add_songs([self.song, random_song, another_song]) self.assertEqual(self.playlist.next_song(), random_song) self.assertEqual(self.playlist.next_song(), another_song) with self.assertRaises(Exception): self.playlist.next_song() def test_next_songs_with_repeat_True(self): random_song = Song("Random", "Random", "The Sons of Odin", "3:44") another_song = Song("Anther", "Kanye West", "Heartless", "4:20") song = Song("Baby", "J.Beiber", "Gay Album", "3:50") p = Playlist("p", repeat=True) p.add_songs([self.song, random_song, another_song, song]) self.assertEqual(p.next_song(), random_song) self.assertEqual(p.next_song(), another_song) self.assertEqual(p.next_song(), song) self.assertEqual(p.next_song(), self.song) def test_generate_json_name(self): self.assertEqual( self.playlist.generate_json_name(), "The-sex-and-the-city.json") def test_save_load(self): song = Song("Baby", "J.Beiber", "Gay Album", "3:50") self.playlist.add_songs([self.song, song]) self.playlist.save() g = Playlist.load("The-sex-and-the-city.json") self.assertEqual(self.playlist.songs, g.songs) self.assertEqual(g.name, "The sex and the city") def test_crawler_generate_ability(self): crawler = MusicCrawler("/home/hdimitrova/Music/Linkin Park - Meteora") playlist = crawler.generate_playlist("Meteora") self.assertEqual(playlist.total_length(), '0:36:41') def test_crawlered_playlist_save(self): crawler = MusicCrawler("/home/hdimitrova/Music/Linkin Park - Meteora") playlist = crawler.generate_playlist("Linkin Park - Meteora") playlist.save() playlist.pprint_playlist()
def test_artists_return_histogram_of_artists_in_playlist(self): test_playlist = Playlist('OneRepublic', songs_list = [Song(title='Love Runs Out', artist='OneRepublic', album='Native', length='3:44'), Song(title='Counting Stars', artist='OneRepublic', album='Native', length='3:50')]) expected_result = {'OneRepublic': 2} self.assertEqual(test_playlist.artists(), expected_result)