Exemplo n.º 1
0
def main():
    p = Playlist(name='za ceniteli')

    p.add_songs([
        Song(title='Domination',
             artist='Pantera',
             album='Cowboys From Hell',
             length='05:04'),
        Song(title='This Love',
             artist='Pantera',
             album='Vulgar display of power',
             length='04:54'),
        Song(title='Walk',
             artist='Pantera',
             album='Vulgar display of power',
             length='03:54'),
        Song(title='Momicheto',
             artist='Hipodil',
             album='Nadurveni vuglishta',
             length='03:09')
    ])

    p.pprint_playlist()
    p.save()

    print('*' * 50)

    p = Playlist.load('za-ceniteli.json')

    p.add_songs([
        Song(title='Vurtianalen SEX',
             artist='Hipodil',
             album='Nadurveni vuglishta',
             length='04:04'),
        Song(title='Kolio Piqndeto',
             artist='Obraten Efekt',
             album='Efekten Obrat',
             length='03:31'),
        Song(title='Polet',
             artist='Obraten Efekt',
             album='Vervaite ni',
             length='03:50'),
        Song(title='Choki',
             artist='Obraten Efekt',
             album='Vervaite ni',
             length='04:09')
    ])

    p.pprint_playlist()
    p.save()
Exemplo n.º 2
0
class PlaylistTests(unittest.TestCase):
    def setUp(self):
        self.one = Song("bbb", "aaa", "ccc", "3:36")
        self.two = Song("ddd", "aaa", "eee", "4:20")
        self.three = Song("eee", "aaa", "ccc", "12:28")
        self.four = Song("nnn", "mmm", "ooo", "6:32")
        self.five = Song("sss", "ppp", "rrr", "1:20:03")
        self.six = Song("yyy", "xxx", "zzz", "2:32:15")

        self.playlist_one = Playlist(name="First")
        self.playlist_two = Playlist(name="First", repeat=True)
        self.playlist_three = Playlist(name="First", shuffle=True)
        self.playlist_four = Playlist(name="First", repeat=True, shuffle=True)

        self.list_of_songs = [
            self.one, self.two, self.three, self.four, self.five, self.six
        ]

    def test_init_playlist(self):
        with self.subTest("test init"):
            Playlist(name="Test_Playlist")

        with self.subTest("test init"):
            Playlist(name="Test_Playlist", repeat=True)

        with self.subTest("test init"):
            Playlist(name="Test_Playlist", shuffle=True)

        with self.subTest("test init"):
            Playlist(name="Test_Playlist", repeat=True, shuffle=True)

    def test_add_song_to_playlist(self):
        expected = [self.one]
        self.playlist_one.add_song(self.one)
        result = self.playlist_one.songs
        self.assertEqual(result, expected)

    def test_add_songs_to_playlist(self):
        expected = [
            self.one, self.two, self.three, self.four, self.five, self.six
        ]
        self.playlist_one.add_songs(self.list_of_songs)
        result = self.playlist_one.songs
        self.assertEqual(result, expected)

    def test_remove_song_from_playlist(self):
        expected = [self.one, self.three, self.four, self.five, self.six]
        self.playlist_one.add_songs(self.list_of_songs)
        self.playlist_one.remove_song(self.two)
        result = self.playlist_one.songs
        self.assertEqual(result, expected)

    def test_total_length_of_playlist(self):
        expected = "4:19:14"
        self.playlist_one.add_songs(self.list_of_songs)
        result = self.playlist_one.total_length()
        self.assertEqual(result, expected)

    def test_artists_of_playlist(self):
        expected = {'aaa': 3, 'mmm': 1, 'ppp': 1, 'xxx': 1}
        self.playlist_one.add_songs(self.list_of_songs)
        result = self.playlist_one.artists()
        self.assertDictEqual(result, expected)

    def test_next_song_of_playlist(self):
        with self.subTest("next song without shuffle and repeat"):
            expected = [
                self.one, self.two, self.three, self.four, self.five, self.six
            ]
            self.playlist_one.add_songs(self.list_of_songs)
            result = []
            for i in range(len(expected)):
                result.append(self.playlist_one.next_song())
            self.assertListEqual(result, expected)

        with self.subTest("next song with repeat without shuffle"):
            expected = [
                self.one, self.two, self.three, self.four, self.five, self.six,
                self.one, self.two
            ]
            self.playlist_two.add_songs(self.list_of_songs)
            result = []
            for i in range(len(expected)):
                result.append(self.playlist_two.next_song())
            self.assertListEqual(result, expected)

        with self.subTest("next song with shuffle without repeat"):
            expected = [
                self.one, self.two, self.three, self.four, self.five, self.six
            ]
            self.playlist_three.add_songs(self.list_of_songs)
            result = []
            for i in range(len(expected)):
                result.append(self.playlist_three.next_song())
            self.assertTrue(
                len(result) == len(expected)
                and all([result.count(i) == expected.count(i)
                         for i in result]))

        with self.subTest("HOW TO: next song with shuffle with repeat"):
            expected = self.playlist_four.played
            self.playlist_four.add_songs(self.list_of_songs)
            result = []
            for i in range(len(expected)):
                result.append(self.playlist_four.next_song())
            self.assertListEqual(result, expected)