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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
env
**/__pycache__/
5 changes: 4 additions & 1 deletion tests/level_1/test_five_title.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@


def test_change_copy_item():
Copy link
Contributor

Choose a reason for hiding this comment

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

Тут и дальше название тестов так себе

pass
assert change_copy_item('Banana') == 'Copy of Banana'
assert change_copy_item('Copy of Banana') == 'Copy of Banana (2)'
assert change_copy_item('Copy of Banana (7)') == 'Copy of Banana (8)'
assert change_copy_item('Banana', 5) == 'Banana'
Copy link
Contributor

Choose a reason for hiding this comment

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

Почему-то в одном тесте собраны четыре разные теста. Разделить бы.

Copy link
Contributor

Choose a reason for hiding this comment

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

Актуально для почти всех тестов ниже

22 changes: 21 additions & 1 deletion tests/level_1/test_four_bank_parser.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
import datetime
import decimal

from functions.level_1.four_bank_parser import BankCard, SmsMessage, Expense, parse_ineco_expense


def test_parse_ineco_expense():
pass
sms = SmsMessage(
text="Вы купили 0.23 Эфира, *1234 18.05.23 23:59 MEWWALLET authcode 5005",
author="MewWallet",
sent_at=datetime.datetime.now(),
)

cards = [
BankCard("1234", "Pavel Mager"),
BankCard("5678", "Pavel Mager"),
]

expected_output = Expense(
amount=decimal.Decimal("0.23"),
card=cards[0],
spent_in="MEWWALLET",
spent_at=datetime.datetime.strptime("18.05.23 23:59", "%d.%m.%y %H:%M"),
)
assert parse_ineco_expense(sms, cards) == expected_output
Copy link
Contributor

Choose a reason for hiding this comment

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

Разбить бы по AAA

4 changes: 3 additions & 1 deletion tests/level_1/test_one_gender.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@


def test_genderalize():
pass
assert genderalize('Ходил', 'Ходила', 'male') == 'Ходил'
assert genderalize('Ходил', 'Ходила', 'female') == 'Ходила'
assert genderalize('Ходил', 'Ходила', 'banana') == 'Ходила'
4 changes: 3 additions & 1 deletion tests/level_1/test_three_url_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@


def test_build_url():
pass
assert build_url('https://www.youtube.com', 'watch', get_params={'v':'dQw4w9WgXcQ'}) == 'https://www.youtube.com/watch?v=dQw4w9WgXcQ'
assert build_url('https://github.com', 'MagerOK/testing_exercises') == 'https://github.com/MagerOK/testing_exercises'

8 changes: 7 additions & 1 deletion tests/level_1/test_two_date_parser.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
from functions.level_1.two_date_parser import compose_datetime_from
from datetime import datetime


def test_compose_datetime_from():
pass
date = compose_datetime_from('Bla-bla', '11:15')
today = datetime.today()
assert date == datetime(today.year, today.month, today.day, int(date.hour), int(date.minute))
date = compose_datetime_from('tomorrow', '13:40')
assert date == datetime(today.year, today.month, today.day + 1, int(date.hour), int(date.minute))

15 changes: 15 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,15 @@
from functions.level_1_5.five_replace_word import replace_word


def test__replace_word__with_replaces():
text = 'I have the power that my father never dreamed of! NEVER !!!'
replace_from = 'never'
replace_to = 'always'
exp_output = 'I have the power that my father always dreamed of! always !!!'
assert replace_word(text, replace_from, replace_to) == exp_output

def test__replace_word__without_replaces():
text = 'I have the power that my father never dreamed of! NEVER !!!'
replace_from = 'Sponge'
replace_to = 'Bob'
assert replace_word(text, replace_from, replace_to) == text
26 changes: 26 additions & 0 deletions tests/level_1_5/test_four_sentiment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from functions.level_1_5.four_sentiment import check_tweet_sentiment


def test__check_tweet_sentiment__without_any_bad_or_good_words():
text = "This is an ordinary text, without any emotional expressions."
good_words = set()
bad_words = set()
assert check_tweet_sentiment(text, good_words, bad_words) == None

def test__check_tweet_sentiment__with_the_same_number_of_words():
text = "Very good, so good, it'so good, Jesus! But I hate it! It's disgusting! I hate it! I FUCKING HATE IT YOU HEAR ME?"
good_words = {'good,', 'jesus!'}
bad_words = {'hate', 'fucking'}
assert check_tweet_sentiment(text, good_words, bad_words) == None

def test__check_tweet_sentiment__normal_expecting_BAD_response():
Copy link
Contributor

Choose a reason for hiding this comment

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

Капс в названиях тестов лучше не использовать

text = "You motherfucker, come on, you little ass… fuck with me, eh?! You fucking little asshole, dickhead, cocksucker… You fuckin’ — come on, come fuck with me! I’ll get your ass, you jerk! Oh, you fuckhead, motherfucker! Fuck all you and your family! Come on, you cocksucker, slime bucket, shitface, turdball! Come on, you scum sucker, you fucking with me?! Come on, you asshole!"
good_words = {'family!', 'handsome', 'smart'}
bad_words = {'fuck', 'fucking', 'ass...'}
assert check_tweet_sentiment(text, good_words, bad_words) == 'BAD'

def test__check_tweet_sentiment__normal_expecting_GOOD_response():
text = "I love this place! it's perfect to suicide for sure. i love it!"
good_words = {'love'}
bad_words = {'suicide'}
assert check_tweet_sentiment(text, good_words, bad_words) == 'GOOD'
21 changes: 21 additions & 0 deletions tests/level_1_5/test_one_median.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from functions.level_1_5.one_median import get_median_value
import pytest


"""Хотелось бы сразу заметить, что функция и нормальные тесты невозможны"""
Copy link
Contributor

Choose a reason for hiding this comment

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

Во-первых, комментарий в формате докстринги принято ставить сразу после дефа. Этот комментарий нужно писать с помощью решётки. Сейчас это строковой литерал.

Во-вторых, в этом комментарии пропущено слово и можно на изи неправильно его понять.

Ну и в-третьих очень даже возможно написать нормальные тесты на функцию с багом.

def test__get_median_value__empty_list():
assert get_median_value([]) is None

def test__get_median_value__list_with_odd_numbers_elem():
assert get_median_value([3, 7, 4]) == 4

def test__get_median_value__list_with_even_numbers_elem():
with pytest.raises(IndexError):
get_median_value([1, 3, 5, 7])

def test__get_median_value__list_with_1_elem():
with pytest.raises(IndexError):
get_median_value([1])

def test__get_median_value__list_with_negative_numb():
assert get_median_value([-5, -10, -1, -6, -8]) == -6
16 changes: 16 additions & 0 deletions tests/level_1_5/test_three_first.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from functions.level_1_5.three_first import first
import pytest

def test__first__list_of_numbers():
assert first([1, 2, 3, 4, 5]) == 1

def test__first__list_of_numbers_with_default_value():
assert first([1, 2, 3, 4, 5], 10) == 1

def test__first__empty_list_with_default_value():
assert first([], 'There is no numbers') == 'There is no numbers'

def test__first__empty_list_without_default_value():
with pytest.raises(AttributeError):
first([])

14 changes: 14 additions & 0 deletions tests/level_1_5/test_two_square_equation.py
Copy link
Contributor

Choose a reason for hiding this comment

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

Тут я бы ещё кейсов поискал

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from functions.level_1_5.two_square_equation import solve_square_equation


def test__solve_square_equation__no_roots():
assert solve_square_equation(1.0, 0.0, 1.0) == (None, None)

def test__solve_square_equation__one_root():
assert solve_square_equation(1, -2, 1) == (1.0, 1.0)

def test__solve_square_equation__two_roots():
assert solve_square_equation(1, -3, 2) == (1.0, 2.0)

def test__solve_square_equation__linear():
assert solve_square_equation(0, 2, -1) == (0.5, None)