Exemple #1
0
 def test_add_rating_vote(self):
     movie = Movie("Moana", 2016, 7)
     movie.rating_votes = 5
     movie.external_rating = 6.2
     movie.add_rating_vote(8)
     print()
     print(f"Number of votes: {movie.rating_votes}")
     print(f"New rating for the movie: {movie.external_rating}")
     assert movie.external_rating == 6.5
     movie2 = Movie("ABC", 2016, 2)
     movie2.rating_votes = "2"
     movie2.external_rating = "2.5"
     movie2.add_rating_vote(10)
     assert movie2.external_rating == 5
     movie3 = Movie("", 0, 5)
     movie3.rating_votes = -1
     movie3.external_rating = "-2"
     movie3.add_rating_vote(10)
     assert movie3.external_rating == 10
    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