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


Python Playlist.to_string方法代码示例

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


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

示例1: TestPlaylist

# 需要导入模块: from playlist import Playlist [as 别名]
# 或者: from playlist.Playlist import to_string [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)
开发者ID:IvanAlexandrov,项目名称:HackBulgaria-Tasks,代码行数:95,代码来源:test_playlist.py


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