forked from pytest-dev/pytest-bdd
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bcc1408
commit 7ef30de
Showing
3 changed files
with
44 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,27 @@ | ||
"""This files represents simple `Application under test`""" | ||
from typing import List | ||
from dataclasses import dataclass, field | ||
from typing import Iterable, List | ||
|
||
from attr import Factory, attrib, attrs | ||
|
||
|
||
@attrs | ||
@dataclass # Easy way to not write redundant __init__ https://docs.python.org/3/library/dataclasses.html | ||
class Book: | ||
author = attrib(type=str) | ||
title = attrib(type=str) | ||
author: str | ||
title: str | ||
|
||
|
||
@attrs | ||
@dataclass | ||
class Catalog: | ||
storage = attrib(default=Factory(list)) | ||
storage: List[Book] = field(default_factory=list) | ||
|
||
def add_books_to_catalog(self, books: List[Book]): | ||
def add_books_to_catalog(self, books: Iterable[Book]): | ||
self.storage.extend(books) | ||
|
||
def search_by_author(self, term: str): | ||
return filter(lambda book: term in book.author, self.storage) | ||
for book in self.storage: | ||
if term in book.author: | ||
yield book | ||
|
||
def search_by_title(self, term: str): | ||
return filter(lambda book: term in book.title, self.storage) | ||
for book in self.storage: | ||
if term in book.title: | ||
yield book |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters