Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

THe code I have so far in python: from datetime import date class Song: def __init__(self, title: str, artist: str, album: str, date_added: str, runtime:

THe code I have so far in python:

from datetime import date class Song: def __init__(self, title: str, artist: str, album: str, date_added: str, runtime: str, file_path: str, file_name: str): try: self._title = title self._artist = artist self._album = album self._date_added = date_added self._runtime = runtime self._file_path = file_path self._file_name = file_name except ValueError: print("Value Error!") exit(1) self._count = 0 self._last_played = "" self._user_rating = "" def count(self): self._count = self._count + 1 self._last_played = date.today() def get_user_rating(self): return self._user_rating def set_user_rating(self, rating: str): try: self._user_rating = rating except ValueError: print("Value Error!") exit(1) def song_description(self): if self._user_rating == "": desc = "{} by {} from the album {} added on {}. Runtime is {}. " \ "Last played on {}.".format(self._title, self._artist, self._album, self._date_added, self._runtime, self._last_played) else: desc = "{} by {} from the album {} added on {}. Runtime is {}. " \ "Last played on {}. User rating is ".format(self._title, self._artist, self._album, self._date_added, self._runtime, self._last_played, self._user_rating) return desc THe tests I need to run are 
  • Example:

Crazy by Gnarls Barkley from the album St. Elsewhere added on 2019-09-01. Runtime is 3:02.

Where the items in bold describe a specific song on the playlist (title, artist, album, date added, runtime). These items must always be set for the song (i.e., they cannot be undefined or empty).

  • A way to get the location of the audio file. This returns the pathname and filename for the audio file. This information must be set when the Song is created, and cannot be undefined or empty.
  • Ability to update the play count for the song, ie, the number of times this song has been played.
  • A way to get and set a user rating for the song.
  • The description of the song should show like this after it has been played:

Crazy by Gnarls Barkley from the album St. Elsewhere added on 2019-09-01. Runtime is 3:02. Last played on 2019-09-16.

... and like this after it has been rated ...

Crazy by Gnarls Barkley from the album St. Elsewhere added on 2019-09-01. Runtime is 3:02. Last played on 2019-09-16. User rating is 3/5.

  • A way to play the song (currently this will do nothing more than update the last played date and the play count).

I then need to test it with:

should pass in (to the constructor) the full pathname to the mp3 file, for example: "C:\Users\man\Music\crazy.mp3", and the file should really exist (ie: you should check for file existence using os.path.exists()). If you want to make your testing repeatable, create a folder called Music in your PyCharm project, and the use a relative path for testing, such as ".\Music\crazy.mp3".

the instructions do not call for a way to retrieve the play count, but you should probably make play_count a property, or add a get_playcount() method - otherwise there is no way to check that it increments correctly.

Instructions:

  • Create a new main Python script for the testing of your class. The file should be called main.py and have a main function.
    • Make sure you import your Song class
  • Create tests for each of the public methods in your class, including your constructor.
    • Make sure to cover all success cases for the method. This is where the method returns an expected result.
    • Cover at least one error case for the methods that take in parameters. An example is if you pass in an invalid parameter where an exception should be raised

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing Fundamentals, Design, and Implementation

Authors: David M. Kroenke, David J. Auer

14th edition

133876705, 9781292107639, 1292107634, 978-0133876703

More Books

Students also viewed these Databases questions

Question

1. Which is the most abundant gas presented in the atmosphere?

Answered: 1 week ago

Question

=+and non-compete agreements in three to five different countries.

Answered: 1 week ago