Esempio n. 1
0
class PlaylistTest(unittest.TestCase):
    def setUp(self):
        self.my_song = Song("Solder Of Frortune", "Deep Purple",
                            "Stormbringer", "3:14")
        self.second_song = Song("I Stand Alone", "Godsmack", "Awake", "4:30")
        self.rock = Playlist("Rock songs", True)
        self.songs = [self.my_song, self.second_song]
        self.rock.add_songs(self.songs)

    def test_playlist_constructor(self):
        self.assertTrue(isinstance(self.rock, Playlist))

    def test_add_song(self):
        self.assertEqual(self.rock.playlist, self.songs)

    def test_remove_song(self):
        self.rock.remove_song(self.my_song)
        self.assertEqual(self.rock.playlist, [self.second_song])

    def test_remove_song_fail(self):
        self.rock.remove_song(self.my_song)
        with self.assertRaises(NoSuchSong):
            self.rock.remove_song(self.my_song)

    def test_add_songs(self):
        self.assertEqual(self.rock.playlist, self.songs)

    def test_total_length(self):
        self.assertEqual(self.rock.total_length(), "0:07:44")

    def test_artists(self):
        histogram = {"Deep Purple": 1, "Godsmack": 1}
        self.assertEqual(self.rock.artists(), histogram)

    def test_repeat(self):
        self.assertEqual(self.rock.next_song(), self.my_song)
        self.assertEqual(self.rock.next_song(), self.second_song)
        self.assertEqual(self.rock.next_song(), self.my_song)

    def test_no_more_songs(self):
        self.rock.change_repeat(False)
        self.assertEqual(self.rock.next_song(), self.my_song)
        self.assertEqual(self.rock.next_song(), self.second_song)
        with self.assertRaises(NoMoreSongs):
            self.rock.next_song()
        self.rock.change_shuffle(True)
        self.rock.next_song()
        self.rock.next_song()
        with self.assertRaises(NoMoreSongs):
            self.rock.next_song()

    def test_shuffle(self):
        self.rock.change_shuffle(True)
        bard = Song("The Bard's Song", "Blind Guardian", "Somwhere Far Beyond",
                    "3:28")
        self.rock.add_song(bard)
        a = self.rock.next_song()
        b = self.rock.next_song()
        c = self.rock.next_song()
        self.assertTrue(a != b and c != a and c != b)
Esempio n. 2
0
 def test_class_Playlist_method_remove_song(self):
     song2 = Song(artist="Metalica", album="metalica",
                  length=385, song_name="Nothing else matters")
     pl = Playlist("rado")
     pl.add_song(song2)
     pl.remove_song(song2)
     self.assertTrue(len(pl.song_lst) == 0)
Esempio n. 3
0
    def test_playlist_next_song_works_as_expected_with_no_repeat_and_no_shuffle(
            self):
        f = Song(title="Odin",
                 artist="Manowar",
                 album="The Sons of Odin",
                 length="3:44")
        s = Song(title="Empty",
                 artist="Metric",
                 album="Live It Out",
                 length="5:55")
        q = Song(title="Superman",
                 artist="Eminem",
                 album="The Eminem Show",
                 length="5:50")
        code_songs = Playlist(name="Code", repeat=False, shuffle=False)

        code_songs.add_song(f)
        code_songs.add_song(s)
        code_songs.add_song(q)

        code_songs.next_song()
        code_songs.next_song()

        self.assertEqual(code_songs.next_song(),
                         'There are no more songs in your playlist.')
class TestPlaylist(unittest.TestCase):

    def setUp(self):
        self.s = Song("Odin", "Manowar", "The Sons of Odin", "3:44")
        self.other = Song("Odin", "Manowar", "The Sons of Odin", "3:44")
        self.other2 = Song("Odinkata", "Manowar", "The Sons of Odin", "3:4:40")
        self.my_playlist = Playlist("MyPlaylist", repeat=True, shuffle=False)

    def test_init(self):
        self.assertTrue(isinstance(self.my_playlist, Playlist))

    def test_add_song(self):
        self.my_playlist.add_song(self.s)
        self.assertTrue(self.s in self.my_playlist.songs)

    def test_add_list_of_songs(self):
        tmp = [self.other, self.other2]
        self.my_playlist.add_songs(tmp)
        self.assertTrue(self.other in self.my_playlist.songs and self.other2 in self.my_playlist.songs)

    def test_remove_song(self):
        tmp = [self.other, self.other2]
        self.my_playlist.add_songs(tmp)
        self.my_playlist.remove_song(self.other)
        self.assertFalse(self.other in self.my_playlist.songs)

    def test_total_length(self):
        tmp = [self.other, self.s]
        self.my_playlist.add_songs(tmp)
#        self.assertEqual(self.my_playlist.total_length(), "3:8:20")

        self.assertEqual(self.my_playlist.total_length(), "7:28")

    def test_artists(self):
        pass
Esempio n. 5
0
class TestPlaylist(unittest.TestCase):
    """docstring for TestPlaylist"""
    def setUp(self):
        self.p = Playlist(name="Code", repeat=False, shuffle=False)
        self.song_1 = Song(title="Odin", artist="Manowar", album="The Sons of Odin", length="60")
        self.song_2 = Song(title="Odin2", artist="Manowar2", album="The Sons of Odin2", length="60")

    def test_Playlist_addsong(self):
        self.p.add_song(self.song_1)
        self.assertIn(self.song_1, self.p.playlist)

    def test_Playlist_addsongs(self):
        songs = [self.song_1, self.song_2]
        self.p.add_songs(songs)
        self.assertIn(self.song_1, self.p.playlist)
        self.assertIn(self.song_2, self.p.playlist)
        self.assertEqual(len(self.p.playlist), 2)

    def test_Playlist_remove_song(self):
        songs = [self.song_1, self.song_2]
        self.p.add_songs(songs)
        self.assertEqual(self.p.remove_song(self.song_1), self.song_1)
        self.assertEqual(len(self.p.playlist), 1)
    #tank_size - how much our car can ride with a full tank of gas. It is a positive integer in kilometers

    def test_Playlist_total_length(self):
        songs = [self.song_1, self.song_2]
        self.p.add_songs(songs)
        self.assertEqual(self.p.total_length(), "0:02:00")

    def test_Playlist_artists(self):
        songs = [self.song_1, self.song_2]
        self.p.add_songs(songs)
        self.p.add_song(self.song_1)

    def test_Playlist_shuffle(self):
        songs = [self.song_1, self.song_2]
        self.p.add_songs(songs)
        self.p._shuffle = True
        self.assertNotIn(self.p.shuffle(), self.p._shuffle_playlist)
        self.assertNotIn(self.p.shuffle(), self.p._shuffle_playlist)
        #self.assertEqual(self.p.shuffle(), 0)

    def test_Playlist_next_song(self):
        songs = [self.song_1, self.song_2]
        self.p.add_songs(songs)

    def test_Playlist_pprint_playlist(self):
        songs = [self.song_1, self.song_2]
        self.p.add_songs(songs)
        print(self.p.pprint_playlist())

    def test_Playlist_save(self):
        songs = [self.song_1, self.song_2]
        self.p.add_songs(songs)
        self.p.save('export.json')

    def test_Playlist_load(self):
        code = Playlist.load('export.json')
Esempio n. 6
0
    def test_playlist_artists_works_as_expected(self):
        my_playlist = Playlist(name="Code", repeat=True, shuffle=True)
        test = Song(title="Odin",
                    artist="Manowar",
                    album="The Sons of Odin",
                    length="3:44")

        my_playlist.add_song(test)

        self.assertEqual(my_playlist.artists(), {'Manowar': 1})
Esempio n. 7
0
    def test_playlist_add_song_adds_song_to_object_list_of_songs(self):
        test = Song(title="Odin",
                    artist="Manowar",
                    album="The Sons of Odin",
                    length="3:44")
        my_playlist = Playlist(name="Code", repeat=True, shuffle=True)

        my_playlist.add_song(test)

        assert test in my_playlist.songs
class TestPlaylist(unittest.TestCase):
    def setUp(self):
        self.title = "nana"
        self.artist = "Viki"
        self.album = "Na"
        self._length = "3:00"
        self.song = Song(self.title, self.artist, self.album, self._length)
        self.song2 = Song("lq", "Viktoria", "lqlq", "4:30")
        self.song3 = Song(self.title, self.artist, self.album, self._length)
        self.play_list = Playlist("random playlist")
        self.songs = [self.song, self.song2]

    def test_add_song(self):
        self.play_list.add_song(self.song)
        self.assertIn(self.song, self.play_list.get_song())

    def test_remove_song(self):
        self.play_list.remove_song(self.song)
        self.assertNotIn(self.song, self.play_list.get_song())

    def test_add_songs(self):
        self.play_list.add_songs(self.songs)
        self.assertIn(self.song, self.play_list.get_song())
        self.assertIn(self.song2, self.play_list.get_song())

    def test_total_length(self):
        pass

    def test_artist(self):
        pass

    def test_next_song(self):
        self.play_list.add_songs(self.songs)
        self.assertIn(self.play_list.next_song(), self.songs)

    def test_next_song_many_times(self):
        self.play_list.add_songs(self.songs)
        self.assertEqual(self.play_list.next_song, self.song)
        self.assertEqual(self.play_list.next_song, self.song2)

    def test_next_song_many_times_repeat_on(self):
        pass

    def test_next_song_suffle_on(self):
        self.play_list = Playlist("random playlist", repeat=True)

        self.play_list.add_songs(self.songs)
        self.assertEqual(self.play_list.next_song, self.song)
        self.assertEqual(self.play_list.next_song, self.song2)

    def test_json_dumps(self):
        pass

    if __name__ == "__main__":
        unittest.main()
Esempio n. 9
0
    def test_class_Playlist_method_save_and_load(self):
        song2 = Song(artist="Metalica", album="metalica",
                     length=385, song_name="Nothing else matters")
        song3 = Song(
            artist="Metalica", album="metalica", length=7200, song_name="The Unforgiven")

        pl = Playlist("default")
        pl.add_song(song2)
        pl.add_song(song3)
        pl.save()
        pl.load()
Esempio n. 10
0
    def test_playlist_remove_song_removes_song_from_object_list_of_songs(self):
        test = Song(title="Odin",
                    artist="Manowar",
                    album="The Sons of Odin",
                    length="3:44")
        my_playlist = Playlist(name="Code", repeat=True, shuffle=True)

        my_playlist.add_song(test)
        my_playlist.remove_song(test)

        self.assertEqual(my_playlist.songs, [])
Esempio n. 11
0
class TestPlaylist(unittest.TestCase):

    def setUp(self):
        self.code_songs = Playlist(name="Code", repeat=True, shuffle=True)

    def test_initialisation(self):
        self.assertTrue(isinstance(self.code_songs, Playlist))

    def test_add_remove_song(self):
        a = Song()
        self.assertFalse(a in self.code_songs.song_list)
        self.code_songs.add_song(a)
        self.assertTrue(a in self.code_songs.song_list)
        self.code_songs.remove_song(a)
        self.assertTrue(a not in self.code_songs.song_list)

    def test_add_songs(self):
        a = Song()
        b = Song(title="Pesho's song", artist="Pesho",
                 album="Pesho/'s album", length="23:22:12")
        l = []
        l.append(a)
        l.append(b)
        self.code_songs.add_songs(l)
        self.assertTrue(a in self.code_songs.song_list)
        self.assertTrue(b in self.code_songs.song_list)

    def test_artists_histogram(self):
        a = Song(title="alaba", artist="Rihanna",
                 album="Nqkoi", length="12:02")
        b = Song(title="Pesho's song", artist="Pesho",
                 album="Pesho/'s album", length="23:22:12")
        c = Song(title="PeshosOtherSong", artist="Pesho",
                 album="blaa", length="22:12")
        self.code_songs.song_list.append(a)
        self.code_songs.song_list.append(b)
        self.code_songs.song_list.append(c)
        dicta = {}
        dicta['Pesho'] = 2
        dicta['Rihanna'] = 1
        self.assertEqual(dicta, self.code_songs.artists())

    def test_total_length(self):
        a = Song(title="alaba", artist="Rihanna",
                 album="Nqkoi", length="12:02")
        b = Song(title="Pesho's song", artist="Pesho",
                 album="Pesho/'s album", length="23:22:12")
        c = Song(title="PeshosOtherSong", artist="Pesho",
                 album="blaa", length="22:12")
        self.code_songs.song_list.append(a)
        self.code_songs.song_list.append(b)
        self.code_songs.song_list.append(c)
        self.assertEqual(self.code_songs.total_length(), '23:56:26')
Esempio n. 12
0
class testPlaylist(unittest.TestCase):
    def setUp(self):
        self.pl = Playlist("ssss")
        self.pl.add_song(
            Song(title="Odin",
                 artist="Manowar",
                 album="The Sons of Odin",
                 time="3:44"))
        self.pl.add_song(
            Song(title="Odin", artist="Manowar", album="Odin", time="6:26"))

    def test_next_song(self):
        self.assertEqual(self.pl.next_song(), "")
Esempio n. 13
0
    def test_playlist_next_song_works_as_expected_with_repeat_and_shuffle(
            self):
        f = Song(title="Odin",
                 artist="Manowar",
                 album="The Sons of Odin",
                 length="3:44")
        s = Song(title="Empty",
                 artist="Metric",
                 album="Live It Out",
                 length="5:55")
        q = Song(title="Superman",
                 artist="Eminem",
                 album="The Eminem Show",
                 length="5:50")
        code_songs = Playlist(name="Code", repeat=True, shuffle=True)
        test = Playlist(name="Code2", repeat=True, shuffle=True)

        code_songs.add_song(f)
        code_songs.add_song(s)
        code_songs.add_song(q)

        test.add_song(code_songs.next_song())
        test.add_song(code_songs.next_song())
        test.add_song(code_songs.next_song())

        code_songs.next_song()

        assert code_songs.next_song() in getattr(test, 'songs')
Esempio n. 14
0
    def test_playlist_total_length_is_calculated_correctly_with_songs_under_a_minute(
            self):
        my_playlist = Playlist(name="Code", repeat=True, shuffle=True)
        test1 = Song(title="Odin",
                     artist="Manowar",
                     album="The Sons of Odin",
                     length="0:44")
        test2 = Song(title="Empty",
                     artist="Metric",
                     album="Live It Out",
                     length="0:10")

        my_playlist.add_song(test1)
        my_playlist.add_song(test2)

        self.assertEqual(my_playlist.total_length(), '0:54')
Esempio n. 15
0
    def test_playlist_total_length_is_calculated_correctly_with_songs_sum_over_hour(
            self):
        my_playlist = Playlist(name="Code", repeat=True, shuffle=True)
        test1 = Song(title="Odin",
                     artist="Manowar",
                     album="The Sons of Odin",
                     length="55:44")
        test2 = Song(title="Empty",
                     artist="Metric",
                     album="Live It Out",
                     length="5:16")

        my_playlist.add_song(test1)
        my_playlist.add_song(test2)

        self.assertEqual(my_playlist.total_length(), '1:01:00')
Esempio n. 16
0
    def test_playlist_add_song_raises_excpetion_if_song_already_in_playlist(
            self):
        test1 = Song(title="Odin",
                     artist="Manowar",
                     album="The Sons of Odin",
                     length="3:44")
        test2 = Song(title="Odin",
                     artist="Manowar",
                     album="The Sons of Odin",
                     length="3:44")
        my_playlist = Playlist(name="Code", repeat=True, shuffle=True)
        exc = None

        my_playlist.add_song(test1)

        try:
            my_playlist.add_song(test2)
        except Exception as err:
            exc = err

        self.assertIsNotNone(exc)
        self.assertEqual(str(exc), 'Song is already in the playlist.')
class MusicPlayerTest(unittest.TestCase):

    def setUp(self):
        self.song = Song("Odin", "Manowar", "The Sons of Odin", "3:44")
        self.playlist = Playlist("The sex and the city")

    def test_str(self):
        self.assertEqual(str(
            self.song), "Manowar - Odin (The Sons of Odin) : 3:44")

    def test_adding_song_in_playlist(self):
        self.playlist.add_song(self.song)
        self.assertTrue(self.playlist.has_song(self.song))

    def test_removing_song(self):
        self.playlist.add_song(self.song)
        self.playlist.remove_song(self.song)
        self.assertFalse(self.playlist.has_song(self.song))

    def test_total_length(self):
        song = Song("Baby", "J.Beiber", "Gay Album", "3:50")
        self.playlist.add_songs([self.song, song])
        self.assertEqual(self.playlist.total_length(), "0:07:34")

    def test_artists(self):
        song = Song("Baby", "J.Beiber", "Gay Album", "3:50")
        self.playlist.add_songs([self.song, song])
        self.assertEqual(
            self.playlist.artists(), {'Manowar': 1, "J.Beiber": 1})

    def test_play_next_song_in_empty_playlist(self):
        with self.assertRaises(Exception):
            self.playlist.next_song()

    def test_play_next_song_if_there_is_only_one_with_repeat_False(self):
        self.playlist.add_song(self.song)
        with self.assertRaises(Exception):
            self.playlist.next_song()

    def test_next_songs_with_repeat_False(self):
        random_song = Song("Random", "Manowar", "The Sons of Odin", "1:30:44")
        another_song = Song("Anther", "Manowar", "The Sons of Odin", "1:30:44")
        self.playlist.add_songs([self.song, random_song, another_song])
        self.assertEqual(self.playlist.next_song(), random_song)
        self.assertEqual(self.playlist.next_song(), another_song)
        with self.assertRaises(Exception):
            self.playlist.next_song()

    def test_next_songs_with_repeat_True(self):
        random_song = Song("Random", "Random", "The Sons of Odin", "3:44")
        another_song = Song("Anther", "Kanye West", "Heartless", "4:20")
        song = Song("Baby", "J.Beiber", "Gay Album", "3:50")
        p = Playlist("p", repeat=True)
        p.add_songs([self.song, random_song, another_song, song])
        self.assertEqual(p.next_song(), random_song)
        self.assertEqual(p.next_song(), another_song)
        self.assertEqual(p.next_song(), song)
        self.assertEqual(p.next_song(), self.song)

    def test_generate_json_name(self):
        self.assertEqual(
            self.playlist.generate_json_name(), "The-sex-and-the-city.json")

    def test_save_load(self):
        song = Song("Baby", "J.Beiber", "Gay Album", "3:50")
        self.playlist.add_songs([self.song, song])
        self.playlist.save()

        g = Playlist.load("The-sex-and-the-city.json")
        self.assertEqual(self.playlist.songs, g.songs)
        self.assertEqual(g.name, "The sex and the city")

    def test_crawler_generate_ability(self):
        crawler = MusicCrawler("/home/hdimitrova/Music/Linkin Park - Meteora")
        playlist = crawler.generate_playlist("Meteora")
        self.assertEqual(playlist.total_length(), '0:36:41')

    def test_crawlered_playlist_save(self):
        crawler = MusicCrawler("/home/hdimitrova/Music/Linkin Park - Meteora")
        playlist = crawler.generate_playlist("Linkin Park - Meteora")
        playlist.save()
        playlist.pprint_playlist()
Esempio n. 18
0
 def test_add_song_when_song_is_instance_of_class_song_then_add_song_to_playlist(self):
     test_playlist = Playlist('OneRepublic')
     test_playlist.add_song(Song(title='Love Runs Out', artist='OneRepublic', album='Native', length='3:44'))
     expected_result = [Song(title='Love Runs Out', artist='OneRepublic', album='Native', length='3:44')]
     self.assertEqual(test_playlist.songs_list, expected_result)