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


Python Playlist.str方法代码示例

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


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

示例1: Tests

# 需要导入模块: from playlist import Playlist [as 别名]
# 或者: from playlist.Playlist import str [as 别名]
class Tests(unittest.TestCase):
	def setUp(self):
		self.playlist = Playlist('PlayList')
		self.song = Song('title', 'artist', 'album', 5, 93, 256)

	def test_song_init(self):
		self.assertEqual(self.playlist.name, 'PlayList')

	def test_add_song(self):
		self.playlist.add_song(self.song)
		self.assertEqual(self.playlist.playlist[0],self.song)

	def test_remove_song(self):
		self.playlist.remove_song('title')
		self.assertEqual(len(self.playlist.playlist), 0)

	def test_total_length(self):
		song1 = Song('title1', 'artist1', 'album1', 5, 93, 256)
		song2 = Song('title2', 'artist2', 'album2', 3, 87, 126)
		self.playlist.add_song(song1)
		self.playlist.add_song(song2)
		self.assertEqual(self.playlist.total_length(),180)

	def test_remove_disrated(self):
		song1 = Song('title1', 'artist1', 'album1', 5, 93, 256)
		song2 = Song('title2', 'artist2', 'album2', 3, 87, 126)
		song3 = Song('title3', 'artist3', 'album3', 5, 88, 148)
		self.playlist.add_song(song1)
		self.playlist.add_song(song2)
		self.playlist.add_song(song3)
		self.playlist.remove_disrated(3)
		self.assertEqual(self.playlist.total_length(),181)

	def test_remove_bad_quality(self):
		song1 = Song('title1', 'artist1', 'album1', 5, 93, 256)
		song2 = Song('title2', 'artist2', 'album2', 3, 87, 126)
		song3 = Song('title3', 'artist3', 'album3', 5, 88, 148)
		self.playlist.add_song(song1)
		self.playlist.add_song(song2)
		self.playlist.add_song(song3)
		self.playlist.remove_bad_quality(126)
		self.assertEqual(self.playlist.total_length(),181)

	def test_show_artists(self):
		song1 = Song('title1', 'artist1', 'album1', 5, 93, 256)
		song2 = Song('title2', 'artist2', 'album2', 3, 87, 126)
		song3 = Song('title3', 'artist2', 'album3', 5, 88, 148)
		self.playlist.add_song(song1)
		self.playlist.add_song(song2)
		self.playlist.add_song(song3)
		artists = ['artist1','artist2']
		self.assertEqual(artists,self.playlist.show_artists())

	def test_str(self):
		song1 = Song('title1', 'artist1', 'album1', 5, 93, 256)
		song2 = Song('title2', 'artist2', 'album2', 3, 87, 126)
		self.playlist.add_song(song1)
		self.playlist.add_song(song2)
		songs = 'artist1 title1 - 1:33\nartist2 title2 - 1:27\n'
		self.assertEqual(songs,self.playlist.str())
开发者ID:kalpak44,项目名称:Program101,代码行数:62,代码来源:test_playlist.py

示例2: TestPlaylist

# 需要导入模块: from playlist import Playlist [as 别名]
# 或者: from playlist.Playlist import str [as 别名]
class TestPlaylist(unittest.TestCase):

    def setUp(self):

        self.song1 = Song("Title1", "Artist","Album", 5.0, 4, 320)
        self.song2 = Song("Title2", "Artist","Album", 2.0, 2, 320)
        self.song3 = Song("Title3", "Artist2","Album", 5.0, 4, 128)
        self.my_playlist = Playlist("Playlist")
        self.my_playlist.songs.append(self.song1)
        self.my_playlist.songs.append(self.song2)
        self.my_playlist.songs.append(self.song3)

    def test_init(self):

        self.assertEqual(self.my_playlist.songs, [self.song1, self.song2, self.song3])
        self.assertEqual(self.my_playlist.name, "Playlist")

    def test_add_song(self):

        self.song4 = Song("Title", "Artist","Album", 5.0, 4.22, 320)
        self.my_playlist.add_song(self.song4)
        self.assertEqual(self.my_playlist.songs, [self.song1, self.song2, self.song3, self.song4])

    def test_remove_song(self):

        self.my_playlist.remove_song("Title2")
        self.assertEqual(self.my_playlist.songs, [self.song1, self.song3])

    def test_total_lenght(self):

        self.assertEqual(self.my_playlist.total_lenght(), 10)

    def test_remove_disrated(self):

        self.my_playlist.remove_disrated(3)
        self.assertEqual(self.my_playlist.songs, [self.song1, self.song3])

    def test_remove_bad_quality(self):

        self.my_playlist.remove_bad_quality(320)
        self.assertEqual(self.my_playlist.songs, [self.song1, self.song2])

    def test_show_artists(self):

        self.assertEqual(self.my_playlist.show_artits(), ["Artist", "Artist2"])

    def test_str(self):

        print(self.my_playlist.str()) 
开发者ID:skdls-,项目名称:Python,代码行数:51,代码来源:test_playlist.py

示例3: SongTest

# 需要导入模块: from playlist import Playlist [as 别名]
# 或者: from playlist.Playlist import str [as 别名]
class SongTest(unittest.TestCase):
    def setUp(self):
        self.song = song.Song("Emerald Sword", "Rhapsody", "Fire", 4, 2400, 192)
        self.song2 = song.Song("Highway To Hell", "AC/DC", "Rough And Tough", 3, 2000, 64)
        self.my_playlist = Playlist("my_playlist")
        self.my_playlist.add_song(self.song)
        self.my_playlist.add_song(self.song2)

    def test_init(self):
        self.assertEqual(self.my_playlist.songs, [self.song, self.song2])
        self.assertEqual(self.my_playlist.name, "my_playlist")

    def test_add(self):
        self.assertEqual([self.song, self.song2], self.my_playlist.songs)

    def test_remove(self):
        self.my_playlist.remove_song(self.song)
        self.assertEqual(self.my_playlist.songs, [self.song2])

    def test_length(self):
        self.assertEqual(self.my_playlist.total_length(), 4400)

    def test_remove_disrated(self):
        self.my_playlist.remove_disrated(3)
        self.assertEqual(self.my_playlist.songs, [self.song])

    def test_remove_bad_quality(self):
        self.my_playlist.remove_bad_quality()
        self.assertEqual(self.my_playlist.songs, [self.song])

    def test_show_artists(self):
        self.assertEqual(self.my_playlist.show_artists(), ["Rhapsody", "AC/DC"])

    def test_str(self):
        self.my_playlist.remove_song(self.song2)
        self.assertEqual(self.my_playlist.str(), ["Rhapsody Emerald Sword 2400"])
开发者ID:georgi-lyubenov,项目名称:HackBulgaria,代码行数:38,代码来源:playlist_test.py

示例4: PlaylistTests

# 需要导入模块: from playlist import Playlist [as 别名]
# 或者: from playlist.Playlist import str [as 别名]
class PlaylistTests(unittest.TestCase):

    def setUp(self):
        self.playlist = Playlist("The Named Playlist")
        self.song1 = Song("Loosing My Insanity", "DIO", "Magica", 5, 333, 256)
        self.song2 = Song("Last In Line", "DIO", "Last In Line", 4, 222, 191)
        file = open("test_file", "w")
        file.close()

    def test_init(self):
        self.assertEqual("The Named Playlist", self.playlist.name)
        self.assertEqual([], self.playlist.collection)

    def test_add_song(self):
        self.assertTrue(self.playlist.add_song(self.song1))

    def test_add_song_value_error(self):
        with self.assertRaises(ValueError):
            self.playlist.add_song("tomatoe")

    def test_remove_song(self):
        self.playlist.add_song(self.song1)
        self.playlist.add_song(self.song2)
        self.playlist.remove_song("Last In Line")
        lst = deepcopy(self.playlist.collection)
        lst = list(map(lambda x: x.title, lst))
        self.assertEqual(0, lst.count("Last In Line"))

    def test_total_length(self):
        self.playlist.add_song(self.song1)
        self.playlist.add_song(self.song2)
        self.assertEqual(555, self.playlist.total_length())

    def test_total_length_empty_collection(self):
        self.assertEqual(0, self.playlist.total_length())

    def test_remove_disrated(self):
        self.playlist.add_song(self.song1)
        self.playlist.add_song(self.song2)
        self.playlist.remove_disrated(5)
        lst = deepcopy(self.playlist.collection)
        lst = list(map(lambda x: x.rating, lst))
        self.assertEqual(0, lst.count(4))

    def test_remove_disrated_value_error(self):
        with self.assertRaises(ValueError):
            self.playlist.remove_disrated(8)

    def test_remove_bad_quality(self):
        self.playlist.add_song(self.song1)
        self.playlist.add_song(self.song2)
        self.playlist.remove_bad_quality()
        lst = deepcopy(self.playlist.collection)
        lst = list(map(lambda x: x.bitrate, lst))
        self.assertEqual(0, lst.count(191))

    def test_show_artists(self):
        self.playlist.add_song(self.song1)
        self.playlist.add_song(self.song2)
        self.assertEqual(["DIO"], self.playlist.show_artists())

    def test_show_artists_empty_collection(self):
        self.assertEqual([], self.playlist.show_artists())

    def test_str(self):
        self.playlist.add_song(self.song1)
        self.playlist.add_song(self.song2)
        self.assertEqual("DIO Loosing My Insanity - 05:33\n" +
                         "DIO Last In Line - 03:42\n", self.playlist.str())

    # I'm not sure how to test them separately
    def test_save_and_load(self):
        self.playlist.add_song(self.song1)
        self.playlist.add_song(self.song2)
        self.playlist.save("test_file")
        self.assertEqual(self.playlist.str(), Playlist.load("test_file").str())

    def tearDown(self):
        remove("test_file")
开发者ID:Fusl,项目名称:Hack-Bulgaria-Programming-101,代码行数:81,代码来源:playlist_test.py

示例5: TestPlayslist

# 需要导入模块: from playlist import Playlist [as 别名]
# 或者: from playlist.Playlist import str [as 别名]
class TestPlayslist(unittest.TestCase):

    def setUp(self):
        self.test_playlist = Playlist("My playlist")
        self.test_song = Song("Wonderland", "Sunrise Avenue", "On the way to wonderland", 5, 220, 255)

    def test_playlist_init(self):
        self.assertEqual("My playlist", self.test_playlist.name)

    def test_playlist_add_song(self):
        self.test_playlist.add_song(self.test_song)
        test_song2 = Song("Bla bla", "bla", "blaa", 1, 240, 412)
        test_song3 = Song("lala", "la", "laa", 2, 210, 478)
        self.test_playlist.add_song(test_song2)
        self.test_playlist.add_song(test_song3)
        self.assertIn(self.test_song, self.test_playlist.songs)
        self.assertIn(test_song2, self.test_playlist.songs)
        self.assertIn(test_song3, self.test_playlist.songs)

    def test_playlist_remove_song(self):
        test_song2 = Song("Bla bla", "bla", "blaa", 1, 240, 412)
        self.test_playlist.add_song(self.test_song)
        self.test_playlist.add_song(test_song2)
        self.test_playlist.remove_song("Wonderland")
        self.assertNotIn(self.test_song, self.test_playlist.songs)
        self.assertIn(test_song2, self.test_playlist.songs)

    def test_total_length(self):
        test_song2 = Song("Bla bla", "bla", "blaa", 3, 240, 412)
        test_song3 = Song("lala", "la", "laa", 4, 210, 478)
        self.test_playlist.add_song(self.test_song)
        self.test_playlist.add_song(test_song2)
        self.test_playlist.add_song(test_song3)
        self.assertEqual(self.test_playlist.total_length(), 670)

    def test_remove_disrated(self):
        test_song2 = Song("Bla bla", "bla", "blaa", 1, 240, 412)
        test_song3 = Song("lala", "la", "laa", 2, 210, 478)
        self.test_playlist.add_song(self.test_song)
        self.test_playlist.add_song(test_song2)
        self.test_playlist.add_song(test_song3)
        self.test_playlist.remove_disrated(1)
        self.assertNotIn(test_song2, self.test_playlist.songs)

    def test_remove_bad_quality(self):
        test_song2 = Song("Bla bla", "bla", "blaa", 1, 240, 412)
        test_song3 = Song("lala", "la", "laa", 2, 210, 478)
        self.test_playlist.add_song(self.test_song)
        self.test_playlist.add_song(test_song2)
        self.test_playlist.add_song(test_song3)
        self.test_playlist.remove_bad_quality()
        self.assertNotIn(self.test_song, self.test_playlist.songs)

    def test_show_artists(self):
        test_song2 = Song("Bla bla", "bla", "blaa", 1, 240, 412)
        test_song3 = Song("lala", "la", "laa", 2, 210, 478)
        self.test_playlist.add_song(self.test_song)
        self.test_playlist.add_song(test_song2)
        self.test_playlist.add_song(test_song3)
        self.assertEqual({"Sunrise Avenue", "bla", "la"}, self.test_playlist.show_artists())

    def test_str(self):
        test_song2 = Song("Bla bla", "bla", "blaa", 1, 240, 412)
        test_song3 = Song("lala", "la", "laa", 2, 210, 478)
        self.test_playlist.add_song(self.test_song)
        self.test_playlist.add_song(test_song2)
        self.test_playlist.add_song(test_song3)
        self.assertIn("Sunrise Avenue Wonderland - 220", self.test_playlist.str())
开发者ID:smilen4eto,项目名称:Music-Library,代码行数:70,代码来源:playlist_test.py


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