コード例 #1
0
ファイル: band_test.py プロジェクト: nkolew/Softuni-Python
 def test_remove_song_working(self):
     album = Album("The Sound of Perseverance")
     song = Song("Scavenger of Human Sorrow", 6.56, False)
     album.add_song(song)
     message = album.remove_song("Scavenger of Human Sorrow")
     expected = "Removed song Scavenger of Human Sorrow from album The Sound of Perseverance."
     self.assertEqual(message, expected)
コード例 #2
0
ファイル: band_test.py プロジェクト: nkolew/Softuni-Python
 def test_add_song_already_added(self):
     album = Album("The Sound of Perseverance")
     song = Song("Scavenger of Human Sorrow", 6.56, False)
     album.add_song(song)
     message = album.add_song(song)
     expected = "Song is already in the album."
     self.assertEqual(message, expected)
コード例 #3
0
ファイル: load.py プロジェクト: alenatorgasheva/music
 def load_album(cls, fl_album, name):
     """Загрузка альбома"""
     with open(fl_album, 'r') as file_in:
         data = file_in.readlines()
     new_album = Album(name)
     for song in data:
         singer, name, duration = song.split(' - ')
         new_album.add_song(Song(singer, name, duration))
コード例 #4
0
ファイル: band_test.py プロジェクト: nkolew/Softuni-Python
 def test_remove_song_album_published(self):
     album = Album("The Sound of Perseverance")
     song = Song("Scavenger of Human Sorrow", 6.56, False)
     album.add_song(song)
     album.publish()
     message = album.remove_song("Scavenger of Human Sorrow")
     expected = "Cannot remove songs. Album is published."
     self.assertEqual(message, expected)
コード例 #5
0
ファイル: artist.py プロジェクト: jordmax12/Python-bootcamp
    def add_song(self, name, year, title):
        """Add a new song to the collection of albums

        This method will add the song to an album in the collection.
        A new album will be created in the collection if it doesn't already exist.

        Args:
            name (str): The name of the album
            year (int): The year the album was produced
            title (str): The title of the song
        """
        album_found = find_object(name, self.albums)
        if album_found is None:
            print(name + " not found")
            album_found = Album(name, year, self)
            self.add_album(album_found)
        else:
            print("Found album " + name)

        album_found.add_song(title)
コード例 #6
0
    def load_data(self):

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

                # add the new artist to the list
                new_artist = self.add_to_artist_list(artist_field)

                # create the basic objects from the data
                new_song = Song(song_field, artist_field)
                new_album = Album(album_field, year_field, artist_field)

                # create the cross connections
                new_album = new_artist.add_album(new_album)
                new_album.add_song(new_song)
                print("Processed ... ", artist_field, album_field, year_field,
                      song_field)
コード例 #7
0
def load_data():
    new_artist = None
    new_album = None
    artist_list = []
    with open('albums.txt') as albums:
        for a_line in albums:
            artist_field, album_field, year_field, song_field = a_line.strip(
            ).split("\t")
            print("{} - {} - {} - {}".format(artist_field, album_field,
                                             year_field, song_field))

            if new_artist is None:
                new_artist = Artist(artist_field)
                artist_list.append(new_artist)
            elif new_artist.name != artist_field:
                # Compare to previous artist, and if not equal to previous artist
                # Retrieve artist object if there is one, if not then create new artist
                new_artist = find_object(artist_field, artist_list)
                if new_artist is None:
                    new_artist = Artist(artist_field)
                    artist_list.append(new_artist)
                new_album = None

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

            # Song is just the same, song is created and we add song
            new_song = Song(song_field, new_artist)
            new_album.add_song(new_song)

    return artist_list
コード例 #8
0
 def add_song(self, album, year, song):
     new_album = the_finder.find_object(album, self.albums)
     if new_album is None:
         new_album = Album(album, year, self.name)
         self.albums.append(new_album)
     new_album.add_song(song)
コード例 #9
0
    def remove_album(self, album_name):
        try:
            album = next(filter(lambda a: a.name == album_name, self.albums))
            if album.published:
                return f"Album has been published. It cannot be removed."
            self.albums.remove(album)
            return f"Album {album_name} has been removed."
        except StopIteration:
            return f"Album {album_name} is not found."

    def details(self):
        data = f"Band {self.name}\n"
        for a in self.albums:
            data += a.details()
        return data




song = Song("Running in the 90s", 3.45, False)
print(song.get_info())
album = Album("Initial D", song)
second_song = Song("Around the World", 2.34, False)
print(album.add_song(second_song))
print(album.details())
print(album.publish())
band = Band("Manuel")
print(band.add_album(album))
print(band.remove_album("Initial D"))
print(band.details())
コード例 #10
0
ファイル: band_test.py プロジェクト: nkolew/Softuni-Python
 def test_details(self):
     album = Album("The Sound of Perseverance")
     song = Song("Scavenger of Human Sorrow", 6.56, False)
     album.add_song(song)
     message = album.details().strip()
     expected = "Album The Sound of Perseverance\n== Scavenger of Human Sorrow - 6.56"
コード例 #11
0
ファイル: band_test.py プロジェクト: nkolew/Softuni-Python
 def test_add_song_single(self):
     album = Album("The Sound of Perseverance")
     song = Song("Scavenger of Human Sorrow", 6.56, True)
     message = album.add_song(song)
     expected = "Cannot add Scavenger of Human Sorrow. It's a single"
     self.assertEqual(message, expected)
コード例 #12
0
ファイル: band_test.py プロジェクト: nkolew/Softuni-Python
 def test_add_song_working(self):
     album = Album("The Sound of Perseverance")
     song = Song("Scavenger of Human Sorrow", 6.56, False)
     message = album.add_song(song)
     expected = "Song Scavenger of Human Sorrow has been added to the album The Sound of Perseverance."
     self.assertEqual(message, expected)