Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .coverage
Binary file not shown.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
env/
__pycache__/
settings.json
2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[flake8]
max-line-length = 120
31 changes: 31 additions & 0 deletions tests/level_1.5/test_five_replace_word.py
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)
29 changes: 29 additions & 0 deletions tests/level_1.5/test_four_sentiment.py
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
19 changes: 19 additions & 0 deletions tests/level_1.5/test_one_median.py
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])
27 changes: 27 additions & 0 deletions tests/level_1.5/test_three_first.py
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)
15 changes: 15 additions & 0 deletions tests/level_1.5/test_two_square_equation.py
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
41 changes: 41 additions & 0 deletions tests/level_1/conftest.py
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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Тут ты используешь другие фикстуры, но не инджектишь их в фикстуре expense. Так работать не будет.

А это значит, что ты не запускал тесты перед тем как их сдавать. Не советую так делать.

card=bank_card_1234,
spent_in=spent_in,
spent_at=datetime.strptime("12.04.23 16:00", "%d.%m.%y %H:%M"),
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Отступ лишний

30 changes: 28 additions & 2 deletions tests/level_1/test_five_title.py
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)
18 changes: 15 additions & 3 deletions tests/level_1/test_four_bank_parser.py
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)
13 changes: 11 additions & 2 deletions tests/level_1/test_one_gender.py
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
33 changes: 31 additions & 2 deletions tests/level_1/test_three_url_builder.py
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
33 changes: 31 additions & 2 deletions tests/level_1/test_two_date_parser.py
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