-
Notifications
You must be signed in to change notification settings - Fork 55
Fixtures level 1 #18
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
mishakov1c
wants to merge
18
commits into
learnpythonru:main
Choose a base branch
from
mishakov1c:fixtures_level_1
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
Fixtures level 1 #18
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
e990422
done
mishakov1c 4bdd4ec
new iteration
mishakov1c 61d355c
small fix
mishakov1c 018234f
new try
mishakov1c 043bea6
small fix
mishakov1c 1f9e482
another try)
mishakov1c 1e33d32
first try
mishakov1c 8dc0b15
tests_1_try_3
mishakov1c 7e2b61d
Merge pull request #5 from mishakov1c/homework_1.5
mishakov1c cae8000
Merge branch 'main' into homework_1_try_3
mishakov1c 35f6a33
the fourth try
mishakov1c 35dbd9b
Merge pull request #7 from mishakov1c/homework_1_try_4
mishakov1c 553a066
parametrize_try_1
mishakov1c 625e2ad
after cr
mishakov1c b3b1e2b
Merge branch 'learnpythonru:main' into main
mishakov1c 60231dc
removed unnecessary parametrize
mishakov1c 929718a
Merge pull request #9 from mishakov1c/removing-unnecessary-parametrize
mishakov1c 4bede8c
added fixtures level 1
mishakov1c 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,3 @@ | ||
| env/ | ||
| __pycache__/ | ||
| settings.json |
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 @@ | ||
| [flake8] | ||
| max-line-length = 120 |
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 @@ | ||
| from functions.level_1_5.five_replace_word import replace_word | ||
| import pytest | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| 'text, replace_from, replace_to, expected_result', | ||
| [ | ||
| ( | ||
| 'Установите последнюю версию PowerShell для новых функций и улучшения!', | ||
| 'Установите', | ||
| 'Удалите', | ||
| 'Удалите последнюю версию PowerShell для новых функций и улучшения!', | ||
| ), | ||
| ('', 'PowerShell', 'WinRar', ''), | ||
| ('Установите', 'PowerShell', 'WinRar', 'Установите'), | ||
| ], | ||
| ) | ||
| def test__replace_word__success(text, replace_from, replace_to, expected_result): | ||
| assert replace_word(text, replace_from, replace_to) == expected_result | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| 'text, replace_from, replace_to, exception_type', | ||
| [ | ||
| (1111, 'PowerShell', 'WinRar', AttributeError), | ||
| ('Установите последнюю версию PowerShell', 'Установите', 1111, TypeError), | ||
| ], | ||
| ) | ||
| def test__replace_word__exceptions(text, replace_from, replace_to, exception_type): | ||
| with pytest.raises(exception_type): | ||
| replace_word(text, replace_from, replace_to) |
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 functions.level_1_5.four_sentiment import check_tweet_sentiment | ||
| import pytest | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| 'text, good_words, bad_words, expected_result', | ||
| [ | ||
| ( | ||
| 'I love this movie', | ||
| {'love', 'great', 'awesome'}, | ||
| {'hate', 'terrible', 'awful'}, | ||
| 'GOOD', | ||
| ), | ||
| ( | ||
| 'This pizza is disgusting', | ||
| {'love', 'great', 'awesome'}, | ||
| {'disgusting', 'terrible', 'awful'}, | ||
| 'BAD', | ||
| ), | ||
| ( | ||
| 'The product has good features, but the customer support is bad', | ||
| {'good', 'excellent', 'impressive'}, | ||
| {'bad', 'poor', 'disappointing'}, | ||
| None, | ||
| ), | ||
| ], | ||
| ) | ||
| def test__check_tweet_sentiment(text, good_words, bad_words, expected_result): | ||
| assert check_tweet_sentiment(text, good_words, bad_words) == expected_result |
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,19 @@ | ||
| from functions.level_1_5.one_median import get_median_value | ||
| import pytest | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| 'items, expected_result', | ||
| [ | ||
| ([], None), | ||
| ([8, 1, 3, 2, 5, 7], 6), | ||
| ([8, 1, 3, 2, 5], 2), | ||
| ], | ||
| ) | ||
| def test__get_median_value__success(items, expected_result): | ||
| assert get_median_value(items) == expected_result | ||
|
|
||
|
|
||
| def test__get_median_value__index_error(): | ||
| with pytest.raises(IndexError): | ||
| get_median_value([8, 1, 3, 2]) |
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,27 @@ | ||
| from functions.level_1_5.three_first import first | ||
| import pytest | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| 'items, default, expected_result', | ||
| [ | ||
| ([1, 2, 3, 4], None, 1), | ||
| (['88', '2', '3', '4'], None, '88'), | ||
| ([], 'def', 'def'), | ||
| ([], (1, 5), (1, 5)), | ||
| ], | ||
| ) | ||
| def test__first__success(items, default, expected_result): | ||
| assert first(items, default) == expected_result | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| 'items, default, exception_type', | ||
| [ | ||
| ([], None, AttributeError), | ||
| ({'a': 'b'}, None, KeyError), | ||
| ], | ||
| ) | ||
| def test__first__exceptions(items, default, exception_type): | ||
| with pytest.raises(exception_type): | ||
| first(items) |
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 functions.level_1_5.two_square_equation import solve_square_equation | ||
| import pytest | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| 'square_coefficient, linear_coefficient, const_coefficient, expected_result', | ||
| [ | ||
| (2.12, 4.5, 8.55, (None, None)), | ||
| (1, 3, 2, (-2.0, -1.0)), | ||
| (0, 2, 2, (-1.0, None)), | ||
| (0, 0, 2, (None, None)), | ||
| ], | ||
| ) | ||
| def test__salve_square_equation(square_coefficient, linear_coefficient, const_coefficient, expected_result): | ||
| assert solve_square_equation(square_coefficient, linear_coefficient, const_coefficient) == expected_result |
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,41 @@ | ||
| import pytest | ||
| from datetime import datetime | ||
| from decimal import Decimal | ||
| from functions.level_1.four_bank_parser import BankCard, Expense, SmsMessage | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def bank_card_1234(): | ||
| return BankCard('1234', 'KONSTANTIN MISHAKOV') | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def bank_card_5678(): | ||
| return BankCard('5678', 'KONSTANTIN MISHAKOV') | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def expense_amount(): | ||
| return Decimal("99.99") | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def spent_in(): | ||
| return "nenaprasno.ru" | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def sms_message(): | ||
| return SmsMessage( | ||
| f'{expense_amount} руб, *1234 12.04.23 16:00 nenaprasno.ru authcode 0000', "Tinkoff", datetime.now() | ||
| ) | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def expense(): | ||
| return Expense( | ||
| amount=expense_amount, | ||
| card=bank_card_1234, | ||
| spent_in=spent_in, | ||
| spent_at=datetime.strptime("12.04.23 16:00", "%d.%m.%y %H:%M"), | ||
| ) | ||
|
Contributor
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. Отступ лишний |
||
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 |
|---|---|---|
| @@ -1,5 +1,31 @@ | ||
| from functions.level_1.five_title import change_copy_item | ||
| import pytest | ||
|
|
||
|
|
||
| def test_change_copy_item(): | ||
| pass | ||
| @pytest.mark.parametrize( | ||
| 'title, max_main_item_title_length, expected_result', | ||
| [ | ||
| ( | ||
| 'Hello World!', | ||
| 20, | ||
| 'Hello World!', | ||
| ), | ||
| ( | ||
| 'Hello World!', | ||
| 100, | ||
| 'Copy of Hello World!', | ||
| ), | ||
| ( | ||
| 'Copy of Hello World! (3)', | ||
| 100, | ||
| 'Copy of Hello World! (4)', | ||
| ), | ||
| ], | ||
| ) | ||
| def test__change_copy_item__success(title, max_main_item_title_length, expected_result): | ||
| assert change_copy_item(title, max_main_item_title_length) == expected_result | ||
|
|
||
|
|
||
| def test__change_copy_item__exception(): | ||
| with pytest.raises(AttributeError): | ||
| change_copy_item(123, 100) |
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 |
|---|---|---|
| @@ -1,5 +1,17 @@ | ||
| from functions.level_1.four_bank_parser import BankCard, SmsMessage, Expense, parse_ineco_expense | ||
| from functions.level_1.four_bank_parser import parse_ineco_expense | ||
| import pytest | ||
|
|
||
|
|
||
| def test_parse_ineco_expense(): | ||
| pass | ||
| def test__parse_ineco_expense__success(bank_card_1234, bank_card_5678, sms_message, expense): | ||
| cards = [bank_card_1234, bank_card_5678] | ||
|
|
||
| result = parse_ineco_expense(sms_message, cards) | ||
|
|
||
| assert result == expense | ||
|
|
||
|
|
||
| def test__parse_ineco_expense__invalid_format(bank_card_5678, sms_message): | ||
| cards = [bank_card_5678] | ||
|
|
||
| with pytest.raises(IndexError): | ||
| parse_ineco_expense(sms_message, cards) |
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 |
|---|---|---|
| @@ -1,5 +1,14 @@ | ||
| from functions.level_1.one_gender import genderalize | ||
| import pytest | ||
|
|
||
|
|
||
| def test_genderalize(): | ||
| pass | ||
| @pytest.mark.parametrize( | ||
| 'verb_male, verb_female, gender, expected_result', | ||
| [ | ||
| ('сказал', 'сказала', 'male', 'сказал'), | ||
| ('сказал', 'сказала', 'female', 'сказала'), | ||
| ('сказал', 'сказала', 'none', 'сказала'), | ||
| ], | ||
| ) | ||
| def test__genderalize(verb_male, verb_female, gender, expected_result): | ||
| assert genderalize(verb_male, verb_female, gender) == expected_result |
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 |
|---|---|---|
| @@ -1,5 +1,34 @@ | ||
| from functions.level_1.three_url_builder import build_url | ||
| import pytest | ||
|
|
||
|
|
||
| def test_build_url(): | ||
| pass | ||
| @pytest.mark.parametrize( | ||
| 'host_name, relative_url, get_params, expected_result', | ||
| [ | ||
| ( | ||
| 'https://yandex.ru', | ||
| 'search/', | ||
| { | ||
| 'text': 'kinopoisk', | ||
| 'search_source': 'yaru_desktop_common', | ||
| 'src': 'suggest_Pers', | ||
| }, | ||
| 'https://yandex.ru/search/?text=kinopoisk&search_source=yaru_desktop_common&src=suggest_Pers', | ||
| ), | ||
| ( | ||
| 'https://yandex.ru', | ||
| 'search/', | ||
| None, | ||
| 'https://yandex.ru/search/', | ||
|
|
||
| ), | ||
| ( | ||
| 'https://yandex.ru', | ||
| 'search/', | ||
| {}, | ||
| 'https://yandex.ru/search/', | ||
| ), | ||
| ], | ||
| ) | ||
| def test__build_url(host_name, relative_url, get_params, expected_result): | ||
| assert build_url(host_name, relative_url, get_params) == expected_result |
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 |
|---|---|---|
| @@ -1,5 +1,34 @@ | ||
| from functions.level_1.two_date_parser import compose_datetime_from | ||
| import datetime | ||
| import pytest | ||
|
|
||
|
|
||
| def test_compose_datetime_from(): | ||
| pass | ||
| @pytest.mark.parametrize( | ||
| 'date_str, time_str, expected_result', | ||
| [ | ||
| ( | ||
| 'today', | ||
| "17:15", | ||
| datetime.datetime( | ||
| datetime.date.today().year, | ||
| datetime.date.today().month, | ||
| datetime.date.today().day, | ||
| 17, | ||
| 15, | ||
| ) | ||
| ), | ||
| ( | ||
| 'tomorrow', | ||
| "17:15", | ||
| datetime.datetime( | ||
| (datetime.date.today() + datetime.timedelta(1)).year, | ||
| (datetime.date.today() + datetime.timedelta(1)).month, | ||
| (datetime.date.today() + datetime.timedelta(1)).day, | ||
| 17, | ||
| 15, | ||
| ) | ||
| ), | ||
| ], | ||
| ) | ||
| def test__compose_datetime_from(date_str, time_str, expected_result): | ||
| assert compose_datetime_from(date_str, time_str) == expected_result |
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.
Тут ты используешь другие фикстуры, но не инджектишь их в фикстуре expense. Так работать не будет.
А это значит, что ты не запускал тесты перед тем как их сдавать. Не советую так делать.