Пример #1
0
def load_movies(data_path: str, repo: MemoryRepository):
    movies = dict()

    for data_row in read_csv_file(os.path.join(data_path, 'Data1000Movies.csv')):
        movie = Movie(
            rank=int(data_row[0]),
            title=data_row[1].strip(),
            release_year=int(data_row[6]),
            description=data_row[3].strip()
        )

        actors = data_row[5]
        actors = actors.split(',')
        for actor in actors:
            actor = actor.strip()
            if Actor(actor) not in movie.actors:
                movie.add_actor(Actor(actor))

        genres = data_row[2]
        genres = genres.split(',')
        for genre in genres:
            genre = genre.strip()
            if Genre(genre) not in movie.genres:
                movie.add_genre(Genre(genre))

        director = data_row[4]
        director = director.strip()
        movie.director = Director(director)

        repo.add_movie(movie)
        movies[data_row[0]] = movie
    return movies
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_director():
    movie1 = Movie("Spirited Away", 2000)
    movie2 = Movie("Your Name", 2000)
    movie3 = Movie("Batman", 2000)
    movie4 = Movie(None, None)

    movie1.director = Director("BB Huang")
    assert movie1.director == Director("BB Huang")
    movie1.director = Director("Jack Huang")
    assert movie1.director == Director("Jack Huang")
    movie2.director = "Jack Huang"
    assert movie2.director == None
    movie3.director = 123456
    assert movie3.director == None
    movie3.director = None
    assert movie4.director == None
Пример #4
0
def test_get_movie_by_director(in_memory_repo):
    assert in_memory_repo.get_movie_by_director('M. Night Shyamalan') == [
        Movie(
            3, 'Split', 2016, "Three girls are\
                                                                        kidnapped by a man with a diagnosed 23 \
                                                                        distinct personalities. They must try to \
                                                                        escape before the apparent emergence of \
                                                                        a frightful new 24th."
        )
    ]
    movie1 = Movie(11, '1', 2000, "b")
    movie2 = Movie(12, '2', 3000, "a")
    director1 = Director('a')
    movie1.director = director1
    movie2.director = director1
    in_memory_repo.add_movie(movie1)
    in_memory_repo.add_movie(movie2)
    assert in_memory_repo.get_movie_by_director('a') == [movie1, movie2]
def movie():
    m = Movie(
        1,
        "Guardians of the Galaxy",
        "It's a nice movies",
        2020,
        120,
        66.8,
        23424,
        122.7,
        76
    )
    m.director = 'Denis Villeneuve'
    return m
Пример #6
0
    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