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


Python Playlist.__str__方法代码示例

本文整理汇总了Python中playlist.Playlist.__str__方法的典型用法代码示例。如果您正苦于以下问题:Python Playlist.__str__方法的具体用法?Python Playlist.__str__怎么用?Python Playlist.__str__使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在playlist.Playlist的用法示例。


在下文中一共展示了Playlist.__str__方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: TestPlaylist

# 需要导入模块: from playlist import Playlist [as 别名]
# 或者: from playlist.Playlist import __str__ [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))
开发者ID:kkashev,项目名称:hackbulgaria,代码行数:55,代码来源:test_playlist_class.py

示例2: TestPlaylist

# 需要导入模块: from playlist import Playlist [as 别名]
# 或者: from playlist.Playlist import __str__ [as 别名]

#.........这里部分代码省略.........
        self.assertEqual(songs_with_this_rate, 0)

    def test_remove_disrated_more_than_one(self):
        rating = 4
        song = Song(
            "Whole Lotta Love",
            "Led Zeppelin",
            "Led Zeppelin II",
            3,
            334,
            320000
        )
        self.playlist.add_song(song)
        self.playlist.add_song(song)
        self.playlist.add_song(song)
        self.playlist.remove_disrated(rating)
        songs_with_this_rate = 0
        for song in self.playlist.songs:
            if song.rating < rating:
                songs_with_this_rate += 1
        self.assertEqual(songs_with_this_rate, 0)


    def test_remove_bad_quality(self):
        song = Song(
            "Whole Lotta Love",
            "Led Zeppelin",
            "Led Zeppelin II",
            3,
            334,
            240000
        )
        self.playlist.add_song(song)
        self.playlist.remove_bad_quality()
        songs_with_this_rate = 0
        for song in self.playlist.songs:
            if song.bitrate < 320000:
                songs_with_this_rate += 1
        self.assertEqual(songs_with_this_rate, 0)

    def test_remove_bad_quality_more_than_one(self):
        song = Song(
            "Whole Lotta Love",
            "Led Zeppelin",
            "Led Zeppelin II",
            3,
            334,
            240000
        )
        self.playlist.add_song(song)
        self.playlist.add_song(song)
        self.playlist.add_song(song)
        self.playlist.remove_bad_quality()
        songs_with_this_rate = 0
        for song in self.playlist.songs:
            if song.bitrate < 320000:
                songs_with_this_rate += 1
        self.assertEqual(songs_with_this_rate, 0)

    def test_show_artists(self):
        song = Song(
            "Whole Lotta Love",
            "Led Zeppelin",
            "Led Zeppelin II",
            5,
            334,
            320000
        )
        self.playlist.add_song(song)
        self.playlist.add_song(song)
        self.playlist.add_song(song)
        artists = self.playlist.show_artists()
        self.assertSetEqual(artists, {"Led Zeppelin"})

    def test_playlist_str(self):
        song = Song(
            "Whole Lotta Love",
            "Led Zeppelin",
            "Led Zeppelin II",
            5,
            334,
            320000
        )
        self.playlist.add_song(song)
        string_repr = self.playlist.__str__()
        self.assertEqual(string_repr, "Led Zeppelin Whole Lotta Love - 5:34")

    def test_playlist_str_more_songs(self):
        song = Song(
            "Whole Lotta Love",
            "Led Zeppelin",
            "Led Zeppelin II",
            5,
            334,
            320000
        )
        self.playlist.add_song(song)
        self.playlist.add_song(song)
        string_repr = self.playlist.__str__()
        self.assertEqual(string_repr, "Led Zeppelin Whole Lotta Love - 5:34\nLed Zeppelin Whole Lotta Love - 5:34")
开发者ID:stoilov,项目名称:Programming101,代码行数:104,代码来源:playlist_test.py


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