Example #1
0
 def read_csv_file(self):
     try:
         csvfile = open(self.file_name, encoding='utf-8-sig', newline='')
         reader = csv.DictReader(csvfile)
         for row in reader:
             try:
                 movie = Movie(row['Title'].strip(),
                               int(row['Year'].strip()))
                 movie.description = row['Description']
                 director = Director(row['Director'].strip())
                 movie.director = director
                 director.add_movie(movie)
                 actors = {
                     Actor(actor.strip())
                     for actor in row['Actors'].split(",")
                 }
                 for actor in actors:
                     movie.add_actor(actor)
                     actor.add_movie(movie)
                 genres = {
                     Genre(genre.strip())
                     for genre in row['Genre'].split(",")
                 }
                 for genre in genres:
                     movie.add_genre(genre)
                     genre.add_movie(movie)
                 movie.runtime_minutes = int(row['Runtime (Minutes)'])
                 movie.rating = float(row['Rating'])
                 movie.votes = int(row['Votes'])
                 self.movies.append(movie)
                 self.actors.update(set(actors))
                 self.directors.add(director)
                 self.genres.update(set(genres))
             except:
                 continue  # Skips movies with invalid formatting
         csvfile.close()
     except:
         raise Exception("Error while reading CSV file!")
def test_user_watch_movie(user):
	movie = Movie("Imception", 2011)
	movie.runtime_minutes = 120
	user.watch_movie(movie)
	assert movie in user.watched_movies
	assert user.time_spent_watching_movies_minutes == movie.runtime_minutes