def setUpClass(cls) -> None:
     cls.artist1 = Artist('Steve', 'UK')
     cls.artist2 = Artist('John', 'USA')
     cls.album1 = Album('s_album1', 2019, cls.artist1)
     cls.album2 = Album('j_album1', 2017, cls.artist2)
     cls.song1 = Song('s_song', cls.artist1, 2018, 180, cls.album1)
     cls.song2 = Song('j_song', cls.artist2, 2017, 150, cls.album2)
Exemple #2
0
 def test_add_song_works_correct(self):
     art1 = Artist("Mettalica", "USA")
     alb1 = Album('Death magnetic', 2008, 'Thrash metal', art1)
     song1 = Song('That Was Just Your Life', 2008, 426, art1, alb1)
     len_1 = len(alb1.songs)
     self.assertEqual(alb1.songs, [song1])
     song2 = Song('The End of the Line', 2008, 470, art1, alb1)
     len_2 = len(alb1.songs)
     self.assertEqual(len_1, len_2 - 1)
     song1 = Song('That Was Just Your Life', 2008, 426, art1, alb1)
     len_3 = len(alb1.songs)
     self.assertEqual(len_2, len_3)
Exemple #3
0
def load_data():
    new_artist = None
    new_album = None
    artist_list = []

    with open("albums.txt", "r") as albums:
        for line in albums:
            artist_field, album_field, year_field, song_field = tuple(
                line.strip('\n').split('\t'))
            year_field = int(year_field)
            print(artist_field, album_field, year_field, song_field)

            if new_artist is None:
                new_artist = Artist(artist_field)
            elif new_artist.name != artist_field:
                new_artist.add_album(new_album)
                artist_list.append(new_artist)
                new_artist = Artist(artist_field)
                new_album = None

            if new_album is None:
                new_album = Album(album_field, year_field, new_artist)
            elif new_album.name != album_field:
                new_artist.add_album(new_album)
                new_album = Album(album_field, year_field, new_artist)

            new_song = Song(song_field, new_artist)
            new_album.add_song(new_song)

        if new_artist is not None:
            if new_album is not None:
                new_artist.add_album(new_album)
            artist_list.append(new_artist)

    return artist_list
 def test_adding_song_raises_error_when_artists_doesnt_match(self):
     a = Artist('Lana Del Ray', 'USA')
     a1 = Artist('Adele', 'UK')
     b = Album('Born to Die', 2012, 'alternative/indie', a)
     b1 = Album('21', 2011, 'pop/soul', a1)
     c = Song('Blue Jeans', a, 2012, 240, b)
     with self.assertRaises(WrongArtistError):
         b1.add_song(c)
Exemple #5
0
def create_song_list(items):
    song_list = []
    for item in items:
        title = item["track"]["name"]
        album = item["track"]["album"]["name"]
        artist = item["track"]["artists"][0]["name"]
        duration = Duration(item["track"]["duration_ms"])
        time_played = Time(item["played_at"])
        song_list.append(Song(title, album, artist, duration, time_played))
    return song_list
Exemple #6
0
def object_creator(row_list):
    """
    Takes row_lists and creates a Song-object.
    Adds these to a separate dictionary and a list
    :param row_list:
    :return:
    """
    object = Song(row_list[0], row_list[1], row_list[2], row_list[3])
    object_list.append(object)
    node = HashNode(row_list[2], object)
    table.put(node)
Exemple #7
0
def object_creator(row_list):
    """
    Takes row_lists and creates a Song-object.
    Adds these to a separate dictionary and a list
    :param row_list:
    :return:
    """
    song_object = Song(row_list[0], row_list[1], row_list[2], row_list[3])
    #song_list.append(song_object)
    if row_list[2] in song_dict:
        song_dict[row_list[2]].append(song_object)
    else:
        song_dict[row_list[2]] = [song_object]
 def test_creating_song_adds_it_to_albums_songs_list(self):
     a = Artist('Ed Sheeran', 'UK')
     b = Album('Divide', 2017, 'pop', a)
     c = Song('New Man', a, 2017, 189, b)
     self.assertIn(c, b.songs)
 def setUpClass(cls) -> None:
     cls.artist1 = Artist('Steve', 'UK')
     cls.album1 = Album('s_album1', 2019, cls.artist1)
     cls.song1 = Song('s_song', cls.artist1, 2018, 180, cls.album1)
 def test_property_songs_number(self):
     self.song2 = Song('s_song2', self.artist1, 2019, 150, self.album1)
     self.assertEqual(self.artist1.songs_number, 2)
 def test_song_number_is_calculated_right(self):
     a = Artist('Ed Sheeran', 'UK')
     b = Album('Divide', 2017, 'pop', a)
     c = Song('Galway Girl', a, 2017, 248, b)
     d = Song('Castle on the Hill', a, 2017, 421, b)
     self.assertEqual(a.songs_number, 2)
Exemple #12
0
from classes import Artist, Album, Song

if __name__ == '__main__':
    a = Artist('Ed Sheeran', 'GB')
    s = Artist('Edn', 'GB')
    b = Album('Divide', 2015, 'pop', a)
    print(a.albums)
    print(a.songs)
    c = Song('Galway Girl', a, 2016, 150, b, 9)
    print(a.songs)

    print(c.duration)
from classes import Artist, Album, Song

if __name__ == '__main__':
    artist1 = Artist('Steve', 'UK')
    artist2 = Artist('John', 'USA')

    steve_album1 = Album('s_album1', 2019, 'Indie rock', artist1)
    john_album1 = Album('j_album1', 2018, 'Alternative rock', artist2)
    john_album2 = Album('j_album2', 2017, 'Heavy metal', artist2)

    steve_song1 = Song('s_song1', artist1, [artist2], 2019, 180, steve_album1)
    steve_song2 = Song('s_song2', artist1, [artist2], 2019, 220)
    john_song1 = Song('j_song1', artist2, [artist1], 2017, 150, john_album1)
    john_song2 = Song('j_song2', artist2, [artist1], 2018, 300, john_album2)
    john_song3 = Song('j_song3', artist2, [artist1], 2019, 180, john_album1)
    # Exception:
    steve_song3 = Song('s_song3', artist1, [artist2], 2019, 210, john_album1)

    # print(artist1.albums)
    # print(artist2.albums)
    # print(steve_album1.songs)
    # print(john_album1.songs)
    # print(artist1.songs)
    # print(artist2.songs)
    # print(john_album1.duration)
Exemple #14
0
from classes import Artist, Album, Song
# import classes as clx

if __name__ == "__main__":
    art1 = Artist("Mettalica", "USA")
    alb1 = Album('Death magnetic', 2008, 'Thrash metal', art1)
    song1 = Song('That Was Just Your Life', 2008, 426, art1, alb1)
    song2 = Song('The End of the Line', 2008, 470,  art1, alb1)
    alb2 = Album('St. Anger', 2003, 'Thrash metal', art1)
    song3 = Song('Frantic', 2003, 348,  art1, alb2)
    art2 = Artist('Motorhead', "USA")
    song4 = Song('Enter Sandman', 1991, 330, art1)
    song4.add_artist(art2)

    print(art1.songs_number, alb1.duration,
          alb1.songs_number, art1.album_number,
          song4.features, art2.album_number)


 def test_repr_check(self):
     a = Artist('Ed Sheeran', 'UK')
     b = Album('Divide', 2017, 'pop', a)
     c = Song('Supermarket Flowers', a, 2017, 221, b)
     self.assertEqual(repr(c), c.name)
 def song_number_is_calculated_right(self):
     a = Artist('Lana Del Ray', 'USA')
     b = Album('Born to Die', 2012, 'alternative/indie', a)
     c = Song('Blue Jeans', a, 2012, 240, b)
     d = Song('Born to Die', a, 2012, 320, b)
     self.assertEqual(b.songs_number, 2)
 def test_duration_is_calculated_right(self):
     a = Artist('Lana Del Ray', 'USA')
     b = Album('Born to Die', 2012, 'alternative/indie', a)
     c = Song('Blue Jeans', a, 2012, 240, b)
     d = Song('Born to Die', a, 2012, 320, b)
     self.assertEqual(b.duration, c.duration + d.duration)
 def test_creating_song_adds_it_to_artists_songs_list(self):
     a = Artist('Ed Sheeran', 'UK')
     b = Album('Divide', 2017, 'pop', a)
     c = Song('Shape of You', a, 2017, 234, b)
     self.assertIn(c, a.songs)
 def test_album_raises_error_if_artist_and_album_mismatch(self):
     with self.assertRaises(WrongArtistError):
         self.song3 = Song('s_song2', self.artist1, 2017, 140, self.album2)