diff --git a/__pycache__/main.cpython-313.pyc b/__pycache__/main.cpython-313.pyc new file mode 100644 index 0000000..7e179ef Binary files /dev/null and b/__pycache__/main.cpython-313.pyc differ diff --git a/__pycache__/tests.cpython-313-pytest-8.4.2.pyc b/__pycache__/tests.cpython-313-pytest-8.4.2.pyc new file mode 100644 index 0000000..22093bd Binary files /dev/null and b/__pycache__/tests.cpython-313-pytest-8.4.2.pyc differ diff --git a/main.py b/main.py index d3e0a17..8286cdf 100644 --- a/main.py +++ b/main.py @@ -54,4 +54,4 @@ def delete_book_from_favorites(self, name): # получаем список Избранных книг def get_list_of_favorites_books(self): - return self.favorites + return self.favorites \ No newline at end of file diff --git a/tests.py b/tests.py index 383385e..1d23d32 100644 --- a/tests.py +++ b/tests.py @@ -1,24 +1,63 @@ +# -*- coding: utf-8 -*- from main import BooksCollector +import pytest + + +@pytest.fixture +def books(): + return BooksCollector() + -# класс TestBooksCollector объединяет набор тестов, которыми мы покрываем наше приложение BooksCollector -# обязательно указывать префикс Test class TestBooksCollector: - # пример теста: - # обязательно указывать префикс test_ - # дальше идет название метода, который тестируем add_new_book_ - # затем, что тестируем add_two_books - добавление двух книг - def test_add_new_book_add_two_books(self): - # создаем экземпляр (объект) класса BooksCollector - collector = BooksCollector() + @pytest.mark.parametrize('name', ['The Witcher', 'The Witcher 2', 'Sherlock']) + def test_add_new_book(self, books, name): + check = len(books.books_genre) + books.add_new_book(name) + assert check + 1 == len(books.books_genre) + + @pytest.mark.parametrize('name,genre', [['The Witcher', 'Фантастика'], ['The Witcher 2', 'Фантастика'], + ['Sherlock', 'Детективы']]) + def test_set_book_genre(self, books, name, genre): + if name not in books.books_genre: + books.add_new_book(name) + books.set_book_genre(name, genre) + print(books.books_genre) + assert books.books_genre[name] == genre + + def test_get_book_genre(self, books): + books.add_new_book('The Witcher') + books.set_book_genre('The Witcher', 'Фантастика') + assert books.get_book_genre('The Witcher') == 'Фантастика' + + def test_get_books_with_specific_genre(self, books): + books.books_genre = {'Sherlock': 'Детективы', 'The Witcher 2': 'Фантастика', 'The Witcher': 'Фантастика'} + result = len(books.get_books_with_specific_genre('Фантастика')) + assert result == 2 + + def test_get_books_genre(self, books): + books.books_genre = {'Sherlock': 'Детективы', 'The Witcher 2': 'Фантастика', 'The Witcher': 'Фантастика'} + assert books.get_books_genre() == books.books_genre + + def test_get_books_for_children(self, books): + books.books_genre = {'Sherlock': 'Детективы', 'The Witcher 2': 'Фантастика', 'The Witcher': 'Фантастика'} + children_books = {'The Witcher', 'The Witcher 2'} + result = books.get_books_for_children() + assert set(result) == children_books - # добавляем две книги - collector.add_new_book('Гордость и предубеждение и зомби') - collector.add_new_book('Что делать, если ваш кот хочет вас убить') + def test_add_book_in_favorites(self, books): + books.books_genre = {'Sherlock': 'Детективы', 'The Witcher 2': 'Фантастика', 'The Witcher': 'Фантастика'} + books.add_book_in_favorites('The Witcher 2') + assert 'The Witcher 2' in books.favorites - # проверяем, что добавилось именно две - # словарь books_rating, который нам возвращает метод get_books_rating, имеет длину 2 - assert len(collector.get_books_rating()) == 2 + def test_delete_book_from_favorites(self, books): + books.books_genre = {'Sherlock': 'Детективы', 'The Witcher 2': 'Фантастика', 'The Witcher': 'Фантастика'} + books.add_book_in_favorites('The Witcher 2') + books.delete_book_from_favorites('The Witcher 2') + assert 'The Witcher 2' not in books.favorites - # напиши свои тесты ниже - # чтобы тесты были независимыми в каждом из них создавай отдельный экземпляр класса BooksCollector() \ No newline at end of file + def test_get_list_of_favorites_books(self, books): + books.books_genre = {'Sherlock': 'Детективы', 'The Witcher 2': 'Фантастика', 'The Witcher': 'Фантастика'} + books.add_book_in_favorites('The Witcher 2') + books.add_book_in_favorites('The Witcher') + assert books.get_list_of_favorites_books() == ['The Witcher 2', 'The Witcher']