def test_metascores(self): movie = Movie("Moana", 2016, 7) movie.metascores = "23" assert movie.metascores == 23 movie1 = Movie("Up", 2009, 8) movie1.revenue = "N/A" assert movie1.metascores is None movie2 = Movie("", 0, 1) movie2.metascores = 41 assert movie2.metascores == 41 movie3 = Movie("", 0, 1) movie3.metascores = -2 assert movie3.metascores is None
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: title = row['Title'] release_year = int(row['Year']) actors = row['Actors'].split(",") genres = row['Genre'].split(",") director = Director(row['Director']) rating = row['Rating'] votes = row['Votes'] revenue = row['Revenue (Millions)'] metascore = row['Metascore'] movie = Movie(title, release_year, index + 1) movie.director = director # extension attribute application movie.external_rating = rating movie.rating_votes = votes movie.revenue = revenue movie.metascores = metascore # adding the actors, genres, director and the movie to the corresponding datasets for i in range(len(actors)): actor = Actor(actors[i]) movie.add_actor(actor) if actor not in self.__dataset_of_actors: # adding only unique actors to the dataset self.__dataset_of_actors.add(actor) for i in range(len(genres)): genre = Genre(genres[i]) movie.add_genre(genre) if genre not in self.__dataset_of_genres: # adding only unique genres to the dataset self.__dataset_of_genres.add(genre) if movie.director not in self.__dataset_of_directors: # adding only unique directors to the dataset self.__dataset_of_directors.add(movie.director) self.__dataset_of_movies.append(movie) index += 1