def test_runtime(): movie1 = Movie("Spirited Away", 2000) movie2 = Movie("Your Name", 2000) movie3 = Movie("Batman", 2000) movie4 = Movie(None, None) movie1.runtime_minutes = 150 assert movie1.runtime_minutes == 150 movie2.runtime_minutes = 1 assert movie2.runtime_minutes == 1 movie3.runtime_minutes = "150" assert movie3.runtime_minutes == 0 movie4.runtime_minutes = None assert movie4.runtime_minutes == 0
def test_code_runner(): movie = Movie("Moana", 2016) assert movie.title == "Moana" assert movie.release_year == 2016 director = Director("Ron Clements") movie.director = director assert movie.director == Director("Ron Clements") actors = [ Actor("Auli'i Cravalho"), Actor("Dwayne Johnson"), Actor("Rachel House"), Actor("Temuera Morrison") ] for actor in actors: movie.add_actor(actor) assert movie.actors == [ Actor("Auli'i Cravalho"), Actor("Dwayne Johnson"), Actor("Rachel House"), Actor("Temuera Morrison") ] movie.runtime_minutes = 107 assert movie.runtime_minutes == 107
def test_add_movies_and_length(): user = User("Jack Huang", "123124") movie1 = Movie("Your Name", 2000) movie2 = Movie("Spirited Away", 1995) movie3 = Movie("Avengers 4", 1899) movie1.runtime_minutes = 100 movie2.runtime_minutes = 150 movie3.runtime_minutes = 300 assert user.watched_movies == [] user.watch_movie(movie1) user.watch_movie(movie2) user.watch_movie(movie3) assert user.watched_movies == [ Movie("Your Name", 2000), Movie("Spirited Away", 1995), Movie("Avengers 4", None) ] assert user.time_spent_watching_movies_minutes == 550
def read_csv_file(self): with open(self.__file_name, mode='r', encoding='utf-8-sig') as csvfile: movie_file_reader = csv.DictReader(csvfile) index = 0 for row in movie_file_reader: # Read in Title title = row['Title'] # Read in Year release_year = int(row['Year']) movie = Movie(title, release_year) self.__dataset_of_movies.append(movie) # Read in description description = row["Description"] movie.description = description # Read in runtime runtime = row["Runtime (Minutes)"] movie.runtime_minutes = int(runtime) # Read in Actors actors = row['Actors'] actor = actors.split(",") for i in actor: actor = i.strip() movie.add_actor(Actor(actor)) self.__dataset_of_actors.add(Actor(actor)) # Read in Directors director = row['Director'] movie.director = Director(director) self.__dataset_of_directors.add(Director(director)) # Read in Genre genres = row['Genre'] genre = genres.split(",") for i in genre: a = i.strip() movie.add_genre(Genre(a)) self.__dataset_of_genres.add(Genre(a)) # Read in Rank rank = row["Rank"] movie.rank = rank # Read in Rating rating = row["Rating"] movie.rating = rating # Read in Votes vote = row["Votes"] movie.votes = vote # Read in revenue revenue = row["Revenue (Millions)"] movie.revenue = revenue # Read in meta_scores metascore = row["Metascore"] movie.metascore = metascore index += 1