本文整理汇总了Python中playlist.Playlist.remove_disrated方法的典型用法代码示例。如果您正苦于以下问题:Python Playlist.remove_disrated方法的具体用法?Python Playlist.remove_disrated怎么用?Python Playlist.remove_disrated使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类playlist.Playlist
的用法示例。
在下文中一共展示了Playlist.remove_disrated方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Tests
# 需要导入模块: from playlist import Playlist [as 别名]
# 或者: from playlist.Playlist import remove_disrated [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: __init__
# 需要导入模块: from playlist import Playlist [as 别名]
# 或者: from playlist.Playlist import remove_disrated [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!")
示例3: TestPlaylist
# 需要导入模块: from playlist import Playlist [as 别名]
# 或者: from playlist.Playlist import remove_disrated [as 别名]
class TestPlaylist (unittest.TestCase):
def setUp(self):
self.playlist = Playlist("TestPlaylist")
self.song = Song("Thunderstruck", "ACDC", "The Razors Edge", 5, 271.8, 320)
self.song2 = Song("Nothing else matters", "Metallica", "IDK", 0, 271.8, 320)
self.playlist.add_song(self.song)
self.playlist.add_song(self.song2)
"""def test_playlist_init(self):
self.assertEqual(self.playlist.name, "TestPlaylist")
self.assertListEqual(self.playlist.songs,[])"""
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)
song_name = "Thunderstruck"
self.playlist.remove_song(song_name)
self.assertNotIn(song_name, self.playlist.songs)
#Check if removes more than 1 song if we have 3 eqqual songs!
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)
def test_remove_disrated(self):
song = Song("Thunderstruck", "ACDC", "The Razors Edge", 0, 271.8, 320)
self.playlist.add_song(song)
self.playlist.remove_disrated(2)
self.assertNotIn(song, self.playlist.songs)
def test_show_artists(self):
song1 = Song("Thunderstruck", "ACDC", "The Razors Edge", 0, 271.8, 320)
self.playlist.add_song(song1)
song2 = Song("Nothing else matters", "Metallica", "IDK", 0, 271.8, 320)
self.playlist.add_song(song2)
self.assertEqual(self.playlist.show_artists(), ["ACDC", "Metallica"])
def test_save(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.playlist.save("json.txt")
示例4: PlaylistTest
# 需要导入模块: from playlist import Playlist [as 别名]
# 或者: from playlist.Playlist import remove_disrated [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")
示例5: TestPlaylist
# 需要导入模块: from playlist import Playlist [as 别名]
# 或者: from playlist.Playlist import remove_disrated [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)
示例6: test_remove_disrated
# 需要导入模块: from playlist import Playlist [as 别名]
# 或者: from playlist.Playlist import remove_disrated [as 别名]
def test_remove_disrated(self):
new_playlist = Playlist("my_playlist")
enter_song = Song("Enter sandman", "Metallica", "Balck album", 2, 300, 192)
enter_song1 = Song("Enter sandman", "Metallica", "Balck album", 2.5, 300, 192)
harvester_song = Song("Harvester of sorrow", "Metallica", "...And justice for all",4 , 300, 150)
new_playlist.songs.append(harvester_song)
new_playlist.songs.append(enter_song1)
new_playlist.songs.append(enter_song)
new_playlist.remove_disrated(3)
self.assertEqual(len(new_playlist.songs), 1)
self.assertEqual(new_playlist.songs[0], harvester_song)
示例7: TestPlaylist
# 需要导入模块: from playlist import Playlist [as 别名]
# 或者: from playlist.Playlist import remove_disrated [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')
示例8: TestPlaylist
# 需要导入模块: from playlist import Playlist [as 别名]
# 或者: from playlist.Playlist import remove_disrated [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))
示例9: TestPlaylist
# 需要导入模块: from playlist import Playlist [as 别名]
# 或者: from playlist.Playlist import remove_disrated [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"])
示例10: TestPlaylist
# 需要导入模块: from playlist import Playlist [as 别名]
# 或者: from playlist.Playlist import remove_disrated [as 别名]
class TestPlaylist(unittest.TestCase):
def setUp(self):
self.song1 = Song("Title1", "Artist","Album", 5.0, 4, 320)
self.song2 = Song("Title2", "Artist","Album", 2.0, 2, 320)
self.song3 = Song("Title3", "Artist2","Album", 5.0, 4, 128)
self.my_playlist = Playlist("Playlist")
self.my_playlist.songs.append(self.song1)
self.my_playlist.songs.append(self.song2)
self.my_playlist.songs.append(self.song3)
def test_init(self):
self.assertEqual(self.my_playlist.songs, [self.song1, self.song2, self.song3])
self.assertEqual(self.my_playlist.name, "Playlist")
def test_add_song(self):
self.song4 = Song("Title", "Artist","Album", 5.0, 4.22, 320)
self.my_playlist.add_song(self.song4)
self.assertEqual(self.my_playlist.songs, [self.song1, self.song2, self.song3, self.song4])
def test_remove_song(self):
self.my_playlist.remove_song("Title2")
self.assertEqual(self.my_playlist.songs, [self.song1, self.song3])
def test_total_lenght(self):
self.assertEqual(self.my_playlist.total_lenght(), 10)
def test_remove_disrated(self):
self.my_playlist.remove_disrated(3)
self.assertEqual(self.my_playlist.songs, [self.song1, self.song3])
def test_remove_bad_quality(self):
self.my_playlist.remove_bad_quality(320)
self.assertEqual(self.my_playlist.songs, [self.song1, self.song2])
def test_show_artists(self):
self.assertEqual(self.my_playlist.show_artits(), ["Artist", "Artist2"])
def test_str(self):
print(self.my_playlist.str())
示例11: TestPlaylist
# 需要导入模块: from playlist import Playlist [as 别名]
# 或者: from playlist.Playlist import remove_disrated [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())
示例12: main
# 需要导入模块: from playlist import Playlist [as 别名]
# 或者: from playlist.Playlist import remove_disrated [as 别名]
def main():
#new_songs_arr = []
print(start_message())
print(songs_to_add())
new_playlist = Playlist("my_playlist")
while True:
command = split_command_str(input("Enter command>"))
if the_command(command, "generate"):
new_crawler = Music_crawler(command[1])
new_playlist = new_crawler.generate_playlist()
print(new_playlist.str_func())
elif the_command(command, "remove_disrated"):
new_playlist.remove_disrated(int(command[1]))
print(new_playlist.str_func())
elif the_command(command, "remove_bad_quality"):
new_playlist.remove_bad_quality()
print(new_playlist.str_func())
elif the_command(command, "remove"):
new_playlist.remove_song(command[1])
print(new_playlist.str_func())
elif the_command(command, "add"):
for song in songs_arr:
if command[1] == song.title:
new_playlist.add_song(song)
break
print(new_playlist.str_func())
elif the_command(command, "load"):
new_playlist.load(command[1])
print(new_playlist.str_func())
elif the_command(command, "save"):
new_playlist.save(command[1])
elif the_command(command, "finish"):
print("GoodBye. Thank you for using the player")
break
else:
print(unknown_command())
示例13: PlaylistTests
# 需要导入模块: from playlist import Playlist [as 别名]
# 或者: from playlist.Playlist import remove_disrated [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)
示例14: TestPlaylist
# 需要导入模块: from playlist import Playlist [as 别名]
# 或者: from playlist.Playlist import remove_disrated [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)
示例15: SongTest
# 需要导入模块: from playlist import Playlist [as 别名]
# 或者: from playlist.Playlist import remove_disrated [as 别名]
class SongTest(unittest.TestCase):
def setUp(self):
self.song = song.Song("Emerald Sword", "Rhapsody", "Fire", 4, 2400, 192)
self.song2 = song.Song("Highway To Hell", "AC/DC", "Rough And Tough", 3, 2000, 64)
self.my_playlist = Playlist("my_playlist")
self.my_playlist.add_song(self.song)
self.my_playlist.add_song(self.song2)
def test_init(self):
self.assertEqual(self.my_playlist.songs, [self.song, self.song2])
self.assertEqual(self.my_playlist.name, "my_playlist")
def test_add(self):
self.assertEqual([self.song, self.song2], self.my_playlist.songs)
def test_remove(self):
self.my_playlist.remove_song(self.song)
self.assertEqual(self.my_playlist.songs, [self.song2])
def test_length(self):
self.assertEqual(self.my_playlist.total_length(), 4400)
def test_remove_disrated(self):
self.my_playlist.remove_disrated(3)
self.assertEqual(self.my_playlist.songs, [self.song])
def test_remove_bad_quality(self):
self.my_playlist.remove_bad_quality()
self.assertEqual(self.my_playlist.songs, [self.song])
def test_show_artists(self):
self.assertEqual(self.my_playlist.show_artists(), ["Rhapsody", "AC/DC"])
def test_str(self):
self.my_playlist.remove_song(self.song2)
self.assertEqual(self.my_playlist.str(), ["Rhapsody Emerald Sword 2400"])