当前位置: 首页>>代码示例>>Python>>正文


Python Song.rate方法代码示例

本文整理汇总了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)
开发者ID:stoilov,项目名称:Programming101,代码行数:29,代码来源:song_test.py

示例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)
开发者ID:antonpetkoff,项目名称:Programming101,代码行数:27,代码来源:song_test.py

示例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)
开发者ID:Legena,项目名称:HackBulgaria,代码行数:28,代码来源:song_tests.py

示例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))
开发者ID:dsspasov,项目名称:HackBulgaria,代码行数:12,代码来源:song_test.py

示例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)
开发者ID:smilen4eto,项目名称:Music-Library,代码行数:18,代码来源:song_test.py

示例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)
开发者ID:VictorVangelov,项目名称:HackBulgaria,代码行数:18,代码来源:test_song.py

示例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
开发者ID:kkashev,项目名称:hackbulgaria,代码行数:19,代码来源:playlist.py

示例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)
开发者ID:kkashev,项目名称:hackbulgaria,代码行数:20,代码来源:test_song.py

示例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)
开发者ID:modzozo,项目名称:hack101,代码行数:20,代码来源:songtest.py

示例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)
开发者ID:kal0ian,项目名称:HackBulgaria,代码行数:20,代码来源:song-test.py

示例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)
开发者ID:skdls-,项目名称:Python,代码行数:20,代码来源:test_song.py

示例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)
开发者ID:betrakiss,项目名称:HackBulgaria,代码行数:21,代码来源:song_test.py

示例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)
开发者ID:nkgeorgiev,项目名称:HackBulgaria---Programming101---2,代码行数:22,代码来源:song_test.py

示例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)
开发者ID:GalinaDimitrova,项目名称:Hack,代码行数:22,代码来源:song_test.py

示例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())
开发者ID:maieutiquer,项目名称:music-library,代码行数:22,代码来源:test_song.py


注:本文中的song.Song.rate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。