本文整理汇总了Python中song.Song.rate方法的典型用法代码示例。如果您正苦于以下问题:Python Song.rate方法的具体用法?Python Song.rate怎么用?Python Song.rate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类song.Song
的用法示例。
在下文中一共展示了Song.rate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestSong
# 需要导入模块: from song import Song [as 别名]
# 或者: from song.Song import rate [as 别名]
class TestSong(unittest.TestCase):
def setUp(self):
self.song = Song(
"Whole Lotta Love",
"Led Zeppelin",
"Led Zeppelin II",
5,
334,
320000
)
def test_song_init(self):
self.assertEqual(self.song.title, "Whole Lotta Love")
self.assertEqual(self.song.artist, "Led Zeppelin")
self.assertEqual(self.song.album, "Led Zeppelin II")
self.assertEqual(self.song.rating, 5)
self.assertEqual(self.song.length, 334)
self.assertEqual(self.song.bitrate, 320000)
def test_rate(self):
self.song.rate(4)
self.assertEqual(self.song.rating, 4)
def test_rate_error(self):
with self.assertRaises(ValueError):
self.song.rate(200000)
示例2: SongTests
# 需要导入模块: from song import Song [as 别名]
# 或者: from song.Song import rate [as 别名]
class SongTests(unittest.TestCase):
def setUp(self):
self.song = Song("The Jack", "ACDC", "T.N.T.", 4, 240, 320)
def test_init(self):
song = Song("The Jack", "ACDC", "T.N.T.", 4, 240, 320)
self.assertEqual(song.title, "The Jack")
self.assertEqual(song.artist, "ACDC")
self.assertEqual(song.album, "T.N.T.")
self.assertEqual(song.rating, 4)
self.assertEqual(song.length, 240)
self.assertEqual(song.bitrate, 320)
def test_rate_value_error(self):
with self.assertRaises(ValueError):
self.song.rate(6)
def test_rate_success(self):
self.song.rate(3)
self.assertEqual(self.song.rating, 3)
def test_str(self):
expected = "ACDC The Jack - 0:04:00"
self.assertEqual(str(self.song), expected)
示例3: SongTests
# 需要导入模块: from song import Song [as 别名]
# 或者: from song.Song import rate [as 别名]
class SongTests(unittest.TestCase):
def setUp(self):
self.test_song = Song(
"Hells Bells",
"ACDC",
"Back in Black",
5,
312,
320
)
def test_song_init(self):
self.assertEqual(self.test_song.title, "Hells Bells")
self.assertEqual(self.test_song.artist, "ACDC")
self.assertEqual(self.test_song.album, "Back in Black")
self.assertEqual(self.test_song.rating, 5)
self.assertEqual(self.test_song.length, 312)
self.assertEqual(self.test_song.bitrate, 320)
def test_song_rate(self):
self.test_song.rate(3)
self.assertEqual(self.test_song.rating, 3)
def test_song_rate_out_of_range(self):
with self.assertRaises(ValueError):
self.test_song.rate(8)
示例4: TestSong
# 需要导入模块: from song import Song [as 别名]
# 或者: from song.Song import rate [as 别名]
class TestSong(unittest.TestCase):
def setUp(self):
self.song = Song("Sweet Child O'mine", "Guns N' Roses", "Appetite for Destruction", 5, 356, 320 )
def test_rate_0(self):
self.song.rate(5)
self.assertEqual(5,self.song.rating)
def test_rate_error(self):
self.assertRaises(ValueError, lambda:self.song.rate(6))
示例5: TestSong
# 需要导入模块: from song import Song [as 别名]
# 或者: from song.Song import rate [as 别名]
class TestSong(unittest.TestCase):
def setUp(self):
self.new_song = Song("Wonderland", "Sunrise Avenue", "On the way to wonderland", 5, 220, 455)
def test_song_init(self):
self.assertEqual("Wonderland", self.new_song.title)
self.assertEqual("Sunrise Avenue", self.new_song.artist)
self.assertEqual("On the way to wonderland", self.new_song.album)
self.assertEqual(5, self.new_song.rating)
self.assertEqual(220, self.new_song.length)
self.assertEqual(455, self.new_song.bitrate)
def test_rate(self):
with self.assertRaises(ValueError):
self.new_song.rate(20)
示例6: TestSong
# 需要导入模块: from song import Song [as 别名]
# 或者: from song.Song import rate [as 别名]
class TestSong(unittest.TestCase):
def setUp(self):
self.some_song = Song("title", "artist", "album", 0, 333, 32)
def test_init(self):
self.assertEqual("title", self.some_song.title)
self.assertEqual("artist", self.some_song.artist)
self.assertEqual("album", self.some_song.album)
self.assertEqual(0, self.some_song.rating)
self.assertEqual(333, self.some_song.length)
self.assertEqual(32, self.some_song.bitrate)
def test_rate(self):
self.some_song.rate(6)
self.assertEqual(self.some_song.rating, 5)
示例7: load
# 需要导入模块: from song import Song [as 别名]
# 或者: from song.Song import rate [as 别名]
def load():
file_name = "data.txt"
file_read = open(file_name)
json_temp = json.load(file_read)
playlist1 = Playlist(json_temp['name'])
for song in json_temp["songs"]:
title = song['title']
artist = song['artist']
rating = song['rating']
bitrate = song['bitrate']
album = song['album']
length = song['length']
song1 = Song(title, artist, album, length, bitrate)
if rating is not None:
song1.rate(rating)
playlist1.add_song(song1)
return playlist1
示例8: TestSong
# 需要导入模块: from song import Song [as 别名]
# 或者: from song.Song import rate [as 别名]
class TestSong(unittest.TestCase):
def setUp(self):
self.test_song = Song("Take me", "AC DC", "Black in black", 4, 180, 320)
def test_init_song(self):
self.assertEqual(self.test_song.title, "Take me")
self.assertEqual(self.test_song.artist, "AC DC")
self.assertEqual(self.test_song.album, "Black in black")
self.assertEqual(self.test_song.length, 180)
self.assertEqual(self.test_song.bitrate, 320)
def test_rate(self):
self.test_song.rate(4)
self.assertEqual(self.test_song.rating, 4)
def test_rating_out_of_range(self):
with self.assertRaises(ValueError):
self.test_song.rate(200)
示例9: SongTest
# 需要导入模块: from song import Song [as 别名]
# 或者: from song.Song import rate [as 别名]
class SongTest(unittest.TestCase):
def setUp(self):
self.song = Song("Shelter", "Years & Years","EP",4,"04:00",128)
def test_init(self):
self.assertEqual(self.song.title, "Shelter")
self.assertEqual(self.song.artist, "Years & Years")
self.assertEqual(self.song.album,"EP")
self.assertEqual(self.song.rating,4)
self.assertEqual(self.song.length,"04:00")
self.assertEqual(self.song.bitrate,128)
def test_rate_outofvalue(self):
self.song.rate(4)
self.assertEqual(self.song.rating, 4)
with self.assertRaises(ValueError):
self.song.rate(6)
示例10: SongTest
# 需要导入模块: from song import Song [as 别名]
# 或者: from song.Song import rate [as 别名]
class SongTest(unittest.TestCase):
def setUp(self):
self.song = Song("Title", "Artist", "Album", 2, 3.82, 64)
def test_init(self):
self.assertEqual(self.song.title, "Title")
self.assertEqual(self.song.artist, "Artist")
self.assertEqual(self.song.album, "Album")
self.assertEqual(self.song.rating, 2)
self.assertEqual(self.song.length, 3.82)
self.assertEqual(self.song.bitrate, 64)
def test_rate(self):
self.song.rate(2)
self.assertEqual(self.song.rating, 2)
with self.assertRaises(ValueError):
self.song.rate(self)
示例11: TestSong
# 需要导入模块: from song import Song [as 别名]
# 或者: from song.Song import rate [as 别名]
class TestSong(unittest.TestCase):
def setUp(self):
self.song = Song("Title", "Artist","Album", 5.0, 4.22, 320)
def test_init(self):
self.assertEqual(self.song.title, "Title")
self.assertEqual(self.song.artist, "Artist")
self.assertEqual(self.song.album, "Album")
self.assertEqual(self.song.rating, 5.0)
self.assertEqual(self.song.length, 4.22)
self.assertEqual(self.song.bitrate, 320)
def test_rate(self):
self.song.rate(4)
self.assertEqual(self.song.rating, 4)
with self.assertRaises(ValueError):
self.song.rate(6)
示例12: TestSong
# 需要导入模块: from song import Song [as 别名]
# 或者: from song.Song import rate [as 别名]
class TestSong(unittest.TestCase):
def setUp(self):
self.test_song = Song("BeatBox", "PsychoFrog", "BB 2015", 4, 190, 320)
def test_init(self):
self.assertEqual("BeatBox", self.test_song.title)
self.assertEqual("PsychoFrog", self.test_song.artist)
self.assertEqual("BB 2015", self.test_song.album)
self.assertEqual(4, self.test_song.rating)
self.assertEqual(190, self.test_song.length)
self.assertEqual(320, self.test_song.bitrate)
def test_rate_invalid_value(self):
with self.assertRaises(ValueError):
self.test_song.rate(10)
def test_rate_with_valid_value(self):
self.test_song.rate(4)
self.assertEqual(4, self.test_song.rating)
示例13: TestSong
# 需要导入模块: from song import Song [as 别名]
# 或者: from song.Song import rate [as 别名]
class TestSong(unittest.TestCase):
def setUp(self):
self.test_song = Song("Highway to Hell", "AC/DC", "Highway to Hell", 5, 208, 256, "asa")
def test_song_init(self):
self.assertEqual("Highway to Hell", self.test_song.title)
self.assertEqual("AC/DC", self.test_song.artist)
self.assertEqual("Highway to Hell", self.test_song.album)
self.assertEqual(5, self.test_song.rating)
self.assertEqual(208, self.test_song.length)
self.assertEqual(256, self.test_song.bitrate)
self.assertEqual("asa", self.test_song.path)
def test_song_rate_raise_error(self):
with self.assertRaises(ValueError):
self.test_song.rate(10)
def test_song_rate(self):
self.test_song.rate(3)
self.assertEqual(3, self.test_song.rating)
示例14: SongTest
# 需要导入模块: from song import Song [as 别名]
# 或者: from song.Song import rate [as 别名]
class SongTest(unittest.TestCase):
def setUp(self):
self.song = Song(
"Desert rose", "Sting", "Brand New Day", 0.0, "4:45", 8)
def test_init(self):
self.assertEqual(self.song.title, "Desert rose")
self.assertEqual(self.song.artist, "Sting")
self.assertEqual(self.song.album, "Brand New Day")
self.assertEqual(self.song.rating, 0.0)
self.assertEqual(self.song.length, "4:45")
self.assertEqual(self.song.bitrate, 8)
def test_rate(self):
self.song.rate(4)
self.assertEqual(self.song.rating, 4.0)
def test_rong_rate(self):
self.assertRaises(ValueError, self.song.rate, 6)
示例15: TestSong
# 需要导入模块: from song import Song [as 别名]
# 或者: from song.Song import rate [as 别名]
class TestSong(unittest.TestCase):
def setUp(self):
self.song = Song(
"Skinny Love",
"Birdy",
"Birdy",
5,
190,
320,
)
def test_get_rating(self):
self.assertEqual(5, self.song.get_rating())
def test_rate(self):
self.song.rate(3)
self.assertEqual(4, self.song.get_rating())
self.song.rate(1)
self.assertEqual(3, self.song.get_rating())