- Notifications
You must be signed in to change notification settings - Fork 58
Edit3#11
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?
Uh oh!
There was an error while loading. Please reload this page.
Edit3 #11
Changes from all commits
d922f119df0f472c543276c3e5f14f3c230e768d2e85bec9b6d9d3cee7ec87a795615745bba610097574a324b099c2ebeb59d5a2a3781ea2f8e8701d2ab8af8a7a81f16fb337f452344File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| # Environments | ||
| .env | ||
| .venv | ||
| env/ | ||
| venv/ | ||
| ENV/ | ||
| env.bak/ | ||
| venv.bak/ | ||
| __pycache__/ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,18 @@ | ||
| 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,23 @@ | ||
| from functions.level_1.four_bank_parser import BankCard, SmsMessage, Expense, parse_ineco_expense | ||
| import datetime | ||
| import decimal | ||
| from typing import NamedTuple | ||
| # ВОПРОС: | ||
| # В таких случаях, как этот, нужен ли параметрайз? | ||
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. Так у тебя тут один тест, нечего параметрайзить :) | ||
| 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 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,21 @@ | ||
| from functions.level_1.one_gender import genderalize | ||
| import pytest | ||
| def test_genderalize(): | ||
| pass | ||
| @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"), | ||
| ] | ||
| ) | ||
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. Опять лишняя строка 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. Ну и дальше они тоже есть у параметрайзов | ||
| 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") | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,42 @@ | ||
| 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", | ||
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. Отступы потерялись | ||
| [ | ||
| ('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,31 @@ | ||
| 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. Длинные туплы, их бы тоже разбить на несколько строк | ||
| ("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)), | ||
| ] | ||
| ) | ||
| # когда делала assert is expected_result, получала по каждому туплу ошибку | ||
| # AssertionError: assert datetime.datetime(2023, 5, 28, 19, 55) is datetime.datetime(2023, 5, 28, 19, 55) | ||
| # + where datetime.datetime(2023, 5, 28, 19, 55) = compose_datetime_from('tomorrow', '19:55') | ||
| # Заменила is на ==, теперь тесты проходят. | ||
| # Вопрос: это такая особенность дататайма, или почему так произошло? | ||
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. == проверяет объекты на равенство, а is – на то, что объекты указывают на одну и ту же область в памяти. is обычно используют когда сравнивают с None/True/False. | ||
| def test__compose_datetime_from__is_valid(date_str, time_str, expected_result): | ||
| assert compose_datetime_from(date_str, time_str) == expected_result | ||
| def test__compose_datetime_from_wrong_date(): | ||
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(AttributeError): | ||
| compose_datetime_from("202yhbmj5", 14645) | ||
| def test__compose_datetime_from_no_date_str(): | ||
| with pytest.raises(TypeError): | ||
| compose_datetime_from("19:33") | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| from functions.level_1_5.three_first import first, NOT_SET | ||
| import pytest | ||
| @pytest.mark.parametrize( | ||
| "items, default, expected_result", | ||
| [ | ||
| ([1, 2, 3], None, 1), | ||
| ([1, 2, 3], NOT_SET, 1), | ||
| ([], 'default', 'default'), | ||
| ('', 'default', 'default'), | ||
| (None, 'default', 'default'), | ||
| (None, 1234, 1234), | ||
| (None, None, None), | ||
| (None, (5, 56), (5, 56)), | ||
| ] | ||
| ) | ||
| def test__first__is_valid(items, default, expected_result): | ||
| assert first(items, default) is expected_result | ||
| # ВОПРОС: как параметризовать такие варианты, | ||
| # когда один из параметров не передаётся? | ||
| # Через None? | ||
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. Можно в параметрайзе ввести отдельный параметр типа "передавать ли второй аргумент" и в самом тесте сделать иф этот параметр и по-разному вызывать функцию. Но я советую не париться и сделать через значение аргумента по-умолчанию (в этом случае это NOT_SET) | ||
| def test__first__defaults_is_string(): | ||
| assert first('default') == 'd' | ||
| def test__first__defaults_is_not_set(): | ||
| assert first(NOT_SET) == 'N' | ||
| def test__first__items_is_empty_no_defaults_attributeerror(): | ||
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(AttributeError): | ||
| first([]) | ||
| def test__first__items_is_empty_attributeerror(): | ||
| with pytest.raises(AttributeError): | ||
| first([], NOT_SET) | ||
| def test__first__no_parameters(): | ||
| with pytest.raises(TypeError): | ||
| first() | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| from functions.level_1_5.five_replace_word import replace_word | ||
| import pytest | ||
| def replace_word(text: str, replace_from: str, replace_to: str) -> str: | ||
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. Это тут точно лишнее :) | ||
| words = text.split() | ||
| new_words = [] | ||
| for word in words: | ||
| if word.lower() == replace_from.lower(): | ||
| new_words.append(replace_to) | ||
| else: | ||
| new_words.append(word) | ||
| return ' '.join(new_words) | ||
| @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_valif(text, replace_from, replace_to, expected_result): | ||
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. Очипятка в названии | ||
| assert replace_word(text, replace_from, replace_to) == expected_result | ||
| def test__replace_word__replace_to_is_int_typeerror(): | ||
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(TypeError): | ||
| replace_word('one two three four', 'two', 123) | ||
| def test__replace_word__replace_from_is_int_attributeerror(): | ||
| with pytest.raises(AttributeError): | ||
| replace_word('one two three four', 2, '123') | ||
| def test__replace_word__text_is_int_attributeerror(): | ||
| with pytest.raises(AttributeError): | ||
| replace_word(123314, 'two', '123') | ||
| 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,37 @@ | ||
| 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 | ||
| def test__get_median_value__empty_params(): | ||
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. Этот тест не нужен, он есть в наборе выше | ||
| assert get_median_value('') == None | ||
| def test__get_median_value__no_params_typeerror(): | ||
| with pytest.raises(TypeError): | ||
| get_median_value() | ||
| def test__get_median_value__list_of_four_params_indexerror(): | ||
| with pytest.raises(IndexError): | ||
| get_median_value([2, 1, 3, 9]) | ||
| def test__get_median_value__one_int_in_params_typeerror(): | ||
| with pytest.raises(TypeError): | ||
| get_median_value(1) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| 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.
Пустые строки лишние