Coverage report: + 100% +
+ + ++ Files + Functions + Classes +
++ coverage.py v7.11.3, + created at 2026-01-01 21:26 +0500 +
+diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..8b107e6b5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,216 @@ + +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[codz] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py.cover +.hypothesis/ +.pytest_cache/ +cover/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +.pybuilder/ +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +# Pipfile.lock + +# UV +# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control. +# This is especially recommended for binary packages to ensure reproducibility, and is more +# commonly ignored for libraries. +# uv.lock + +# poetry +# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. +# This is especially recommended for binary packages to ensure reproducibility, and is more +# commonly ignored for libraries. +# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control +# poetry.lock +# poetry.toml + +# pdm +# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. +# pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python. +# https://pdm-project.org/en/latest/usage/project/#working-with-version-control +# pdm.lock +# pdm.toml +.pdm-python +.pdm-build/ + +# pixi +# Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control. +# pixi.lock +# Pixi creates a virtual environment in the .pixi directory, just like venv module creates one +# in the .venv directory. It is recommended not to include this directory in version control. +.pixi + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# Redis +*.rdb +*.aof +*.pid + +# RabbitMQ +mnesia/ +rabbitmq/ +rabbitmq-data/ + +# ActiveMQ +activemq-data/ + +# SageMath parsed files +*.sage.py + +# Environments +.env +.envrc +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ + +# PyCharm +# JetBrains specific template is maintained in a separate JetBrains.gitignore that can +# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore +# and can be added to the global gitignore or merged into this file. For a more nuclear +# option (not recommended) you can uncomment the following to ignore the entire idea folder. +# .idea/ + +# Abstra +# Abstra is an AI-powered process automation framework. +# Ignore directories containing user credentials, local state, and settings. +# Learn more at https://abstra.io/docs +.abstra/ + +# Visual Studio Code +# Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore +# that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore +# and can be added to the global gitignore or merged into this file. However, if you prefer, +# you could uncomment the following to ignore the entire vscode folder +# .vscode/ + +# Ruff stuff: +.ruff_cache/ + +# PyPI configuration file +.pypirc + +# Marimo +marimo/_static/ +marimo/_lsp/ +__marimo__/ + +# Streamlit +.streamlit/secrets.toml diff --git a/htmlcov/.gitignore b/htmlcov/.gitignore new file mode 100644 index 000000000..ccccf1423 --- /dev/null +++ b/htmlcov/.gitignore @@ -0,0 +1,2 @@ +# Created by coverage.py +* diff --git a/htmlcov/class_index.html b/htmlcov/class_index.html new file mode 100644 index 000000000..f6f54d887 --- /dev/null +++ b/htmlcov/class_index.html @@ -0,0 +1,139 @@ + + +
+ ++ coverage.py v7.11.3, + created at 2026-01-01 21:26 +0500 +
+| File | +class | +statements | +missing | +excluded | +coverage | +
|---|---|---|---|---|---|
| tests\conftest.py | +(no class) | +30 | +0 | +0 | +100% | +
| tests\data.py | +(no class) | +6 | +0 | +0 | +100% | +
| tests\test_burger.py | +TestBurger | +26 | +0 | +0 | +100% | +
| tests\test_burger.py | +(no class) | +10 | +0 | +0 | +100% | +
| Total | ++ | 72 | +0 | +0 | +100% | +
+ No items found using the specified filter. +
++ coverage.py v7.11.3, + created at 2026-01-01 21:26 +0500 +
++ No items found using the specified filter. +
++ coverage.py v7.11.3, + created at 2026-01-01 21:26 +0500 +
+| File | +statements | +missing | +excluded | +coverage | +
|---|---|---|---|---|
| tests\conftest.py | +30 | +0 | +0 | +100% | +
| tests\data.py | +6 | +0 | +0 | +100% | +
| tests\test_burger.py | +36 | +0 | +0 | +100% | +
| Total | +72 | +0 | +0 | +100% | +
+ No items found using the specified filter. +
++ « prev + ^ index + » next + + coverage.py v7.11.3, + created at 2026-01-01 21:26 +0500 +
+ +1import pytest
+ +3from unittest.mock import Mock
+ +5from praktikum.burger import Burger
+6from praktikum.bun import Bun
+7from praktikum.ingredient import Ingredient
+8from praktikum import ingredient_types
+9from data import BUN_NAME, BUN_PRICE, FILLING_NAME, FILLING_PRICE, SAUCE_NAME, SAUCE_PRICE
+ + +12@pytest.fixture
+13def burger():
+14 return Burger()
+ + +17@pytest.fixture()
+18def mock_bun():
+19 mock_bun = Mock(spec=Bun)
+20 mock_bun.get_name.return_value = BUN_NAME
+21 mock_bun.get_price.return_value = BUN_PRICE
+22 return mock_bun
+ + +25@pytest.fixture()
+26def mock_filling():
+27 mock_filling = Mock(spec=Ingredient)
+28 mock_filling.get_type.return_value = ingredient_types.INGREDIENT_TYPE_FILLING
+29 mock_filling.get_name.return_value = FILLING_NAME
+30 mock_filling.get_price.return_value = FILLING_PRICE
+31 return mock_filling
+ + +34@pytest.fixture()
+35def mock_sauce():
+36 mock_sauce = Mock(spec=Ingredient)
+37 mock_sauce.get_type.return_value = ingredient_types.INGREDIENT_TYPE_SAUCE
+38 mock_sauce.get_name.return_value = SAUCE_NAME
+39 mock_sauce.get_price.return_value = SAUCE_PRICE
+40 return mock_sauce
++ « prev + ^ index + » next + + coverage.py v7.11.3, + created at 2026-01-01 21:26 +0500 +
+ +1BUN_NAME = "black bun"
+2BUN_PRICE = 100
+3SAUCE_NAME = "sour cream"
+4SAUCE_PRICE = 200
+5FILLING_NAME = "sausage"
+6FILLING_PRICE = 300
++ « prev + ^ index + » next + + coverage.py v7.11.3, + created at 2026-01-01 21:26 +0500 +
+ +1import pytest
+ + +4class TestBurger:
+ +6 def test_initial_state(self, burger):
+7 """Тестирование начального состояния нового бургера."""
+8 assert burger.bun is None
+9 assert burger.ingredients == []
+ +11 def test_set_buns(self, burger, mock_bun):
+12 """Проверяем установку булочки в бургер."""
+13 burger.set_buns(mock_bun)
+14 assert burger.bun == mock_bun
+ +16 @pytest.mark.parametrize("ingredient_fixture", ["mock_sauce", "mock_filling"])
+17 def test_add_ingredient(self, burger, ingredient_fixture, request):
+18 """Тестирование метода добавления ингредиентов в бургер."""
+19 ingredient = request.getfixturevalue(ingredient_fixture)
+20 assert burger.ingredients == []
+21 burger.add_ingredient(ingredient)
+22 assert len(burger.ingredients) == 1
+23 assert burger.ingredients[0] == ingredient
+ +25 def test_remove_ingredient(self, burger, mock_sauce, mock_filling):
+26 """Тестирование метода удаления ингредиента из бургера."""
+27 burger.ingredients = [mock_sauce, mock_filling]
+28 assert len(burger.ingredients) == 2
+29 burger.remove_ingredient(0)
+30 assert len(burger.ingredients) == 1
+31 assert burger.ingredients[0] == mock_filling
+ +33 def test_get_price(self, burger, mock_bun, mock_filling, mock_sauce):
+34 """Тестирование метода получения цены."""
+35 burger.bun = mock_bun
+36 burger.ingredients = [mock_filling, mock_sauce]
+37 expected_price = (
+38 mock_bun.get_price() * 2
+39 + mock_filling.get_price()
+40 + mock_sauce.get_price()
+41 )
+42 assert burger.get_price() == expected_price
+ +44 def test_get_receipt(self, burger, mock_bun, mock_filling, mock_sauce):
+45 """Тестирование метода получения чека."""
+46 burger.bun = mock_bun
+47 burger.ingredients = [mock_filling, mock_sauce]
+48 expected_price = (
+49 mock_bun.get_price() * 2
+50 + mock_filling.get_price()
+51 + mock_sauce.get_price()
+52 )
+53 expected_receipt = (
+54 f"(==== {mock_bun.get_name()} ====)\n"
+55 f"= {mock_filling.get_type().lower()} {mock_filling.get_name()} =\n"
+56 f"= {mock_sauce.get_type().lower()} {mock_sauce.get_name()} =\n"
+57 f"(==== {mock_bun.get_name()} ====)\n"
+58 f"\n"
+59 f"Price: {expected_price}"
+60 )
+61 assert burger.get_receipt() == expected_receipt
+ +63 def test_move_ingredient(self, burger, mock_sauce, mock_filling):
+64 """Тестирование метода перемещения ингредиентов в бургере."""
+65 burger.ingredients = [mock_sauce, mock_filling]
+66 burger.move_ingredient(0, 1)
+67 assert burger.ingredients == [mock_filling, mock_sauce]
+