def test_eq(self): director1 = Director("Taika Waititi") director2 = Director("Ben Zebra") director3 = Director("Taika Waititi") assert (director1 == director3) == True assert (director1 == director2) == False # Yes, I know I could do !=
def test_init_and_repr(self): director1 = Director("Taika Waititi") assert repr(director1) == "<Director Taika Waititi>" director2 = Director("") assert director2.director_full_name is None director3 = Director(42) assert director3.director_full_name is None
def test_setters(self): # inherently tests getters too a_movie = Movie("Back To The Future", 1965) director1 = Director("Brad Bird") a_movie.title = " Mission Impossible: Ghost Protocol " assert a_movie.title == "Mission Impossible: Ghost Protocol" a_movie.title = 15 #assert a_movie.title == "Mission Impossible: Ghost Protocol" a_movie.description = " An action movie " assert a_movie.description == "An action movie" a_movie.director = director1 assert a_movie.director == director1 actor1 = Actor("Tom Cruise") actor2 = Actor("Simon Pegg") a_movie.actors = [actor1, actor2] assert a_movie.actors == [actor1, actor2] genre1 = Genre("Action") genre2 = Genre("Comedy") a_movie.genres = [genre1, genre2] assert a_movie.genres == [genre1, genre2] a_movie.runtime_minutes = 100 assert a_movie.runtime_minutes == 100 assert type(a_movie.runtime_minutes) == int with pytest.raises(ValueError): a_movie.runtime_minutes = 0 a_movie.runtime_minutes = -10
def a_movie(): # these values are half made up a_movie = Movie("Guardians", 2014) a_movie.runtime_minutes = 100 a_movie.description = "descriptiongoeshere" a_movie.director = Director("James Gunn") a_movie.actors = [ Actor("Chris Pratt"), Actor("Vin Diesel"), Actor("Bradley Cooper") ] a_movie.genres = [Genre("Action"), Genre("Adventure"), Genre("Sci-Fi")] a_movie.external_rating = 8.1 a_movie.external_rating_votes = 31204 a_movie.revenue = 301 a_movie.metascore = 74 return a_movie
def read_csv_file(self): # this assumes there aren't repeated actors, genres, or movies (i.e. not a entry with same: release year and movie title) with open(self.__file_name, mode='r', encoding='utf-8-sig') as csvfile: movie_file_reader = csv.DictReader(csvfile) self.__dataset_of_movies = list() self.__dataset_of_actors = list() self.__dataset_of_directors = list() self.__dataset_of_genres = list() index = 0 for row in movie_file_reader: title = row['Title'].strip() # stripping to safe release_year = int(row['Year']) actor_full_name_list = get_list_from_comma_string(row['Actors']) director_full_name = row['Director'].strip() # stripping to safe genre_name_list = get_list_from_comma_string(row['Genre']) #- other things rank = int(row['Rank']) description = row['Description'] runtime_minutes = int(row['Runtime (Minutes)']) external_rating = float(row['Rating']) external_rating_votes = int(row['Votes']) # These require try/except because some values are N/A's (preferably all would but it's SUPER ugly code) try: revenue = float(row['Revenue (Millions)']) except: revenue = None try: metascore = int(row['Metascore']) except: metascore = None #-------- Make Actor, Director and Genre Objects actor_object_list = [Actor(actor_full_name) for actor_full_name in actor_full_name_list] # add actor colleagues, who are the actors who are in the movie with them (i.e. add all other actors to colleagues for all actors) for actor in actor_object_list: for potential_actor_colleague in actor_object_list: # potential because one of them is them if actor != potential_actor_colleague: actor.add_actor_colleague(potential_actor_colleague) director_object = Director(director_full_name) genre_object_list = [Genre(genre_name) for genre_name in genre_name_list] #-------- Create and set up Movie Object movie_object = Movie(title, release_year) movie_object.actors = actor_object_list # thanks to my setter implementation movie_object.director = director_object movie_object.genres = genre_object_list # ^ ditto movie_object.release_year = release_year #- other things movie_object.description = description movie_object.runtime_minutes = runtime_minutes movie_object.external_rating = external_rating movie_object.external_rating_votes = external_rating_votes if revenue != None: movie_object.revenue = revenue if metascore != None: movie_object.metascore = metascore #-------- Take all the above information, and add to datasets self.__dataset_of_movies.append(movie_object) # the assumption is that each row in the csv is a unique movie # I could create a function that adds unique things to lists only, nvm for actor_object in actor_object_list: if actor_object not in self.__dataset_of_actors: self.__dataset_of_actors.append(actor_object) if director_object not in self.__dataset_of_directors: self.__dataset_of_directors.append(director_object) for genre_object in genre_object_list: if genre_object not in self.__dataset_of_genres: self.__dataset_of_genres.append(genre_object) index += 1 # To test my assigmnent, run the following lines of code (I have copy and pasted these in my test_all.py file too) #movie_file_csv_reader_object = MovieFileCSVReader(r"C:\Users\Nathan Longhurst\OneDrive - The University of Auckland\b Comp235\Assignment\GitHub Clone (Current)\CS235FlixSkeleton\datafiles\Data1000Movies.csv") #unclean_dict = movie_file_csv_reader_object.check_csv_file() #movie_file_csv_reader_object.clean_csv_file(unclean_dict)
def test_hash(self): director1 = Director("Taika Waititi") director2 = Director("Ben Zebra") assert (hash(director1) == hash(director2) ) == False # two hashes ?shouldn't? be the same
def test_lt(self): director1 = Director("Taika Waititi") director2 = Director("Ben Zebra") assert (director2 < director1) == True # expect Ben to be less than Taika