-
Notifications
You must be signed in to change notification settings - Fork 1.2k
task_1 done #731
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
sergech9
wants to merge
2
commits into
Yandex-Practicum:main
Choose a base branch
from
sergech9:dev
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
task_1 done #731
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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,7 @@ | ||
| { | ||
| "python.testing.pytestArgs": [ | ||
| "tests" | ||
| ], | ||
| "python.testing.unittestEnabled": false, | ||
| "python.testing.pytestEnabled": true | ||
| } |
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
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
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 | ||
| pytest-cov |
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,18 @@ | ||
| from bun import Bun | ||
|
|
||
| class TestBun: | ||
| def test_initialization_sets_name_attribute(self): | ||
| bun = Bun('Black Bun', 100) | ||
| assert bun.name == 'Black Bun' | ||
|
|
||
| def test_initialization_sets_price_attribute(self): | ||
| bun = Bun('White Bun', 200) | ||
| assert bun.price == 200 | ||
|
|
||
| def test_get_name_returns_correct_value(self): | ||
| bun = Bun('Red Bun', 150) | ||
| assert bun.get_name() == 'Red Bun' | ||
|
|
||
| def test_get_price_returns_correct_value(self): | ||
| bun = Bun('Golden Bun', 300) | ||
| assert bun.get_price() == 300 |
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,91 @@ | ||
| from burger import Burger | ||
| from unittest.mock import Mock | ||
|
|
||
| class TestBurger: | ||
|
|
||
| def test_set_buns_assigns_correct_bun(self): | ||
| burger = Burger() | ||
| mock_bun = Mock() | ||
| burger.set_buns(mock_bun) | ||
| assert burger.bun == mock_bun | ||
|
|
||
| def test_add_ingredient_increases_count(self): | ||
| burger = Burger() | ||
| mock_ingredient = Mock() | ||
| burger.add_ingredient(mock_ingredient) | ||
| assert len(burger.ingredients) == 1 | ||
|
|
||
| def test_add_ingredient_contains_correct_object(self): | ||
| burger = Burger() | ||
| mock_ingredient = Mock() | ||
| burger.add_ingredient(mock_ingredient) | ||
| assert burger.ingredients[0] == mock_ingredient | ||
|
|
||
| def test_remove_ingredient_decreases_count(self): | ||
| burger = Burger() | ||
| mock_ingredient = Mock() | ||
| burger.add_ingredient(mock_ingredient) | ||
| burger.remove_ingredient(0) | ||
| assert len(burger.ingredients) == 0 | ||
|
|
||
| def test_move_ingredient_changes_first_element(self): | ||
| burger = Burger() | ||
| ingred_1, ingred_2 = Mock(), Mock() | ||
| burger.add_ingredient(ingred_1) | ||
| burger.add_ingredient(ingred_2) | ||
| burger.move_ingredient(0, 1) | ||
| assert burger.ingredients[0] == ingred_2 | ||
|
|
||
| def test_move_ingredient_changes_second_element(self): | ||
| burger = Burger() | ||
| ingred_1, ingred_2 = Mock(), Mock() | ||
| burger.add_ingredient(ingred_1) | ||
| burger.add_ingredient(ingred_2) | ||
| burger.move_ingredient(0, 1) | ||
| assert burger.ingredients[1] == ingred_1 | ||
|
|
||
| def test_get_price_calculates_correct_sum(self): | ||
| burger = Burger() | ||
| mock_bun = Mock() | ||
| mock_bun.get_price.return_value = 100 | ||
| burger.set_buns(mock_bun) | ||
|
|
||
| mock_ingredient = Mock() | ||
| mock_ingredient.get_price.return_value = 50 | ||
| burger.add_ingredient(mock_ingredient) | ||
|
|
||
| assert burger.get_price() == 250 | ||
|
|
||
| def test_get_receipt_contains_bun_name(self): | ||
| burger = Burger() | ||
| mock_bun = Mock() | ||
| mock_bun.get_name.return_value = "Black Bun" | ||
| mock_bun.get_price.return_value = 100 | ||
| burger.set_buns(mock_bun) | ||
|
|
||
| receipt = burger.get_receipt() | ||
| assert "Black Bun" in receipt | ||
|
|
||
| def test_get_receipt_contains_ingredient_name(self): | ||
| burger = Burger() | ||
| mock_ingredient = Mock() | ||
| mock_ingredient.get_name.return_value = "Cutlet" | ||
| mock_ingredient.get_price.return_value = 50 | ||
| mock_ingredient.get_type.return_value = "FILLING" | ||
| burger.add_ingredient(mock_ingredient) | ||
|
|
||
| mock_bun = Mock() | ||
| mock_bun.get_price.return_value = 100 | ||
| burger.set_buns(mock_bun) | ||
|
|
||
| receipt = burger.get_receipt() | ||
| assert "Cutlet" in receipt | ||
|
|
||
| def test_get_receipt_contains_total_price(self): | ||
| burger = Burger() | ||
| mock_bun = Mock() | ||
| mock_bun.get_price.return_value = 100 | ||
| burger.set_buns(mock_bun) | ||
|
|
||
| receipt = burger.get_receipt() | ||
| assert "200" in receipt |
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,29 @@ | ||
| from database import Database | ||
|
|
||
| class TestDatabase: | ||
|
|
||
| def test_available_buns_returns_correct_count(self): | ||
| db = Database() | ||
| buns = db.available_buns() | ||
|
|
||
| assert len(buns) == 3 | ||
|
|
||
| def test_available_ingredients_returns_correct_count(self): | ||
| db = Database() | ||
| ingredients = db.available_ingredients() | ||
|
|
||
| assert len(ingredients) == 6 | ||
|
|
||
| def test_database_has_specific_bun(self): | ||
| db = Database() | ||
| buns = db.available_buns() | ||
|
|
||
| names = [bun.get_name() for bun in buns] | ||
| assert "white bun" in names | ||
|
|
||
| def test_database_has_specific_ingredient(self): | ||
| db = Database() | ||
| ingredients = db.available_ingredients() | ||
|
|
||
| names = [ing.get_name() for ing in ingredients] | ||
| assert "hot sauce" in names |
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,32 @@ | ||
| import pytest | ||
| from ingredient import Ingredient | ||
| from ingredient_types import INGREDIENT_TYPE_SAUCE, INGREDIENT_TYPE_FILLING | ||
|
|
||
| class TestIngredient: | ||
|
|
||
| @pytest.mark.parametrize("ing_type", [INGREDIENT_TYPE_SAUCE, INGREDIENT_TYPE_FILLING]) | ||
| def test_get_type_returns_correct_value(self, ing_type): | ||
| ingredient = Ingredient(ing_type, "sour cream", 100) | ||
| assert ingredient.get_type() == ing_type | ||
|
|
||
| @pytest.mark.parametrize("name", ["sour cream", "cutlet"]) | ||
| def test_get_name_returns_correct_value(self, name): | ||
| ingredient = Ingredient(INGREDIENT_TYPE_SAUCE, name, 100) | ||
| assert ingredient.get_name() == name | ||
|
|
||
| @pytest.mark.parametrize("price", [100, 200]) | ||
| def test_get_price_returns_correct_value(self, price): | ||
| ingredient = Ingredient(INGREDIENT_TYPE_SAUCE, "sour cream", price) | ||
| assert ingredient.get_price() == price | ||
|
|
||
| def test_initialization_sets_type_attribute(self): | ||
| ingredient = Ingredient(INGREDIENT_TYPE_FILLING, "chicken", 150) | ||
| assert ingredient.type == INGREDIENT_TYPE_FILLING | ||
|
|
||
| def test_initialization_sets_name_attribute(self): | ||
| ingredient = Ingredient(INGREDIENT_TYPE_FILLING, "chicken", 150) | ||
| assert ingredient.name == "chicken" | ||
|
|
||
| def test_initialization_sets_price_attribute(self): | ||
| ingredient = Ingredient(INGREDIENT_TYPE_FILLING, "chicken", 150) | ||
| assert ingredient.price == 150 | ||
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.
Нужно исправить: здесь и далее: это юнит тесты, на каждый метод должен быть отдельный тест