Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
d922f11
Added test_one_gender
DianaRatnikova May 13, 2023
9df0f47
Added test_one_gender_type
DianaRatnikova May 13, 2023
2c54327
Added test_three
DianaRatnikova May 14, 2023
6c3e5f1
Added test_four
DianaRatnikova May 14, 2023
4f3c230
Added type check for test_four
DianaRatnikova May 14, 2023
e768d2e
Delete tests/level_1/__pycache__ directory
DianaRatnikova May 16, 2023
2819984
Edited task1
DianaRatnikova May 16, 2023
1d345cb
Edited task1
DianaRatnikova May 16, 2023
85bec9b
Edited program2
DianaRatnikova May 16, 2023
6d9d3ce
Edited program1
DianaRatnikova May 16, 2023
e7ec87a
Edited program2
DianaRatnikova May 16, 2023
7956157
Edited program3 and 4
DianaRatnikova May 16, 2023
45bba61
Added test_five
DianaRatnikova May 17, 2023
0097574
Добавила исключения
DianaRatnikova May 20, 2023
a324b09
__pycache__ is deleted
DianaRatnikova May 21, 2023
9c2ebeb
__pycache__ is deleted
DianaRatnikova May 21, 2023
59d5a2a
__pycache__ is deleted
DianaRatnikova May 21, 2023
3781ea2
Исправлен нейминг
DianaRatnikova May 21, 2023
30d2078
Merge branch 'learnpythonru:main' into main
DianaRatnikova May 21, 2023
f8e8701
Merge branch 'learnpythonru:main' into edit2
DianaRatnikova May 21, 2023
d2ab8af
Test one for median is ready
DianaRatnikova May 21, 2023
8a7a81f
Added tests for tasks 2-5
DianaRatnikova May 23, 2023
16fb337
Сделала простые тесты ванлайнером
DianaRatnikova May 27, 2023
f452344
Added parametrize
DianaRatnikova May 27, 2023
3d40352
Собрала все эрроры в параметрайз
DianaRatnikova May 29, 2023
85afda5
Собрала все эрроры в параметрайз
DianaRatnikova May 29, 2023
1cd5a8b
before merge
DianaRatnikova Jun 5, 2023
2e6c78b
Merge branch 'main' of https://github.com/DianaRatnikova/testing_exer…
DianaRatnikova Jun 5, 2023
5e9ac7f
gitignore
DianaRatnikova Jun 5, 2023
c47d3ad
gitignire
DianaRatnikova Jun 5, 2023
d6a0e8d
Merge pull request #1 from DianaRatnikova/edit4
DianaRatnikova Jun 5, 2023
746a228
Merge branch 'learnpythonru:main' into main
DianaRatnikova Jun 5, 2023
a0e0c49
First fixtures
DianaRatnikova Jun 6, 2023
b990c1b
Merge pull request #2 from DianaRatnikova/fixtures1
DianaRatnikova Jun 7, 2023
24f1a58
Доработка level_1, test_3
DianaRatnikova Jun 11, 2023
da6c7c3
!
DianaRatnikova Jun 13, 2023
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
10 changes: 10 additions & 0 deletions .gitignore
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__/
65 changes: 65 additions & 0 deletions tests/level_1/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
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.

Да! Можно :)


@pytest.fixture()
def host_name_1():
return "host_name_8"

@pytest.fixture()
def host_name_2():
return "str"

@pytest.fixture()
def relative_url():
return "relative_url"


@pytest.fixture()
def get_params_mappings_k_and_v():
return {'k': 'k_str', 'v': 'v_str'}

@pytest.fixture()
def querypart_k_and_v(get_params_mappings_k_and_v):
return '?' + '&'.join([f'{k}={v}' for (k, v) in get_params_mappings_k_and_v.items()])

@pytest.fixture()
def url_k_and_v(host_name_2, relative_url, querypart_k_and_v):
return f'{host_name_2}/{relative_url}{querypart_k_and_v}'

@pytest.fixture()
def get_params_mappings_k():
return {'k': 'k_str'}

@pytest.fixture()
def querypart_k(get_params_mappings_k):
return '?' + '&'.join([f'{k}={v}' for (k, v) in get_params_mappings_k.items()])

@pytest.fixture()
def url_k(host_name_1, relative_url, querypart_k):
return f'{host_name_1}/{relative_url}{querypart_k}'


@pytest.fixture()
def get_params_no_querypart():
return {}


@pytest.fixture()
def get_params_none():
return None


@pytest.fixture()
def get_params_attr_error():
return [1,1]

@pytest.fixture()
def querypart_no_querypart(get_params_no_querypart):
return ''

@pytest.fixture()
def url_no_querypart(host_name_1, relative_url, querypart_no_querypart):
return f'{host_name_1}/{relative_url}{querypart_no_querypart}'

15 changes: 13 additions & 2 deletions tests/level_1/test_five_title.py
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
18 changes: 17 additions & 1 deletion tests/level_1/test_four_bank_parser.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
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))
Copy link
Contributor

Choose a reason for hiding this comment

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

Длинная строка, я бы отформатировал

assert parse_ineco_expense(sms, cards) == expense_result

30 changes: 28 additions & 2 deletions tests/level_1/test_one_gender.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,31 @@
from functions.level_1.one_gender import genderalize
import pytest


def test_genderalize():
pass
@pytest.fixture
Copy link
Contributor

Choose a reason for hiding this comment

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

Эти фикстуры тоже едва ли тебе пригодятся где-то ещё.

Ну и не забывай, что место фикстур в конфтесте, а не в файле с тестами

def verb_male():
return "verb_male"

@pytest.fixture
def verb_female():
return "verb_female"

@pytest.fixture
def random_symbols():
return "4w5rgt"

@pytest.mark.parametrize(
"verb_male, verb_female, gender, expected_result",
[
(verb_male, random_symbols, "male", verb_male),
(verb_male, verb_female, "female", verb_female),
(verb_male, verb_female, random_symbols, verb_female),
]
)
def test__genderalize__is_valid(verb_male, verb_female, gender, expected_result):
assert genderalize(verb_male, verb_female, gender) == expected_result


def test__genderalize_only_two_parameters_typeerror():
with pytest.raises(TypeError):
genderalize(verb_male, verb_female)
45 changes: 43 additions & 2 deletions tests/level_1/test_three_url_builder.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,46 @@
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_1', 'relative_url', 'get_params_none', 'url_no_querypart'),
('host_name_2', 'relative_url', 'get_params_mappings_k_and_v', 'url_k_and_v'),
('host_name_1', 'relative_url', 'get_params_mappings_k', 'url_k'),
('host_name_1', 'relative_url', 'get_params_no_querypart', 'url_no_querypart'),
]
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__build_url__is_valid(host_name, relative_url, get_params, expected_result, request):
host_name = request.getfixturevalue(host_name)
relative_url = request.getfixturevalue(relative_url)
get_params = request.getfixturevalue(get_params)
expected_result = request.getfixturevalue(expected_result)
assert build_url(host_name, relative_url, get_params) == expected_result


def test__build_url_only_host_name_typeerror(host_name_1):
with pytest.raises(TypeError):
build_url(host_name_1)


def test_build_url_only_get_params_typeerror(get_params_mappings_k):
with pytest.raises(TypeError):
build_url(get_params_mappings_k)


def test__build_url_value_error_no_parmeters():
with pytest.raises(TypeError):
build_url()

# Вопрос: убрать что ли нафиг этот тест, тк с такими данными результат - не тайпэррор(
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__build_url_bad_key_in_get_params_typeerror(host_name_1, relative_url):
with pytest.raises(TypeError):
build_url(host_name_1, relative_url, {(1,1): None})


def test__build_url_bad_key_in_get_params_attributeerror(host_name_1, relative_url, get_params_attr_error):
with pytest.raises(AttributeError):
build_url(host_name_1, relative_url, get_params_attr_error)
51 changes: 49 additions & 2 deletions tests/level_1/test_two_date_parser.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,52 @@
from functions.level_1.two_date_parser import compose_datetime_from
import datetime
import pytest


def test_compose_datetime_from():
pass
@pytest.fixture
def time_str():
return "19:55"

@pytest.fixture
def expected_result(time_str):
hour_str, minute_str = time_str.strip().split(":")
hour_str = int(hour_str)
minute_str = int(minute_str)
return datetime.datetime(datetime.date.today().year,
datetime.date.today().month,
datetime.date.today().day,
hour_str, minute_str)
Copy link
Contributor

Choose a reason for hiding this comment

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

Все многострочные штуки я предпочитаю форматировать вот так:

return datetime.datetime(
    datetime.date.today().year,
    datetime.date.today().month,
    datetime.date.today().day, 
    hour_str,
    minute_str,
)



@pytest.mark.parametrize(
"date_str, time_str, expected_result",
[
# ("2023,12,15", time_str, expected_result),
Copy link
Contributor

Choose a reason for hiding this comment

The 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)),
]
)
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:
compose_datetime_from(date_str, time_str)
else:
compose_datetime_from(date_str)
50 changes: 50 additions & 0 deletions tests/level_1_5/test_first.py
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):
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([], )
34 changes: 34 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,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):
replace_word(text, replace_from, replace_to)


def test__replace_word__not_enough_params_typeerror():
with pytest.raises(TypeError):
replace_word('123', 'bsrbg')
37 changes: 37 additions & 0 deletions tests/level_1_5/test_four_check_tweet_sentiment.py
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'}, None),
('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', 'BAD'),
('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', None),
]
)

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


@pytest.mark.parametrize(
"text, good_words, bad_words, expected_error",
[
# ('', {''}, TypeError),
(123, '5 6 7 4', '2', AttributeError),
]
)

def test__check_tweet_sentiment__errors(text, good_words, bad_words, expected_error):
with pytest.raises(expected_error):
check_tweet_sentiment(text, good_words, bad_words)

Loading