-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Перенесён код в пакет praktikum, добавлены тесты и исправлен формат чека #672
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Alexander-Startsev
wants to merge
1
commit into
Yandex-Practicum:main
Choose a base branch
from
Alexander-Startsev:develop1
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Empty file.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
File renamed without changes.
This file contains hidden or 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
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| [pytest] | ||
| addopts = -q --maxfail=1 | ||
| testpaths = tests | ||
| pythonpath = . |
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| pytest==8.4.2 | ||
| pytest-cov==7.0.0 |
Binary file not shown.
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Необходимо исправить: эта директория лишняя в проекте. Необходимо убрать её из ветки и добавить в .gitignore в корне проекта |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+1.65 KB
tests/__pycache__/test_burger_price_param.cpython-310-pytest-8.3.2.pyc
Binary file not shown.
Binary file added
BIN
+1.63 KB
tests/__pycache__/test_burger_price_param.cpython-310-pytest-8.4.2.pyc
Binary file not shown.
Binary file added
BIN
+2.39 KB
tests/__pycache__/test_burger_price_param.cpython-312-pytest-8.4.2.pyc
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| from unittest.mock import MagicMock | ||
|
|
||
| import pytest | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def mk_ing(): | ||
| def _make(label: str, *, price: int = 1, type_: str = "FILLING"): | ||
| ing = MagicMock() | ||
| ing.get_name.return_value = label | ||
| ing.get_price.return_value = price | ||
| ing.get_type.return_value = type_ | ||
| return ing | ||
|
|
||
| return _make |
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| from praktikum.burger import Burger | ||
|
|
||
|
|
||
| class TestBurgerMutations: | ||
| def test_add_ingredient_appends_to_list(self, mk_ing): | ||
| burger = Burger() | ||
| ingredient = mk_ing("A") | ||
|
|
||
| burger.add_ingredient(ingredient) | ||
|
|
||
| assert [item.get_name() for item in burger.ingredients] == ["A"] | ||
|
|
||
| def test_remove_ingredient_by_index(self, mk_ing): | ||
| burger = Burger() | ||
| burger.add_ingredient(mk_ing("A")) | ||
| burger.add_ingredient(mk_ing("C")) | ||
| burger.add_ingredient(mk_ing("D")) | ||
|
|
||
| burger.remove_ingredient(1) | ||
|
|
||
| assert [item.get_name() for item in burger.ingredients] == ["A", "D"] | ||
|
|
||
| def test_move_ingredient_changes_positions(self, mk_ing): | ||
| burger = Burger() | ||
| burger.add_ingredient(mk_ing("A")) | ||
| burger.add_ingredient(mk_ing("C")) | ||
| burger.add_ingredient(mk_ing("D")) | ||
|
|
||
| burger.move_ingredient(0, 2) | ||
|
|
||
| assert [item.get_name() for item in burger.ingredients] == ["C", "D", "A"] | ||
|
|
||
| def test_set_buns_assigns_bun(self, mk_ing): | ||
| burger = Burger() | ||
| bun = mk_ing("Black Bun", price=100, type_="BUN") | ||
|
|
||
| burger.set_buns(bun) | ||
|
|
||
| assert burger.bun is bun | ||
| assert burger.bun.get_type() == "BUN" |
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| import pytest | ||
| from unittest.mock import MagicMock | ||
|
|
||
| from praktikum.burger import Burger | ||
|
|
||
|
|
||
| class TestBurgerPrice: | ||
| @pytest.mark.parametrize( | ||
| "bun_price, ingredient_prices, expected", | ||
| [ | ||
| (0, [], 0), | ||
| (50, [], 100), | ||
| (80, [20], 180), | ||
| (100, [10, 20, 30], 260), | ||
| ], | ||
| ) | ||
| def test_total_price_parametrized(self, bun_price, ingredient_prices, expected): | ||
| burger = Burger() | ||
| bun = MagicMock() | ||
| bun.get_price.return_value = bun_price | ||
| bun.get_name.return_value = "Any Bun" | ||
| burger.set_buns(bun) | ||
|
|
||
| for price in ingredient_prices: | ||
| ingredient = MagicMock() | ||
| ingredient.get_price.return_value = price | ||
| ingredient.get_name.return_value = f"i{price}" | ||
| ingredient.get_type.return_value = "FILLING" | ||
| burger.add_ingredient(ingredient) | ||
|
|
||
| assert burger.get_price() == expected |
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| from praktikum.burger import Burger | ||
|
|
||
|
|
||
| class TestBurgerReceipt: | ||
| def test_receipt_text_full_match(self, mk_ing): | ||
| burger = Burger() | ||
| bun = mk_ing("Black Bun", price=100, type_="BUN") | ||
| sauce = mk_ing("spicy", price=30, type_="SAUCE") | ||
| filling = mk_ing("beef", price=70, type_="FILLING") | ||
|
|
||
| burger.set_buns(bun) | ||
| burger.add_ingredient(sauce) | ||
| burger.add_ingredient(filling) | ||
|
|
||
| expected = ( | ||
| f"(==== {bun.get_name()} ====)\n" | ||
| f"= sauce {sauce.get_name()} =\n" | ||
| f"= filling {filling.get_name()} =\n" | ||
| f"(==== {bun.get_name()} ====)\n" | ||
| f"\nPrice: {2 * bun.get_price() + sauce.get_price() + filling.get_price()}\n" | ||
| ) | ||
|
|
||
| assert burger.get_receipt() == expected |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Необходимо исправить: эта директория лишняя в проекте. Необходимо убрать её из ветки и добавить в .gitignore в корне проекта