-
Notifications
You must be signed in to change notification settings - Fork 55
Edit4 #12
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
base: main
Are you sure you want to change the base?
Edit4 #12
Changes from all commits
d922f11
9df0f47
2c54327
6c3e5f1
4f3c230
e768d2e
2819984
1d345cb
85bec9b
6d9d3ce
e7ec87a
7956157
45bba61
0097574
a324b09
9c2ebeb
59d5a2a
3781ea2
30d2078
f8e8701
d2ab8af
8a7a81f
16fb337
f452344
3d40352
85afda5
1cd5a8b
2e6c78b
5e9ac7f
c47d3ad
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| # Environments | ||
| .env | ||
| .venv | ||
| env/ | ||
| venv/ | ||
| ENV/ | ||
| env.bak/ | ||
| venv.bak/ | ||
| pycache/ | ||
| __pycache__/ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,16 @@ | ||
| 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", | ||
| [ | ||
| ('THIS IS TITLE', 100, 'Copy of THIS IS TITLE'), | ||
| ('THIS IS TITLE', 10, 'THIS IS TITLE'), | ||
| ('Copy of something(17)', 100, 'Copy of (18)'), | ||
| ('Copy of something (17)', 100, 'Copy of something (18)'), | ||
| ('Copy of something(1fvd7)', 100, 'Copy of something(1fvd7) (2)'), | ||
| ] | ||
| ) | ||
| def test__change_copy_item__is_valid(title, max_main_item_title_length, expected_result): | ||
| assert change_copy_item(title, max_main_item_title_length) == expected_result |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,29 @@ | ||
| from functions.level_1.four_bank_parser import BankCard, SmsMessage, Expense, parse_ineco_expense | ||
| import datetime | ||
| import decimal | ||
| from typing import NamedTuple | ||
|
|
||
|
|
||
| def test_parse_ineco_expense(): | ||
| pass | ||
| text = "112.3 $, 40004234 13.05.23 17:23 Shop_name authcode jhtfj" | ||
| author = "Masha" | ||
| sent_at = datetime.datetime.now().time() | ||
| # Входное значение для функции | ||
| sms= SmsMessage(text, author, sent_at) | ||
|
|
||
| bank_card1 = BankCard(last_digits='0123', owner= 'User1') | ||
| bank_card2 = BankCard(last_digits = '4234', owner = 'User2') | ||
| # Входное значение для функции | ||
| cards = [bank_card1, bank_card2] | ||
|
|
||
| expense_result=Expense(amount = decimal.Decimal('112.3'), card = BankCard(last_digits ='4234', owner ='User2'), spent_in = 'Shop_name', spent_at = datetime.datetime(2023, 5, 13, 17, 23)) | ||
| assert parse_ineco_expense(sms, cards) == expense_result | ||
|
|
||
| <<<<<<< HEAD | ||
| ======= | ||
| Expense_result = Expense(amount, card, spend_in, spent_at) | ||
|
|
||
| assert parse_ineco_expense(sms, cards) == Expense_result | ||
| assert type(parse_ineco_expense(sms, cards)) == Expense | ||
|
|
||
| >>>>>>> main |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,33 @@ | ||
| from functions.level_1.one_gender import genderalize | ||
| import pytest | ||
|
|
||
|
|
||
| def test_genderalize(): | ||
| pass | ||
| <<<<<<< HEAD | ||
|
|
||
| @pytest.mark.parametrize( | ||
| "verb_male, verb_female, gender, expected_result", | ||
| [ | ||
| ("verb_male", "VF", "male", "verb_male"), | ||
| ("verb_male", "verb_female", "female", "verb_female"), | ||
| ("verb_male", "verb_female", '254654', "verb_female"), | ||
| ] | ||
| ) | ||
| def test__genderalize__is_valid(verb_male, verb_female, gender, expected_result): | ||
| assert genderalize(verb_male, verb_female, gender) is expected_result | ||
|
|
||
|
|
||
| def test__genderalize_only_two_parameters_typeerror(): | ||
| with pytest.raises(TypeError): | ||
| genderalize("verb_male", "verb_female") | ||
| ======= | ||
| def test_genderalize_verb_male(): | ||
| assert genderalize("verb_male", "VF", "male") == "verb_male" | ||
|
|
||
| def test_genderalize_verb_female(): | ||
| assert genderalize("verb_male", "verb_female", "female") == "verb_female" | ||
|
|
||
| def test_genderalize_gender_else(): | ||
| assert genderalize("verb_male", "verb_female", '254654') == "verb_female" | ||
|
|
||
|
|
||
| >>>>>>> main |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,40 @@ | ||
| 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", | ||
| [ | ||
| ('host_name', 'relative_url', None, 'host_name/relative_url'), | ||
| ('str1', 'relative_url', {'k': 'k_str', 'v': 'v_str'}, 'str1/relative_url?k=k_str&v=v_str'), | ||
| ('host_name', 'relative_url', {'k': 'k_str'}, 'host_name/relative_url?k=k_str'), | ||
| ('host_name', 'relative_url', {}, 'host_name/relative_url'), | ||
| ] | ||
| ) | ||
| def test__build_url__is_valid(host_name, relative_url, get_params, expected_result): | ||
| assert build_url(host_name, relative_url, get_params) == expected_result | ||
|
|
||
|
|
||
| def test__build_url_only_host_name_typeerror(): | ||
| with pytest.raises(TypeError): | ||
| build_url('host_name') | ||
|
|
||
|
|
||
| def test_build_url_only_get_params_typeerror(): | ||
| with pytest.raises(TypeError): | ||
| build_url({'k': 'k_str'}) | ||
|
|
||
|
|
||
| def test__build_url_value_error_no_parmeters(): | ||
| with pytest.raises(TypeError): | ||
| build_url() | ||
|
|
||
|
|
||
| def test__build_url_bad_key_in_get_params_typeerror(): | ||
| with pytest.raises(TypeError): | ||
| build_url('host_name', 'relative_url', {[1,1]: None}) | ||
|
|
||
|
|
||
| def test__build_url_bad_key_in_get_params_attributeerror(): | ||
| with pytest.raises(AttributeError): | ||
| build_url('host_name', 'relative_url', [1,1]) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,40 @@ | ||
| 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", | ||
| [ | ||
| ("2023,12,15", "19:55", datetime.datetime(datetime.date.today().year, | ||
| datetime.date.today().month, | ||
| datetime.date.today().day, | ||
| 19, 55)), | ||
|
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. В фикстурах лучше стараться держать данные постатичнее и попроще. Например, ты можешь тут хранить количество дней, которые добавить к тудей, чай и минуту, а сам объект datetime собирать уже в тесте. |
||
| ("tomorrow", "19:55", datetime.datetime(datetime.date.today().year, | ||
| datetime.date.today().month, | ||
| datetime.date.today().day+1, | ||
| 19,55)), | ||
| ("202yhbmj5", "19:33", datetime.datetime(datetime.date.today().year, | ||
| datetime.date.today().month, | ||
| datetime.date.today().day, | ||
| 19,33)), | ||
| ] | ||
| ) | ||
| def test__compose_datetime_from__is_valid(date_str, time_str, expected_result): | ||
| assert compose_datetime_from(date_str, time_str) == expected_result | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "date_str, time_str, expected_error, need_time_str", | ||
| [ | ||
| ("202yhbmj5", 14645, AttributeError, 1), | ||
| ("19:33", 0, TypeError, 0) | ||
| ] | ||
| ) | ||
| def test__compose_datetime_from__error(date_str, time_str, expected_error, need_time_str): | ||
| with pytest.raises(expected_error): | ||
| if need_time_str == 1: | ||
|
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. В python для такого используется не 1/0, а True/False |
||
| compose_datetime_from(date_str, time_str) | ||
| else: | ||
| compose_datetime_from(date_str) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| from functions.level_1_5.three_first import first, NOT_SET | ||
| import pytest | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "items, default, expected_result, items_need", | ||
| [ | ||
| ([1, 2, 3], None, 1, 1), | ||
| ([1, 2, 3], NOT_SET, 1, 1), | ||
| ([], 'default', 'default', 1), | ||
| ('', 'default', 'default', 1), | ||
| (None, 'default', 'default', 1), | ||
| (None, 1234, 1234, 1), | ||
| (None, None, None, 1 ), | ||
| (None, (5, 56), (5, 56), 1), | ||
| (0, 'default', 'd', 0), | ||
| (0, NOT_SET, 'N', 0) | ||
| ] | ||
| ) | ||
| def test__first__is_valid(items, default, expected_result, items_need): | ||
| if items_need == 1: | ||
| assert first(items, default) is expected_result | ||
| else: | ||
| assert first(default) is expected_result | ||
|
|
||
| @pytest.mark.parametrize( | ||
| "items, default, expected_error, items_need, default_need", | ||
| [ | ||
| ([], 0, AttributeError, 1, 0), | ||
| ([], NOT_SET, AttributeError, 1, 1), | ||
| (0, 0, TypeError, 0, 0), | ||
| ] | ||
| ) | ||
| def test__first__errors(items, default, expected_error, items_need, default_need): | ||
|
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. В тесте не дожно быть такой вложенности и такого количества условий. В таком случае лучше разбить на несколько простых тестов |
||
| with pytest.raises(expected_error): | ||
| if items_need == 1: | ||
| if default_need == 1: | ||
| first(items, default) | ||
| else: | ||
| first(items) | ||
| else: | ||
| if default_need == 1: | ||
| pass | ||
| else: | ||
| first() | ||
|
|
||
|
|
||
| def test__first__items_is_empty_attributeerror(): | ||
| with pytest.raises(AttributeError): | ||
| first([], ) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| from functions.level_1_5.five_replace_word import replace_word | ||
| import pytest | ||
|
|
||
| @pytest.mark.parametrize( | ||
| "text, replace_from, replace_to, expected_result", | ||
| [ | ||
| ('one two three four', 'two', 'replace_to', 'one replace_to three four'), | ||
| ('one two three Two four', 'two', 'replace_to','one replace_to three replace_to four'), | ||
| ('one two three four', 'TWo', 'replace_to','one replace_to three four'), | ||
| ('one two three four', '1234', 'replace_to', 'one two three four'), | ||
| ('one two three four', '', 'replace_to', 'one two three four'), | ||
| ('one two three four', 'two', '', 'one three four'), | ||
| ] | ||
| ) | ||
| def test__replace_word__is_valid(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, expected_error", | ||
| [ | ||
| ('one two three four', 'two', 123, TypeError), | ||
| ('one two three four', 2, '123', AttributeError), | ||
| (123314, 'two', '123', AttributeError), | ||
| ] | ||
| ) | ||
| def test__replace_word__errors(text, replace_from, replace_to, expected_error): | ||
| with pytest.raises(expected_error): | ||
|
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. Лишний отступ |
||
| replace_word(text, replace_from, replace_to) | ||
|
|
||
|
|
||
| def test__replace_word__not_enough_params_typeerror(): | ||
| with pytest.raises(TypeError): | ||
| replace_word('123', 'bsrbg') | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| from functions.level_1_5.four_sentiment import check_tweet_sentiment | ||
| import pytest | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "text, good_words, bad_words, expected_result", | ||
| [ | ||
| ('g1 b1 g2 b2 g3 b3 ', {'g1','g2'}, {'b1', 'b2'}, 'BAD'), | ||
| ('g0 b0 g0 b0 g3 b3 ', {'g1','g2'}, {'b1', 'b2'}, None), | ||
| ('g1 b2 g0 b0 g3 b3 ', {'g1','g2'}, {'g1', 'g2'}, None), | ||
| ('g1 b2 g0 b0 g3 b3 g4 b4', {'g1','g2', 'g3'}, {'g1', 'g2'},'GOOD'), | ||
| ('1 2', '5 6 7 4', '2', 'GOOD'), | ||
| ('g0 b0 g0 b0 g0 b3 g4 b4', {'g1','g2', 'g3'}, {'g1', 'g2'}, None), | ||
| ('g0 b0 g3 b3 g4 b4', {'g1','g2'}, {'g1', 'g2', 'g3'},'BAD'), | ||
| ('g0 b0 g3 b3 g4 b4', {''}, {'g1', 'g2', 'g3'}, 'BAD'), | ||
| ('g0 b0 g3 b3 g4 b4', {''}, {''}, None), | ||
| ('', {''}, {''}, None), | ||
| ('one two', 'one', 'two', 'BAD'), | ||
| ] | ||
| ) | ||
|
|
||
| def test__check_tweet_sentiment__is_valid(text, good_words, bad_words, expected_result): | ||
| assert check_tweet_sentiment(text, good_words, bad_words) is expected_result | ||
|
|
||
|
|
||
| def test__check_tweet_sentiment__everything_is_str(): | ||
| assert check_tweet_sentiment('one two', 'one', 'two') == 'BAD' | ||
|
|
||
|
|
||
| def test__check_tweet_sentiment__no_bw_typeerror(): | ||
| with pytest.raises(TypeError): | ||
| check_tweet_sentiment('', {''}) | ||
|
|
||
|
|
||
| def test__check_tweet_sentiment__text_is_int_attributeerror(): | ||
| with pytest.raises(AttributeError): | ||
| check_tweet_sentiment(123, '5 6 7 4', '2') |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| from functions.level_1_5.one_median import get_median_value | ||
| import pytest | ||
|
|
||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "items, expected_result", | ||
| [ | ||
| ('', None), | ||
| ([2, 1, 5], 5), | ||
| ([-2, -1, 5], 5), | ||
| ([2, 1, 3, 9, 10], 9), | ||
| ([2, 1, 1, 1, 3, 3, 2, 9, 9, 3, 9, 10], 9), | ||
| ([0.6, 99.4, 13.2], 13.2), | ||
| ] | ||
| ) | ||
| def test__get_median__is_valid(items, expected_result): | ||
| assert get_median_value(items) is expected_result | ||
|
|
||
| @pytest.mark.parametrize( | ||
| "items, expected_error, items_need", | ||
| [ | ||
| (0, TypeError, 0), | ||
| ([2, 1, 3, 9], IndexError, 1), | ||
| (1, TypeError, 1), | ||
| ] | ||
| ) | ||
| def test__get_median_value__errors(items, expected_error, items_need): | ||
| with pytest.raises(expected_error): | ||
| if items_need == 1: | ||
| get_median_value(items) | ||
| else: | ||
| get_median_value() |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| from functions.level_1_5.two_square_equation import solve_square_equation | ||
| import pytest | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "square_coefficient, linear_coefficient, const_coefficient, expected_results", | ||
| [ | ||
| (0, 0, 0, (None, None)), | ||
| (5, 2, 0, (-0.4, 0.0)), | ||
| (0, 2, 10,(-5.0, None)), | ||
| (0, 2, 0, (0.0, None)), | ||
| (4, 0, -16, (-2.0, 2.0)), | ||
| (5, 3, -26, (-2.6, 2.0)), | ||
| (1, 2, 5, (None, None)), | ||
| (1.1, 2.2, -5.5, (-3.449489742783178, 1.4494897427831779)), | ||
| ] | ||
|
|
||
| ) | ||
|
|
||
| def test__solve_square_equation__is_valid(square_coefficient, linear_coefficient, const_coefficient, expected_results): | ||
| assert solve_square_equation(square_coefficient, linear_coefficient, const_coefficient) == expected_results | ||
|
|
||
|
|
||
| def test__solve_square_equation__not_enougt_params(): | ||
| with pytest.raises(TypeError): | ||
| solve_square_equation(0, 0) | ||
|
|
||
|
|
||
| def test__solve_square_equation__too_many_params(): | ||
| with pytest.raises(TypeError): | ||
| solve_square_equation(5, 2, 0, 9) | ||
|
|
||
|
|
||
| def test__solve_square_equation__params_are_string(): | ||
| with pytest.raises(TypeError): | ||
| solve_square_equation('a', 'b', 'c') | ||
|
|
||
|
|
||
| def test__solve_square_equation__params_are_lists(): | ||
| with pytest.raises(TypeError): | ||
| solve_square_equation([0], [0], [0]) |
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.
В этом файле почти везде потерялись вторые подчёркивания