示例#1
0
    def _read_row(self, row: _ROW, id_: int) -> Movie:
        """
        Helper method to construct a Movie from a row.

        Raises:
            ValueError: unable to parse row: {row}
         """
        error = False

        try:
            title = row['Title']
            genres = [
                self._get_genre(Genre(name))
                for name in row['Genre'].split(',')
            ]
            description = row['Description']
            director = self._get_director(Director(row['Director']))
            actors = [
                self._get_actor(Actor(name))
                for name in row['Actors'].split(',')
            ]
            release_year = int(row['Year'])
            runtime_minutes = int(row['Runtime (Minutes)'])
            rating = float(row['Rating'])
            votes = int(row['Votes'])
            revenue_millions = float(
                row['Revenue (Millions)']
            ) if row['Revenue (Millions)'] != 'N/A' else None
            metascore = int(
                row['Metascore']) if row['Metascore'] != 'N/A' else None
        except KeyError:
            error = True
        except ValueError:
            error = True

        if error:
            raise ValueError(f'unable to parse row: {row}')

        movie = Movie(title, release_year, id_)
        movie.genres = genres
        movie.description = description
        movie.director = director
        movie.actors = actors
        movie.runtime_minutes = runtime_minutes
        movie.rating = rating
        movie.votes = votes

        if revenue_millions:
            movie.revenue_millions = revenue_millions

        if metascore:
            movie.metascore = metascore

        return movie
示例#2
0
def test_loading_of_directors(empty_session):
    directors = ["Andrew", "Cindy"]
    insert_directors(empty_session, directors)

    expected = [Director("Andrew"), Director("Cindy")]
    assert empty_session.query(Director).all() == expected
示例#3
0
def directors():
    return [Director(f'Director{i}') for i in range(10)]
示例#4
0
def director():
    return Director("Firstname Lastname")
def test_constructor_with_empty_string_full_name():
    director = Director("")
    assert director.director_full_name is None
def test_hash_changes(director):
    other = Director("123")
    assert hash(director) != hash(other)
def test_less_than_when_false(director):
    a = Director("a")
    b = Director("b")
    assert not (b < a)
def test_less_than_when_true(director):
    a = Director("a")
    b = Director("b")
    assert a < b
def test_constructor():
    director = Director("123")
    assert director.director_full_name == "123"
def test_equality_when_not_equal(director):
    other = Director("Firstname2 Lastname2")
    assert director != other
def test_equality_when_equal(director):
    other = Director("Firstname Lastname")
    assert director == other
def test_repr_with_no_name():
    director = Director("")
    assert repr(director) == "<Director None>"
def test_constructor_strips_whitespace():
    director = Director("        Firstname Lastname      ")
    assert director.director_full_name == "Firstname Lastname"
def test_constructor_with_non_string_full_name():
    director = Director(42)
    assert director.director_full_name is None