本文整理汇总了Python中song.Song.set_rating方法的典型用法代码示例。如果您正苦于以下问题:Python Song.set_rating方法的具体用法?Python Song.set_rating怎么用?Python Song.set_rating使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类song.Song
的用法示例。
在下文中一共展示了Song.set_rating方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestSong
# 需要导入模块: from song import Song [as 别名]
# 或者: from song.Song import set_rating [as 别名]
class TestSong(unittest.TestCase):
def setUp(self):
self.test_song = Song(
'Hells Bells',
'AC/DC',
'rough and though',
5,
520,
256)
def test_song_init(self):
self.assertEqual(self.test_song.title, 'Hells Bells')
self.assertEqual(self.test_song.artist, 'AC/DC')
self.assertEqual(self.test_song.album, 'rough and though')
self.assertEqual(self.test_song.rating, 5)
self.assertEqual(self.test_song.lenght, 520)
self.assertEqual(self.test_song.bitrate, 256)
def test_rating(self):
self.test_song.set_rating(4)
self.assertEqual(self.test_song.rating, 4)
def test_rating_out_of_range(self):
with self.assertRaises(ValueError):
self.test_song.set_rating(8)
示例2: test_compare_tracks_by_rating
# 需要导入模块: from song import Song [as 别名]
# 或者: from song.Song import set_rating [as 别名]
def test_compare_tracks_by_rating(self):
song2 = Song("../test.mp3")
song2.set_artist("artist2")
song2.set_title("title2")
song2.set_genre("genre2")
song2.set_album("album2")
song2.set_year("2014")
song2.set_track("11")
song2.set_rating("1")
self.assertTrue(song2 < self.song)
self.assertFalse(song2 > self.song)
self.assertFalse(song2 >= self.song)
self.assertFalse(song2 == self.song)
self.assertTrue(song2 <= self.song)
self.assertTrue(song2 != self.song)
示例3: TestSong
# 需要导入模块: from song import Song [as 别名]
# 或者: from song.Song import set_rating [as 别名]
class TestSong(unittest.TestCase):
"""Tests for song objects"""
def setUp(self):
self.song = Song("../test.mp3")
self.song.set_artist("artist")
self.song.set_title("title")
self.song.set_genre("genre")
self.song.set_album("album")
self.song.set_year("2014")
self.song.set_track("10")
self.song.set_rating("5")
def tearDown(self):
self.song.set_artist("artist")
self.song.set_title("title")
self.song.set_genre("genre")
self.song.set_album("album")
self.song.set_year("2014")
self.song.set_track("10")
self.song.set_rating("5")
def test_get_artist(self):
self.assertEqual("artist", self.song.get_artist())
def test_get_title(self):
self.assertEqual("title", self.song.get_title())
def test_get_genre(self):
self.assertEqual("genre", self.song.get_genre())
def test_get_album(self):
self.assertEqual("album", self.song.get_album())
def test_get_year(self):
self.assertEqual("2014", self.song.get_year())
def test_get_track(self):
self.assertEqual("10", self.song.get_track())
def test_get_rating(self):
self.assertEqual("5", self.song.get_rating())
def test_set_rating_bigger_than_allowed(self):
self.song.set_rating("100")
self.assertEqual("5", self.song.get_rating())
def test_set_rating_smaller_than_allowed(self):
self.song.set_rating("-123")
self.assertEqual("5", self.song.get_rating())
def test_set_valid_rating(self):
self.song.set_rating("2")
self.assertEqual("2", self.song.get_rating())
def test_set_artist(self):
self.song.set_artist("new_artist")
self.assertEqual("new_artist", self.song.get_artist())
def test_set_title(self):
self.song.set_title("new_title")
self.assertEqual("new_title", self.song.get_title())
def test_set_genre(self):
self.song.set_genre("new_genre")
self.assertEqual("new_genre", self.song.get_genre())
def test_set_album(self):
self.song.set_album("new_album")
self.assertEqual("new_album", self.song.get_album())
def test_set_valid_year(self):
self.song.set_year("2005")
self.assertEqual("2005", self.song.get_year())
def test_set_invalid_year(self):
self.song.set_year("20000")
self.assertEqual("2014", self.song.get_year())
self.song.set_year("10")
self.assertEqual("2014", self.song.get_year())
self.song.set_year("-123")
self.assertEqual("2014", self.song.get_year())
self.song.set_year("asda")
self.assertEqual("2014", self.song.get_year())
def test_set_valid_track(self):
self.song.set_track("2")
self.assertEqual("2", self.song.get_track())
def test_set_invalid_track(self):
self.song.set_track("asd")
self.assertEqual("10", self.song.get_track())
self.song.set_track("-1")
self.assertEqual("10", self.song.get_track())
def test_compare_tracks_by_rating(self):
#.........这里部分代码省略.........
示例4: TestPlaylist
# 需要导入模块: from song import Song [as 别名]
# 或者: from song.Song import set_rating [as 别名]
class TestPlaylist(unittest.TestCase):
def setUp(self):
self.playlist = Playlist('my_playlist')
self.untitled = Playlist()
self.song_1 = Song(
'Hells Bells',
'AC/DC',
'rough and though',
4,
400,
256)
self.song_2 = Song(
'For Whom the Bell Tolls',
'Metallica',
'For Whom the Bell Tolls',
5,
500,
320)
def test_playlist_init(self):
self.assertEqual(self.playlist.name, 'my_playlist')
self.assertEqual(self.untitled.name, 'Untitled')
def test_add_song(self):
self.playlist.add_song(self.song_1)
self.playlist.add_song(self.song_2)
def test_remove_song(self):
self.playlist.add_song(self.song_1)
self.playlist.add_song(self.song_1)
self.playlist.add_song(self.song_1)
self.playlist.add_song(self.song_2)
self.playlist.remove_song('Hells Bells')
self.assertEqual(len(self.playlist.songs), 1)
def test_total_length(self):
self.playlist.add_song(self.song_1)
self.playlist.add_song(self.song_1)
self.playlist.add_song(self.song_1)
self.playlist.add_song(self.song_1)
self.playlist.add_song(self.song_2)
self.assertEqual(self.playlist.total_length(), 2100)
def test_remove_disrated(self):
self.song_1.set_rating(3)
self.playlist.add_song(self.song_1)
self.playlist.add_song(self.song_1)
self.playlist.add_song(self.song_1)
self.playlist.add_song(self.song_1)
self.playlist.add_song(self.song_2)
self.playlist.remove_disrated(4)
self.assertEqual(len(self.playlist.songs), 1)
def test_remove_bad_quality(self):
self.song_1.bitrate = 92
self.playlist.add_song(self.song_1)
self.playlist.add_song(self.song_1)
self.playlist.add_song(self.song_1)
self.playlist.add_song(self.song_1)
self.playlist.add_song(self.song_2)
self.playlist.remove_bad_quality()
self.assertEqual(len(self.playlist.songs), 1)
def test_show_artists(self):
self.playlist.add_song(self.song_1)
self.playlist.add_song(self.song_1)
self.playlist.add_song(self.song_1)
self.playlist.add_song(self.song_1)
self.playlist.add_song(self.song_2)
# print(self.playlist.show_artists())
def test_to_string(self):
self.playlist.add_song(self.song_1)
self.playlist.add_song(self.song_2)
self.playlist.add_song(self.song_1)
self.playlist.add_song(self.song_2)
self.playlist.add_song(self.song_1)
self.playlist.add_song(self.song_2)
print(self.playlist.to_string())
def test_save(self):
# pass
self.playlist.add_song(self.song_2)
self.playlist.add_song(self.song_1)
self.playlist.add_song(self.song_2)
self.playlist.save('playlist.json')
def test_load(self):
# pass
plst = Playlist.load('playlist.json')
print(plst.to_string)