def setUp(self): self.song = Song("RAndom", "mr.Random", "the best of Random", "1:30") self.song1 = Song("Runaway", "Bon Jovi", "Greatest", "03:51") self.song2 = Song("In and out", "Bon Jovi", "Greatest", "04:26") self.test_list = [] self.test_list.append(self.song1) self.test_list.append(self.song2) self.play_list = Playlist("rrrr")
def generate_playlist(self): pl = Playlist(name="New_Generated_Playlist") for el in self.songs: album = MP3(self.path + "/" + el).tags["TALB"] artist = MP3(self.path + "/" + el).tags["TPE1"] title = MP3(self.path + "/" + el).tags["TIT2"] secs = MP3(self.path + "/" + el).info.pprint().split(", ")[-1] secs = self.format_length(int(secs.split(".")[0])) pl.add_song( Song(title=str(title), artist=str(artist), album=str(album), length=secs, path_to_file=self.path + "/" + el)) return pl
def setUp(self): self.pl1 = Playlist()
class TestPlayList(unittest.TestCase): def setUp(self): self.song = Song("RAndom", "mr.Random", "the best of Random", "1:30") self.song1 = Song("Runaway", "Bon Jovi", "Greatest", "03:51") self.song2 = Song("In and out", "Bon Jovi", "Greatest", "04:26") self.test_list = [] self.test_list.append(self.song1) self.test_list.append(self.song2) self.play_list = Playlist("rrrr") def test_add_song(self): self.play_list.add_song(self.song) self.assertIn(self.song, self.play_list.get_songs()) def test_add_songs(self): self.play_list.add_songs(self.test_list) self.assertIn(self.song1, self.play_list.get_songs()) self.assertIn(self.song2, self.play_list.get_songs()) def test_remove_song(self): self.play_list.add_songs(self.test_list) self.play_list.remove_song(self.song2) self.assertIsNot(self.song2, self.play_list.get_songs()) def test_total_length(self): self.play_list.add_songs(self.test_list) self.play_list.add_song(self.song) self.assertEquals(self.play_list.total_length(), "00:09:47")
class TestPlaylist(unittest.TestCase): def setUp(self): self.pl1 = Playlist() def test_add_song(self): self.assertFalse(self.pl1.songs) self.pl1.add_song(Song()) self.assertTrue(self.pl1.songs) def test_remove_song(self): song = Song() self.pl1.add_song(song) self.pl1.remove_song(song) self.assertFalse(self.pl1.songs) def test_add_songs(self): songs = [Song(), Song("Pretty Fly")] self.pl1.add_songs(songs) self.assertEqual(len(self.pl1.songs), 2) def test_toatl_length(self): songs = [Song(), Song("Pretty Fly", "The Offspring")] self.pl1.add_songs(songs) self.assertEqual(self.pl1.total_length(), "0:7:28") def test_artist(self): songs = [Song(), Song("Pretty Fly", "The Offspring")] self.pl1.add_songs(songs) self.assertEqual(self.pl1.artists(), { "Manowar": 1, "The Offspring": 1 })