Exemplo n.º 1
0
def sort_key(collection, key):
    """Ask for the order as descending or ascending"""
    descending = handle_text('Sort songs in descending order? (Y/N): ',
                             is_bool=True)
    print("Results:")
    sort_results = collection.sort_song(key, descending)
    print(SongCollection.format_data(sort_results))
Exemplo n.º 2
0
def run_tests():
    """Test SongCollection class."""

    # Test empty SongCollection (defaults)
    print("Test empty SongCollection:")
    song_collection = SongCollection()
    print(song_collection)
    assert not song_collection.song_list  # an empty list is considered False

    # Test loading songs
    print("Test loading songs:")
    song_collection.load_songs('songs.csv')
    print(song_collection)
    assert song_collection.song_list  # assuming CSV file is non-empty, non-empty list is considered True

    # Test adding a new Song with values
    print("Test adding new song:")
    song_collection.add_song(Song("My Happiness", "Powderfinger", 1996, True))
    print(song_collection)

    # Test sorting songs
    print("Test sorting - year:")
    sorted_list = song_collection.sort_song("year", descending=True)
    print(song_collection.format_data(sorted_list))
    # Test sorting artists
    print("Test sorting - artist:")
    sorted_list_2 = song_collection.sort_song("artist", descending=True)
    print(song_collection.format_data(sorted_list_2))
    # test sorting titles
    print("Test sorting - title:")
    sorted_list_3 = song_collection.sort_song("title", descending=False)
    print(song_collection.format_data(sorted_list_3))

    #  Test saving songs (check CSV file manually to see results)
    print("Test saving songs:")
    song_collection.save_changes("songs.csv")
    print("Open songs.csv to check whether new song appears or not")

    # Add more tests, as appropriate, for each method
    # Test count learned songs
    print("Test count learned songs:")
    print(song_collection.count_learned())
    # Test count unlearned songs
    print("Test count unlearned songs:")
    print(song_collection.count_unlearned())
Exemplo n.º 3
0
def search_songs(collection):
    """Search the song by keywords that the users input"""
    flag = False
    while not flag:
        print("Search songs")
        title_search = handle_text('Title (keywords):', blank=True)
        year_search = handle_text('Year:', blank=True)
        artist_search = handle_text("Artist", blank=True)
        status_search = handle_text("Learned or unlearned? (Y/N)?",
                                    is_bool=True,
                                    blank=True)

        print("Here are the results: ")
        collection.search_song(title_search, year_search, artist_search,
                               status_search)
        print(SongCollection.format_data(collection.search_list))
        choice = handle_text("Continue? (Y/N): ", is_bool=True)
        if not choice:
            collection.search_list = []
            flag = True