示例#1
0
 def setUp(self):
     self.song = Song(
         "Thunderstruck", "ACDC", "Back in black", 5, 4.24, 256)
     self.collection = []
     self.collection2 = []
     self.collection.append(self.song)
     self.playList1 = Playlist(self.collection, "rock")
     self.playList2 = Playlist(self.collection2, "pop")
示例#2
0
 def test_show_artists(self):
     self.song1 = Song(
         "Shoot to thrill", "ACDC", "Back in black", 4, 4.44, 128)
     self.playList1.add_song(self.song1)
     self.song2 = Song(
         "sweet child o mine", "GnR", "Apetite for destruction", 5, 6.44, 256)
     a = ["ACDC", "GnR"]
     self.playList1.add_song(self.song2)
     self.assertEqual(a, self.playList1.show_artist())
示例#3
0
 def test_playlist_str(self):
     self.song1 = Song(
         "Shoot to thrill", "ACDC", "Back in black", 4, 4.44, 128)
     self.playList1.add_song(self.song1)
     self.song2 = Song(
         "sweet child o mine", "GnR", "Apetite for destruction", 5, 6.44, 256)
     a = ["ACDC", "GnR"]
     self.playList1.add_song(self.song2)
     a = "ACDC Thunderstruck - 4.24\nACDC Shoot to thrill - 4.44\nGnR sweet child o mine - 6.44\n"
     self.assertEqual(a, self.playList1.str())
示例#4
0
 def test_remove_disrated_songs(self):
     self.song1 = Song(
         "Shoot to thrill", "ACDC", "Back in black", 4, 4.44, 128)
     self.playList1.add_song(self.song1)
     self.song2 = Song(
         "TNT", "ACDC", "Bon Scott baby", 3, 4.44, 256)
     self.playList1.add_song(self.song2)
     self.playList1.remove_disrated(5)
     self.assertEqual(1, len(self.playList1.collection))
     self.assertEqual("Thunderstruck", self.playList1.collection[0].title)
示例#5
0
 def test_remove_bad_quality(self):
     flag1 = False
     self.song1 = Song(
         "Shoot to thrill", "ACDC", "Back in black", 4, 4.44, 128)
     self.playList1.add_song(self.song1)
     self.song2 = Song(
         "TNT", "ACDC", "Bon Scott baby", 3, 4.44, 256)
     self.playList1.add_song(self.song2)
     self.playList1.remove_bad_quality()
     if self.song1 in self.playList1.collection:
         flag1 = True
     self.assertFalse(flag1)
示例#6
0
 def test_remove_song(self):
     self.song1 = Song(
         "Shoot to thrill", "ACDC", "Back in black", 4, 4.44, 256)
     self.playList1.add_song(self.song1)
     self.playList1.remove_song(self.song)
     self.assertEqual(1, len(self.playList1.collection))
     self.assertEqual("Shoot to thrill", self.playList1.collection[0].title)
示例#7
0
 def test_JSON_save(self):
     self.song1 = Song(
         "Shoot to thrill", "ACDC", "Back in black", 4, 4.44, 128)
     self.playList1.add_song(self.song1)
     self.song2 = Song(
         "sweet child o mine", "GnR", "Apetite for destruction", 5, 6.44, 256)
     a = ["ACDC", "GnR"]
     self.playList1.add_song(self.song1)
     self.playList1.save("/home/biser/JSon/json1.json")
     self.song3 = Song(
         "Give in to me", "Jackson and Slash", "Best", 4, 4.44, 256)
     self.song4 = Song(
         "Cant stop", "RHCP", "blqblq", 4, 4.44, 128)
     self.playList2.add_song(self.song3)
     self.playList2.add_song(self.song4)
     self.playList2.save("/home/biser/JSon/json2.json")
示例#8
0
class TestSong(unittest.TestCase):

    def setUp(self):
        self.new_song = Song("How Come", "D12", "D12 World", 225, 320)

    def test_init(self):
        self.assertEqual(self.new_song.title, "How Come")
        self.assertEqual(self.new_song.artist, "D12")
        self.assertEqual(self.new_song.album, "D12 World")
        self.assertEqual(self.new_song.le, 225)
        self.assertEqual(self.new_song.bitrate, 320)
        self.assertEqual(self.new_song.rating, 0)

    def test_rate(self):
        self.new_song.rate(3)
        self.assertEqual(self.new_song.rating, 3)
        with self.assertRaises(ValueError):
            self.new_song.rate(6)
        with self.assertRaises(ValueError):
            self.new_song.rate(-1)

    def test_str(self):
        self.assertEqual(str(self.new_song), "D12 - How Come  3:45")
示例#9
0
 def setUp(self):
     self.new_song = Song("How Come", "D12", "D12 World", 225, 320)
示例#10
0
 def __init__(self, artist, album, title, song_id):
     Song.__init__(self, artist, album, title)
     self.song_id = song_id
示例#11
0
 def test_total_length(self):
     self.song1 = Song(
         "Shoot to thrill", "ACDC", "Back in black", 4, 4.44, 256)
     self.playList1.add_song(self.song1)
     self.assertEqual(8.68, self.playList1.total_length())
示例#12
0
class music_player_test(unittest.TestCase):

    def setUp(self):
        self.song = Song(
            "Thunderstruck", "ACDC", "Back in black", 5, 4.24, 256)
        self.collection = []
        self.collection2 = []
        self.collection.append(self.song)
        self.playList1 = Playlist(self.collection, "rock")
        self.playList2 = Playlist(self.collection2, "pop")

    def test_Song_constructor(self):
        self.assertEqual("Thunderstruck", self.song.title)
        self.assertEqual("ACDC", self.song.artist)
        self.assertEqual("Back in black", self.song.album)
        self.assertEqual(5, self.song.rating)
        self.assertEqual(4.24, self.song.length)
        self.assertEqual(256, self.song.bitrate)

    def test_Song_rate_func(self):
        self.song.rate(4)
        self.assertEqual(4, self.song.rating)

    def test_Song_rate_func_invalid_rating(self):
        self.assertEqual("invalid rating", self.song.rate(16))
        self.assertEqual(5, self.song.rating)

    def test_Playlist_constructor(self):
        self.assertEqual(
            self.collection[0].title, self.playList1.collection[0].title)

    def test_add_song(self):
        self.song1 = Song(
            "Shoot to thrill", "ACDC", "Back in black", 4, 4.44, 256)
        self.playList1.add_song(self.song1)
        self.assertEqual("Shoot to thrill", self.playList1.collection[1].title)

    def test_remove_song(self):
        self.song1 = Song(
            "Shoot to thrill", "ACDC", "Back in black", 4, 4.44, 256)
        self.playList1.add_song(self.song1)
        self.playList1.remove_song(self.song)
        self.assertEqual(1, len(self.playList1.collection))
        self.assertEqual("Shoot to thrill", self.playList1.collection[0].title)

    def test_total_length(self):
        self.song1 = Song(
            "Shoot to thrill", "ACDC", "Back in black", 4, 4.44, 256)
        self.playList1.add_song(self.song1)
        self.assertEqual(8.68, self.playList1.total_length())

    def test_remove_disrated_songs(self):
        self.song1 = Song(
            "Shoot to thrill", "ACDC", "Back in black", 4, 4.44, 128)
        self.playList1.add_song(self.song1)
        self.song2 = Song(
            "TNT", "ACDC", "Bon Scott baby", 3, 4.44, 256)
        self.playList1.add_song(self.song2)
        self.playList1.remove_disrated(5)
        self.assertEqual(1, len(self.playList1.collection))
        self.assertEqual("Thunderstruck", self.playList1.collection[0].title)

    def test_remove_bad_quality(self):
        flag1 = False
        self.song1 = Song(
            "Shoot to thrill", "ACDC", "Back in black", 4, 4.44, 128)
        self.playList1.add_song(self.song1)
        self.song2 = Song(
            "TNT", "ACDC", "Bon Scott baby", 3, 4.44, 256)
        self.playList1.add_song(self.song2)
        self.playList1.remove_bad_quality()
        if self.song1 in self.playList1.collection:
            flag1 = True
        self.assertFalse(flag1)

    def test_show_artists(self):
        self.song1 = Song(
            "Shoot to thrill", "ACDC", "Back in black", 4, 4.44, 128)
        self.playList1.add_song(self.song1)
        self.song2 = Song(
            "sweet child o mine", "GnR", "Apetite for destruction", 5, 6.44, 256)
        a = ["ACDC", "GnR"]
        self.playList1.add_song(self.song2)
        self.assertEqual(a, self.playList1.show_artist())

    def test_playlist_str(self):
        self.song1 = Song(
            "Shoot to thrill", "ACDC", "Back in black", 4, 4.44, 128)
        self.playList1.add_song(self.song1)
        self.song2 = Song(
            "sweet child o mine", "GnR", "Apetite for destruction", 5, 6.44, 256)
        a = ["ACDC", "GnR"]
        self.playList1.add_song(self.song2)
        a = "ACDC Thunderstruck - 4.24\nACDC Shoot to thrill - 4.44\nGnR sweet child o mine - 6.44\n"
        self.assertEqual(a, self.playList1.str())

    def test_JSON_save(self):
        self.song1 = Song(
            "Shoot to thrill", "ACDC", "Back in black", 4, 4.44, 128)
        self.playList1.add_song(self.song1)
        self.song2 = Song(
            "sweet child o mine", "GnR", "Apetite for destruction", 5, 6.44, 256)
        a = ["ACDC", "GnR"]
        self.playList1.add_song(self.song1)
        self.playList1.save("/home/biser/JSon/json1.json")
        self.song3 = Song(
            "Give in to me", "Jackson and Slash", "Best", 4, 4.44, 256)
        self.song4 = Song(
            "Cant stop", "RHCP", "blqblq", 4, 4.44, 128)
        self.playList2.add_song(self.song3)
        self.playList2.add_song(self.song4)
        self.playList2.save("/home/biser/JSon/json2.json")

    def test_JSON_load(self):
        Playlist.load("/home/biser/JSon/json1.json")
        pass