Update quotes in CLI tutorial

This commit is contained in:
Roman Mogylatov 2021-09-29 17:46:35 -04:00
parent d8bb4a3bd8
commit 2d006d5326

View File

@ -160,19 +160,19 @@ Second put next in the ``fixtures.py``:
SAMPLE_DATA = [ SAMPLE_DATA = [
('The Hunger Games: Mockingjay - Part 2', 2015, 'Francis Lawrence'), ("The Hunger Games: Mockingjay - Part 2", 2015, "Francis Lawrence"),
('Rogue One: A Star Wars Story', 2016, 'Gareth Edwards'), ("Rogue One: A Star Wars Story", 2016, "Gareth Edwards"),
('The Jungle Book', 2016, 'Jon Favreau'), ("The Jungle Book", 2016, "Jon Favreau"),
] ]
FILE = pathlib.Path(__file__) FILE = pathlib.Path(__file__)
DIR = FILE.parent DIR = FILE.parent
CSV_FILE = DIR / 'movies.csv' CSV_FILE = DIR / "movies.csv"
SQLITE_FILE = DIR / 'movies.db' SQLITE_FILE = DIR / "movies.db"
def create_csv(movies_data, path): def create_csv(movies_data, path):
with open(path, 'w') as opened_file: with open(path, "w") as opened_file:
writer = csv.writer(opened_file) writer = csv.writer(opened_file)
for row in movies_data: for row in movies_data:
writer.writerow(row) writer.writerow(row)
@ -181,20 +181,20 @@ Second put next in the ``fixtures.py``:
def create_sqlite(movies_data, path): def create_sqlite(movies_data, path):
with sqlite3.connect(path) as db: with sqlite3.connect(path) as db:
db.execute( db.execute(
'CREATE TABLE IF NOT EXISTS movies ' "CREATE TABLE IF NOT EXISTS movies "
'(title text, year int, director text)' "(title text, year int, director text)"
) )
db.execute('DELETE FROM movies') db.execute("DELETE FROM movies")
db.executemany('INSERT INTO movies VALUES (?,?,?)', movies_data) db.executemany("INSERT INTO movies VALUES (?,?,?)", movies_data)
def main(): def main():
create_csv(SAMPLE_DATA, CSV_FILE) create_csv(SAMPLE_DATA, CSV_FILE)
create_sqlite(SAMPLE_DATA, SQLITE_FILE) create_sqlite(SAMPLE_DATA, SQLITE_FILE)
print('OK') print("OK")
if __name__ == '__main__': if __name__ == "__main__":
main() main()
Now run in the terminal: Now run in the terminal:
@ -266,7 +266,7 @@ Edit ``__main__.py``:
... ...
if __name__ == '__main__': if __name__ == "__main__":
container = Container() container = Container()
main() main()
@ -321,7 +321,7 @@ and put next into it:
self.director = str(director) self.director = str(director)
def __repr__(self): def __repr__(self):
return '{0}(title={1}, year={2}, director={3})'.format( return "{0}(title={1}, year={2}, director={3})".format(
self.__class__.__name__, self.__class__.__name__,
repr(self.title), repr(self.title),
repr(self.year), repr(self.year),
@ -483,9 +483,9 @@ Edit ``__main__.py``:
... ...
if __name__ == '__main__': if __name__ == "__main__":
container = Container() container = Container()
container.config.from_yaml('config.yml') container.config.from_yaml("config.yml")
main() main()
@ -592,9 +592,9 @@ Edit ``__main__.py``:
... ...
if __name__ == '__main__': if __name__ == "__main__":
container = Container() container = Container()
container.config.from_yaml('config.yml') container.config.from_yaml("config.yml")
container.wire(modules=[sys.modules[__name__]]) container.wire(modules=[sys.modules[__name__]])
main() main()
@ -621,18 +621,18 @@ Edit ``__main__.py``:
@inject @inject
def main(lister: MovieLister = Provide[Container.lister]) -> None: def main(lister: MovieLister = Provide[Container.lister]) -> None:
print('Francis Lawrence movies:') print("Francis Lawrence movies:")
for movie in lister.movies_directed_by('Francis Lawrence'): for movie in lister.movies_directed_by("Francis Lawrence"):
print('\t-', movie) print("\t-", movie)
print('2016 movies:') print("2016 movies:")
for movie in lister.movies_released_in(2016): for movie in lister.movies_released_in(2016):
print('\t-', movie) print("\t-", movie)
if __name__ == '__main__': if __name__ == "__main__":
container = Container() container = Container()
container.config.from_yaml('config.yml') container.config.from_yaml("config.yml")
container.wire(modules=[sys.modules[__name__]]) container.wire(modules=[sys.modules[__name__]])
main() main()
@ -718,7 +718,7 @@ Edit ``finders.py``:
def find_all(self) -> List[Movie]: def find_all(self) -> List[Movie]:
with self._database as db: with self._database as db:
rows = db.execute('SELECT title, year, director FROM movies') rows = db.execute("SELECT title, year, director FROM movies")
return [self._movie_factory(*row) for row in rows] return [self._movie_factory(*row) for row in rows]
Now we need to add the sqlite finder to the container and update lister's dependency to use it. Now we need to add the sqlite finder to the container and update lister's dependency to use it.
@ -877,19 +877,19 @@ Edit ``__main__.py``:
@inject @inject
def main(lister: MovieLister = Provide[Container.lister]) -> None: def main(lister: MovieLister = Provide[Container.lister]) -> None:
print('Francis Lawrence movies:') print("Francis Lawrence movies:")
for movie in lister.movies_directed_by('Francis Lawrence'): for movie in lister.movies_directed_by("Francis Lawrence"):
print('\t-', movie) print("\t-", movie)
print('2016 movies:') print("2016 movies:")
for movie in lister.movies_released_in(2016): for movie in lister.movies_released_in(2016):
print('\t-', movie) print("\t-", movie)
if __name__ == '__main__': if __name__ == "__main__":
container = Container() container = Container()
container.config.from_yaml('config.yml') container.config.from_yaml("config.yml")
container.config.finder.type.from_env('MOVIE_FINDER_TYPE') container.config.finder.type.from_env("MOVIE_FINDER_TYPE")
container.wire(modules=[sys.modules[__name__]]) container.wire(modules=[sys.modules[__name__]])
main() main()
@ -963,14 +963,14 @@ and put next into it:
def container(): def container():
container = Container() container = Container()
container.config.from_dict({ container.config.from_dict({
'finder': { "finder": {
'type': 'csv', "type": "csv",
'csv': { "csv": {
'path': '/fake-movies.csv', "path": "/fake-movies.csv",
'delimiter': ',', "delimiter": ",",
}, },
'sqlite': { "sqlite": {
'path': '/fake-movies.db', "path": "/fake-movies.db",
}, },
}, },
}) })
@ -980,23 +980,23 @@ and put next into it:
def test_movies_directed_by(container): def test_movies_directed_by(container):
finder_mock = mock.Mock() finder_mock = mock.Mock()
finder_mock.find_all.return_value = [ finder_mock.find_all.return_value = [
container.movie('The 33', 2015, 'Patricia Riggen'), container.movie("The 33", 2015, "Patricia Riggen"),
container.movie('The Jungle Book', 2016, 'Jon Favreau'), container.movie("The Jungle Book", 2016, "Jon Favreau"),
] ]
with container.finder.override(finder_mock): with container.finder.override(finder_mock):
lister = container.lister() lister = container.lister()
movies = lister.movies_directed_by('Jon Favreau') movies = lister.movies_directed_by("Jon Favreau")
assert len(movies) == 1 assert len(movies) == 1
assert movies[0].title == 'The Jungle Book' assert movies[0].title == "The Jungle Book"
def test_movies_released_in(container): def test_movies_released_in(container):
finder_mock = mock.Mock() finder_mock = mock.Mock()
finder_mock.find_all.return_value = [ finder_mock.find_all.return_value = [
container.movie('The 33', 2015, 'Patricia Riggen'), container.movie("The 33", 2015, "Patricia Riggen"),
container.movie('The Jungle Book', 2016, 'Jon Favreau'), container.movie("The Jungle Book", 2016, "Jon Favreau"),
] ]
with container.finder.override(finder_mock): with container.finder.override(finder_mock):
@ -1004,7 +1004,7 @@ and put next into it:
movies = lister.movies_released_in(2015) movies = lister.movies_released_in(2015)
assert len(movies) == 1 assert len(movies) == 1
assert movies[0].title == 'The 33' assert movies[0].title == "The 33"
Run in the terminal: Run in the terminal: