本文整理汇总了Python中playlist.Playlist.total_length方法的典型用法代码示例。如果您正苦于以下问题:Python Playlist.total_length方法的具体用法?Python Playlist.total_length怎么用?Python Playlist.total_length使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类playlist.Playlist
的用法示例。
在下文中一共展示了Playlist.total_length方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Tests
# 需要导入模块: from playlist import Playlist [as 别名]
# 或者: from playlist.Playlist import total_length [as 别名]
class Tests(unittest.TestCase):
def setUp(self):
self.playlist = Playlist('PlayList')
self.song = Song('title', 'artist', 'album', 5, 93, 256)
def test_song_init(self):
self.assertEqual(self.playlist.name, 'PlayList')
def test_add_song(self):
self.playlist.add_song(self.song)
self.assertEqual(self.playlist.playlist[0],self.song)
def test_remove_song(self):
self.playlist.remove_song('title')
self.assertEqual(len(self.playlist.playlist), 0)
def test_total_length(self):
song1 = Song('title1', 'artist1', 'album1', 5, 93, 256)
song2 = Song('title2', 'artist2', 'album2', 3, 87, 126)
self.playlist.add_song(song1)
self.playlist.add_song(song2)
self.assertEqual(self.playlist.total_length(),180)
def test_remove_disrated(self):
song1 = Song('title1', 'artist1', 'album1', 5, 93, 256)
song2 = Song('title2', 'artist2', 'album2', 3, 87, 126)
song3 = Song('title3', 'artist3', 'album3', 5, 88, 148)
self.playlist.add_song(song1)
self.playlist.add_song(song2)
self.playlist.add_song(song3)
self.playlist.remove_disrated(3)
self.assertEqual(self.playlist.total_length(),181)
def test_remove_bad_quality(self):
song1 = Song('title1', 'artist1', 'album1', 5, 93, 256)
song2 = Song('title2', 'artist2', 'album2', 3, 87, 126)
song3 = Song('title3', 'artist3', 'album3', 5, 88, 148)
self.playlist.add_song(song1)
self.playlist.add_song(song2)
self.playlist.add_song(song3)
self.playlist.remove_bad_quality(126)
self.assertEqual(self.playlist.total_length(),181)
def test_show_artists(self):
song1 = Song('title1', 'artist1', 'album1', 5, 93, 256)
song2 = Song('title2', 'artist2', 'album2', 3, 87, 126)
song3 = Song('title3', 'artist2', 'album3', 5, 88, 148)
self.playlist.add_song(song1)
self.playlist.add_song(song2)
self.playlist.add_song(song3)
artists = ['artist1','artist2']
self.assertEqual(artists,self.playlist.show_artists())
def test_str(self):
song1 = Song('title1', 'artist1', 'album1', 5, 93, 256)
song2 = Song('title2', 'artist2', 'album2', 3, 87, 126)
self.playlist.add_song(song1)
self.playlist.add_song(song2)
songs = 'artist1 title1 - 1:33\nartist2 title2 - 1:27\n'
self.assertEqual(songs,self.playlist.str())
示例2: test_total_length
# 需要导入模块: from playlist import Playlist [as 别名]
# 或者: from playlist.Playlist import total_length [as 别名]
def test_total_length(self):
song = Song(title="Loki", artist="Manowar", album="The Sons of Odin", length="1:30:44")
song2 = Song(title="Panda", artist="Grizli", album="Panda Dog", length="30:44")
song3 = Song(title="Panda2", artist="Grizli2", album="Panda Dog2", length="44")
code_songs = Playlist(name="Code", repeat=False, shuffle=False)
code_songs.add_song(song)
code_songs.add_song(song2)
code_songs.add_song(song3)
length_str = code_songs.total_length()
self.assertEqual(code_songs.total_length(), length_str)
示例3: test_total_length
# 需要导入模块: from playlist import Playlist [as 别名]
# 或者: from playlist.Playlist import total_length [as 别名]
def test_total_length(self):
new_playlist = Playlist("my_playlist")
harvester_song = Song("Harvester of sorrow", "Metallica", "...And justice for all", 3, 300, 192)
enter_song = Song("Enter sandman", "Metallica", "Balck album", 2, 300, 192)
new_playlist.songs.append(harvester_song)
new_playlist.songs.append(enter_song)
self.assertEqual(new_playlist.total_length(), 600)
示例4: test_total_length
# 需要导入模块: from playlist import Playlist [as 别名]
# 或者: from playlist.Playlist import total_length [as 别名]
def test_total_length(self):
playlist = Playlist("TestPlaylist")
song1 = Song("Thunderstruck", "ACDC", "The Razors Edge", 5, 271.8, 320)
song2 = Song("Thunderstruck", "ACDC", "The Razors Edge", 5, 200, 320)
playlist.add_song(song1)
playlist.add_song(song2)
self.assertEqual(playlist.total_length(), 471.8)
示例5: __init__
# 需要导入模块: from playlist import Playlist [as 别名]
# 或者: from playlist.Playlist import total_length [as 别名]
class MusicPlayer:
def __init__(self):
self.playlist = Playlist("Playlist")
def print_messages(self):
print("Hello, welcome to the music player interface!\n")
print("Load your playlist!")
def get_input(self):
command = input("Enter command> ")
command = command.split(" ")
return command
def interface(self):
command = self.get_input()
while command[0] != "exit":
if command[0] == "load_dir":
folder = MusicCrawler(command[1])
self.playlist = folder.generate_playlist()
command = self.get_input()
elif command[0] == "remove_song":
self.playlist.remove_song(command[1])
print("Songs removed.")
command = self.get_input()
elif command[0] == "total_length":
print(self.playlist.total_length())
command = self.get_input()
elif command[0] == "remove_disrated":
self.playlist.remove_disrated(command[1])
command = self.get_input()
elif command[0] == "remove_song":
self.playlist.remove_song(command[1])
command = self.get_input()
elif command[0] == "remove_bad_quality":
self.playlist.remove_bad_quality()
print("Songs removed.")
command = self.get_input()
elif command[0] == "show_artists":
print(self.playlist.show_artists())
command = self.get_input()
elif command[0] == "remove_song":
self.playlist.remove_song(command[1])
command = self.get_input()
elif command[0] == "save":
self.playlist.save(command[1])
command = self.get_input()
elif command[0] == "load":
self.playlist = self.playlist.load(command[1])
command = self.get_input()
elif command[0] == "print_playlist":
print(self.playlist)
command = self.get_input()
else:
print("Bad input!")
command = self.get_input()
else:
print("Goodbye!")
示例6: PlaylistTest
# 需要导入模块: from playlist import Playlist [as 别名]
# 或者: from playlist.Playlist import total_length [as 别名]
class PlaylistTest(unittest.TestCase):
def setUp(self):
self.song1 = Song("Title1", "Artist1", "Album1", 2, 192, 128)
self.song2 = Song("Title2", "Artist2", "Album2", 2, 183, 1024)
self.playlist = Playlist("PlaylistTitle")
self.playlist.songs.append(self.song1)
self.playlist.songs.append(self.song2)
def test_init(self):
self.assertEqual(self.playlist.name, "PlaylistTitle")
self.assertEqual(self.playlist.songs, [self.song1, self.song2])
def test_add_song(self):
self.song3 = Song("Title3", "Artist3", "Album3", 2, 201, 128)
self.playlist.add_song(self.song3)
self.assertEqual(
self.playlist.songs, [self.song1, self.song2, self.song3])
def test_remove_song(self):
self.song3 = Song("Title3", "Artist3", "Album3", 4, 194, 1024)
self.playlist.add_song(self.song3)
self.playlist.remove_song("Title3")
self.assertEqual(self.playlist.songs, [self.song1, self.song2])
def test_total_length(self):
self.assertEqual(self.playlist.total_length(), 375)
def test_remove_disrated(self):
self.song3 = Song("Title3", "Artist3", "Album3", 4, 206, 1024)
self.playlist.add_song(self.song3)
self.playlist.remove_disrated(3)
self.assertEqual(self.playlist.songs, [self.song3])
def test_remove_bad_quality(self):
self.song3 = Song("Title3", "Artist3", "Album3", 4, 206, 1024)
self.playlist.add_song(self.song3)
self.playlist.remove_bad_quality(1000)
self.assertEqual(self.playlist.songs, [self.song2, self.song3])
def test_show_artists(self):
self.song3 = Song("Title3", "Artist2", "Album3", 4, 206, 1024)
self.playlist.add_song(self.song3)
self.assertEqual(self.playlist.show_artists(), ["Artist1", "Artist2"])
# def test_str(self):
# test = self.playlist.str()
# self.assertEqual(
# "Artist1 Title1 - 3:12\nArtist2 Title2 - 3:03\n", test)
def test_save(self):
self.playlist.save("pesho.txt")
def test_load(self):
self.playlist.load("pesho.txt")
示例7: TestPlaylist
# 需要导入模块: from playlist import Playlist [as 别名]
# 或者: from playlist.Playlist import total_length [as 别名]
class TestPlaylist(unittest.TestCase):
def setUp(self):
self.playlist = Playlist("name")
self.song = Song("title", "artist", "album", 4, 200, 256)
self.beat = Song("beat", "dlg", "hrdlg", 2, 150, 20)
def test_init_playlist(self):
self.assertEqual(self.playlist.name, "name")
self.assertEqual(len(self.playlist.songs), 0)
def test_add_song(self):
self.playlist.add_song(self.song)
self.assertEqual(self.playlist.songs[0], self.song)
def test_remove_song(self):
self.playlist.add_song(self.song)
self.playlist.add_song(self.song)
self.playlist.remove_song("title")
self.assertEqual(len(self.playlist.songs), 0)
def test_total_length(self):
self.playlist.add_song(self.song)
self.playlist.add_song(self.beat)
self.assertEqual(self.playlist.total_length(), 350)
def test_remove_disrated(self):
self.playlist.add_song(self.song)
self.playlist.add_song(self.beat)
self.playlist.remove_disrated(3)
self.assertEqual(len(self.playlist.songs), 1)
self.playlist.remove_disrated(5)
self.assertEqual(len(self.playlist.songs), 0)
def test_remove_bad_quality(self):
self.playlist.add_song(self.song)
self.playlist.add_song(self.beat)
self.playlist.remove_bad_quality()
self.assertEqual(len(self.playlist.songs), 1)
def test_show_artists(self):
self.playlist.add_song(self.song)
self.playlist.add_song(self.beat)
self.playlist.add_song(self.song)
self.playlist.add_song(self.beat)
result = set()
result.add("artist")
result.add("dlg")
self.assertEqual(self.playlist.show_artists(), result)
def test_to_str(self):
self.playlist.add_song(self.song)
self.playlist.add_song(self.beat)
result = "artist title - 3:20\ndlg beat - 2:30\n"
self.assertEqual(str(self.playlist), result)
示例8: TestPlaylist
# 需要导入模块: from playlist import Playlist [as 别名]
# 或者: from playlist.Playlist import total_length [as 别名]
class TestPlaylist(unittest.TestCase):
def setUp(self):
self.playlist = Playlist('Pro Playlist')
self.song = Song("BeatBox", "PsychoFrog", "BB 2015", 4, 190, 320)
def tearDown(self):
os.remove('test_playlist.txt')
def test_add_song(self):
self.playlist.add_song(self.song)
self.assertIn(self.song, self.playlist.songs)
def test_remove_song(self):
self.playlist.add_song(self.song)
self.playlist.add_song(self.song)
self.playlist.add_song(self.song)
self.playlist.remove_song(self.song.title)
self.assertEqual(self.playlist.songs, [])
def test_total_length(self):
self.playlist.add_song(self.song)
self.playlist.add_song(self.song)
self.assertEqual(self.song.length + self.song.length, self.playlist.total_length())
def test_remove_disrated(self):
self.playlist.add_song(self.song)
self.playlist.remove_disrated(5)
self.assertEqual([], self.playlist.songs)
def test_remove_disrated_with_invalid_rating(self):
with self.assertRaises(ValueError):
self.playlist.remove_disrated(-1)
def test_remove_bad_quality(self):
self.playlist.add_song(self.song)
bad_bit_song = Song("d", "R", "A", 4, 40, 256)
self.playlist.add_song(bad_bit_song)
self.playlist.remove_bad_quality()
self.assertEqual([self.song], self.playlist.songs)
def test_show_artists(self):
self.playlist.add_song(self.song)
self.playlist.add_song(self.song)
self.playlist.add_song(Song("Other Song", "Other Artist", "Album", 5, 180, 320))
self.assertEqual(["PsychoFrog", "Other Artist"], self.playlist.show_artists())
def test_saving(self):
self.playlist.save('test_playlist.txt')
示例9: TestPlaylist
# 需要导入模块: from playlist import Playlist [as 别名]
# 或者: from playlist.Playlist import total_length [as 别名]
class TestPlaylist(unittest.TestCase):
def setUp(self):
self.test_playlist = Playlist("Rocking songs")
def test_init_playlist(self):
self.assertEqual(self.test_playlist.name, "Rocking songs")
def test_add_song(self):
test_song = Song("Take me", "AC DC", "Black in black", 4, 180, 320)
self.test_playlist.add_song(test_song)
self.assertIn(test_song, self.test_playlist.playlist)
def test_remove_song(self):
test_song = Song("Take me", "AC DC", "Black in black", 4, 180, 320)
self.test_playlist.delete_song(test_song)
self.assertNotIn(test_song, self.test_playlist.playlist)
def test_total_length(self):
test_song = Song("Take me", "AC DC", "Black in black", 4, 180, 320)
test_song2 = Song("Fuck me", "Metallica", "Rock it", 4, 100, 256)
self.test_playlist.add_song(test_song)
self.test_playlist.add_song(test_song2)
self.assertEqual(280, self.test_playlist.total_length())
def test_remove_disrated(self):
test_song = Song("Take me", "AC DC", "Black in black", 4, 180, 320)
self.test_playlist.add_song(test_song)
test_song.rate(5)
self.test_playlist.remove_disrated(5)
self.assertNotIn(test_song, self.test_playlist.playlist)
def test_remove_bad_quality(self):
test_song = Song("Take me", "AC DC", "Black in black", 4, 180, 64)
self.test_playlist.add_song(test_song)
self.assertIsNot(test_song, self.test_playlist.remove_bad_quality())
def test_show_artists(self):
test_song = Song("Take me", "AC DC", "Black in black", 4, 180, 64)
test_song1 = Song("BlaBla", "Metallica", "Black in black", 4, 180, 64)
test_song2 = Song("Take", "Rihanna", "Black in black", 4, 180, 64)
test_song3 = Song("me", "AC DC", "Black in black", 4, 180, 64)
test_song4 = Song("Take me", "AC DC", "Black in black", 4, 180, 64)
self.test_playlist.add_song(test_song)
self.test_playlist.add_song(test_song1)
self.test_playlist.add_song(test_song2)
self.test_playlist.add_song(test_song3)
self.test_playlist.add_song(test_song4)
self.assertListEqual(["AC DC", "Metallica", "Rihanna"], self.test_playlist.show_artists())
def test_str(self):
test_song = Song("Take me", "AC DC", "Black in black", 4, 180, 64)
self.test_playlist.add_song(test_song)
self.assertEqual("AC DC Take me - 3:00", self.test_playlist.__str__(test_song))
示例10: TestPlaylist
# 需要导入模块: from playlist import Playlist [as 别名]
# 或者: from playlist.Playlist import total_length [as 别名]
class TestPlaylist(unittest.TestCase):
def setUp(self):
self.plist = Playlist("plist out")
self.ruby = Song(
"Ruby",
"Kaiser Chiefs",
"Unknown",
1,
300,
320
)
self.rubyDNB = Song(
"Ruby DNB",
"Kaiser Chiefs",
"Unknown",
4,
300,
120
)
self.plist.add_song(self.ruby)
self.plist.add_song(self.ruby)
self.plist.add_song(self.rubyDNB)
def test_init(self):
self.assertEqual(self.plist.name, "plist out")
def test_add_song(self):
self.assertIn(self.ruby, self.plist.songs)
def test_remove_song(self):
self.plist.remove_song("Ruby")
self.assertNotIn(self.ruby, self.plist.songs)
def test_total_length(self):
self.assertEqual(self.plist.total_length(), 900)
def test_rating_out_of_range(self):
for item in self.plist.songs:
self.assertIn(item.rating, [1, 2, 3, 4, 5])
def test_remove_disrated(self):
self.plist.remove_disrated(3)
self.assertIn(self.rubyDNB, self.plist.songs)
self.assertNotIn(self.ruby, self.plist.songs)
def test_remove_bad_quality(self):
self.plist.remove_bad_quality()
self.assertNotIn(self.rubyDNB, self.plist.songs)
def test_show_artists(self):
self.assertEqual(self.plist.show_artists(), ["Kaiser Chiefs"])
示例11: TestPlaylist
# 需要导入模块: from playlist import Playlist [as 别名]
# 或者: from playlist.Playlist import total_length [as 别名]
class TestPlaylist(unittest.TestCase):
def setUp(self):
self.playlist = Playlist("test_playlist")
self.test_song = Song("Highway to Hell", "AC/DC", "Highway to Hell", 5, 208, 128, "sda")
self.test_song2 = Song("Back in Black", "ACDC", "Back in Black", 4, 200, 256, "sdb")
self.playlist.add_song(self.test_song)
self.playlist.add_song(self.test_song2)
self.playlist.save("sdadada.json")
#self.playlist.load("sdadada.json")
def test_init(self):
self.assertEqual("test_playlist", self.playlist.name)
def test_playlist_add_song(self):
self.assertListEqual(self.playlist.songs, [self.test_song, self.test_song2])
self.assertEqual(self.playlist.totalLength, 408)
def test_playlist_remove_song(self):
self.playlist.remove_song(self.test_song.title)
self.assertListEqual(self.playlist.songs, [self.test_song2])
self.assertEqual(self.playlist.totalLength, 200)
def test_playlist_total_length(self):
self.playlist.remove_song(self.test_song.title)
self.assertEqual(self.playlist.total_length(), 200)
def test_playlist_remove_disrated(self):
self.playlist.remove_disrated(5)
self.assertListEqual(self.playlist.songs, [self.test_song])
self.assertEqual(self.playlist.total_length(), 208)
def test_playlist_remove_bad_quality(self):
self.playlist.remove_bad_quality()
self.assertListEqual(self.playlist.songs, [self.test_song2])
self.assertEqual(self.playlist.total_length(), 200)
def test_playlist_list_artists(self):
self.playlist.add_song(self.test_song2)
artists = self.playlist.list_artists()
self.assertListEqual(["AC/DC", "ACDC"], artists)
示例12: TestPlaylist
# 需要导入模块: from playlist import Playlist [as 别名]
# 或者: from playlist.Playlist import total_length [as 别名]
class TestPlaylist(unittest.TestCase):
def setUp(self):
self.testPlaylist = Playlist("My Playlist")
self.testSong = Song("Title", "Artist", "Album", 5, 120, 512)
self.testSong2 = Song("Title2", "Artist", "Album", 2, 120, 320)
self.testPlaylist.add_song(self.testSong)
def test_init(self):
self.assertEqual(self.testPlaylist.name, "My Playlist")
def test_add_song(self):
self.assertEqual(self.testPlaylist.collection, [self.testSong])
def test_remove_song(self):
self.testPlaylist.add_song(self.testSong2)
self.testSong3 = Song("Title2", "Artist", "Album", 1, 120, 320)
self.testPlaylist.add_song(self.testSong3)
self.testPlaylist.remove_song("Title2")
self.assertEqual(self.testPlaylist.collection, [self.testSong])
def test_total_length(self):
self.testPlaylist.add_song(self.testSong2)
result = self.testPlaylist.total_length()
self.assertEqual(result, 240)
def test_remove_disrated_with_value_error(self):
with self.assertRaises(ValueError):
self.testPlaylist.remove_disrated(6)
with self.assertRaises(ValueError):
self.testPlaylist.remove_disrated(0)
def test_remove_disrated_with_correct_input(self):
self.testPlaylist.add_song(self.testSong2)
self.testSong3 = Song("Title2", "Artist", "Album", 1, 120, 320)
self.testPlaylist.add_song(self.testSong3)
self.testPlaylist.remove_disrated(3)
self.assertEqual(self.testPlaylist.collection, [self.testSong])
def test_remove_bad_quality(self):
self.testPlaylist.add_song(self.testSong2)
self.testSong3 = Song("Title2", "Artist", "Album", 1, 120, 192)
self.testPlaylist.add_song(self.testSong3)
self.testPlaylist.remove_bad_quality(340)
self.assertEqual(self.testPlaylist.collection, [self.testSong])
def test_show_artists(self):
self.testPlaylist.add_song(self.testSong2)
self.testSong3 = Song("Title2", "Artist", "Album", 1, 120, 192)
self.testPlaylist.add_song(self.testSong3)
result = self.testPlaylist.show_artists()
self.assertEqual(result, {"Artist"})
示例13: PlaylistTest
# 需要导入模块: from playlist import Playlist [as 别名]
# 或者: from playlist.Playlist import total_length [as 别名]
class PlaylistTest(unittest.TestCase):
def setUp(self):
self.playlist = Playlist("Indie")
self.song1 = Song(
"Shelter", "Years & Years", "EP", 5, 320, 512)
self.song2 = Song(
"Shelter2", "Years & Years", "EP2", 5, 200, 64)
def test_add_song(self):
self.playlist.add_song(self.song1)
self.playlist.add_song(self.song2)
self.assertEqual(self.playlist.songlist[0],self.song1)
self.assertEqual(self.playlist.songlist[1],self.song2)
def test_remove_song(self):
self.playlist.add_song(self.song1)
song_name="Shelter2"
self.playlist.remove_song(song_name)
self.assertNotIn(song_name, self.playlist.songlist)
def test_total_length(self):
self.playlist.add_song(self.song1)
self.playlist.add_song(self.song2)
self.assertEqual(self.playlist.total_length(),520)
def test_remove_bad_quality(self):
self.playlist.add_song(self.song1)
self.playlist.add_song(self.song2)
self.playlist.remove_bad_quality()
self.assertNotIn(self.song2,self.playlist.songlist)
def test_save_file_with_json_output(self):
def test_show_artist(self):
pass
if __name__ == '__main__':
unittest.main()
示例14: TestPlaylist
# 需要导入模块: from playlist import Playlist [as 别名]
# 或者: from playlist.Playlist import total_length [as 别名]
class TestPlaylist(unittest.TestCase):
def setUp(self):
self.my_playlist = Playlist("Qki pesni 2011")
self.song = Song("Title", "Gosho ot pochivka", "Album", 100, 128)
self.song1 = Song("Title2", "Gosho ot pochivka2", "Album", 200, 256)
self.song2 = Song("Title3", "Gosho ot pochivka2", "Album", 200, 128)
def test_init(self):
self.assertEqual("Qki pesni 2011", self.my_playlist.name)
def test_add_song(self):
self.my_playlist.add_song(self.song)
self.assertIn(self.song, self.my_playlist.playlist)
def test_remove_song(self):
self.my_playlist.add_song(self.song)
self.my_playlist.remove_song("Title")
self.assertNotIn(self.song, self.my_playlist.playlist)
def test_total_length(self):
self.my_playlist.add_song(self.song)
self.my_playlist.add_song(self.song1)
self.assertEqual(300, self.my_playlist.total_length())
def test_remove_disrated(self):
self.song.rate(2)
self.my_playlist.add_song(self.song)
self.song1.rate(4)
self.my_playlist.add_song(self.song1)
self.song2.rate(3)
self.my_playlist.add_song(self.song2)
self.my_playlist.remove_disrated(3)
self.assertNotIn(self.song, self.my_playlist.playlist)
self.assertNotIn(self.song2, self.my_playlist.playlist)
def test_remove_bad_quality(self):
self.my_playlist.add_song(self.song)
self.my_playlist.add_song(self.song1)
self.my_playlist.remove_bad_quality()
self.assertNotIn(self.song, self.my_playlist.playlist)
def test_show_artists(self):
self.my_playlist.add_song(self.song)
self.my_playlist.add_song(self.song1)
song2 = Song("Title5", "Gosho ot pochivka", "Album", 100, 128)
self.my_playlist.add_song(song2)
artists = ["Gosho ot pochivka", "Gosho ot pochivka2"]
self.assertEqual(artists, self.my_playlist.show_artists())
示例15: PlaylistTests
# 需要导入模块: from playlist import Playlist [as 别名]
# 或者: from playlist.Playlist import total_length [as 别名]
class PlaylistTests(unittest.TestCase):
def setUp(self):
self.playlist = Playlist("Test Playlist")
self.song = Song("The Jack", "ACDC", "T.N.T.", 4, 256, 320)
self.song_2 = Song("The Mack", "ACDC", "B.N.B.", 2, 256, 96)
def test_init(self):
test_playlist = Playlist("ASDF")
self.assertEqual(test_playlist.name, "ASDF")
def test_add_song_success(self):
self.playlist.add_song(self.song)
self.assertEqual(self.playlist.songs[0], self.song)
def test_add_song_type_error(self):
with self.assertRaises(TypeError):
self.playlist.add_song("Some newspaper title")
def test_remove_song(self):
self.playlist.add_song(self.song)
self.playlist.add_song(self.song_2)
self.playlist.remove_song(self.song.title)
self.assertEqual(self.playlist.songs, [self.song_2])
def test_total_length(self):
self.playlist.add_song(self.song)
self.playlist.add_song(self.song_2)
self.assertEqual(self.playlist.total_length(), 512)
def test_remove_disrated(self):
self.playlist.add_song(self.song)
self.playlist.add_song(self.song_2)
print(self.playlist)
self.playlist.remove_disrated(3)
self.assertEqual(self.playlist.songs, [self.song])
print(self.playlist)
def test_remove_disrated_value_error(self):
self.playlist.add_song(self.song)
self.playlist.add_song(self.song_2)
with self.assertRaises(ValueError):
self.playlist.remove_disrated(8)