From 78f5178855f8c77d340cd6c6efdb15e2fb93dcc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?mike985-=D0=BC=D0=B0=D0=B9=D0=BA=20985?= Date: Sun, 12 Oct 2025 15:46:23 +0300 Subject: [PATCH 1/2] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D1=8B=20=D1=84=D0=B0=D0=B9=D0=BB=D1=8B=20=D0=B4=D0=BB?= =?UTF-8?q?=D1=8F=20lesson3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 03_lesson/address.py | 10 ++++++++++ 03_lesson/lesson_3_task_1.py | 7 +++++++ 03_lesson/lesson_3_task_2.py | 12 ++++++++++++ 03_lesson/lesson_3_task_3.py | 9 +++++++++ 03_lesson/mailing.py | 11 +++++++++++ 03_lesson/smartphone.py | 5 +++++ 03_lesson/user.py | 13 +++++++++++++ 7 files changed, 67 insertions(+) create mode 100644 03_lesson/address.py create mode 100644 03_lesson/lesson_3_task_1.py create mode 100644 03_lesson/lesson_3_task_2.py create mode 100644 03_lesson/lesson_3_task_3.py create mode 100644 03_lesson/mailing.py create mode 100644 03_lesson/smartphone.py create mode 100644 03_lesson/user.py diff --git a/03_lesson/address.py b/03_lesson/address.py new file mode 100644 index 0000000..5f599d4 --- /dev/null +++ b/03_lesson/address.py @@ -0,0 +1,10 @@ +class Address: + def __init__(self, index, city, street, house, flat ): + self.index = index + self.city = city + self.street = street + self.house = house + self.flat = flat + + def __str__(self): + return f"{self.index}, {self.city}, {self.street}, {self.house} - {self.flat}" \ No newline at end of file diff --git a/03_lesson/lesson_3_task_1.py b/03_lesson/lesson_3_task_1.py new file mode 100644 index 0000000..277afae --- /dev/null +++ b/03_lesson/lesson_3_task_1.py @@ -0,0 +1,7 @@ +from user import User + +my_user = User("Михаил", "Михалыч") + +my_user.get_first_name() +my_user.get_last_name() +my_user.get_First_last_info() \ No newline at end of file diff --git a/03_lesson/lesson_3_task_2.py b/03_lesson/lesson_3_task_2.py new file mode 100644 index 0000000..a02228b --- /dev/null +++ b/03_lesson/lesson_3_task_2.py @@ -0,0 +1,12 @@ +from smartphone import Smartphone + +catalog = [ + Smartphone("Samsung", "Galaxy S21", "+79242718265"), + Smartphone("Samsung", "Galaxy S22", "+79242718264"), + Smartphone("Samsung", "Galaxy S23", "+79242718263"), + Smartphone("Samsung", "Galaxy S24", "+79242718262"), + Smartphone("Samsung", "Galaxy S25", "+79242718261") +] + +for smartphone in catalog: + print(f"{smartphone.phone_brand} - {smartphone.phone_model} - {smartphone.subscription_number}") \ No newline at end of file diff --git a/03_lesson/lesson_3_task_3.py b/03_lesson/lesson_3_task_3.py new file mode 100644 index 0000000..eb75281 --- /dev/null +++ b/03_lesson/lesson_3_task_3.py @@ -0,0 +1,9 @@ +from address import Address +from mailing import Mailing + +to_address = Address(751, "Питер", "Ленина", 1, 1) +from_address = Address(752, "Москва", "Ленина", 2, 2) + +mailing = Mailing(from_address, to_address, 500, "12") + +print(mailing) \ No newline at end of file diff --git a/03_lesson/mailing.py b/03_lesson/mailing.py new file mode 100644 index 0000000..4ee7713 --- /dev/null +++ b/03_lesson/mailing.py @@ -0,0 +1,11 @@ +from address import Address + +class Mailing: + def __init__(self, to_address, from_address, cost, track): + self.to_address = to_address + self.from_address = from_address + self.cost = 500 + self.track = 12 + + def __str__(self): + return f"Отправление {self.track} из {self.from_address} в {self.to_address}. Стоимость {self.cost} рублей." \ No newline at end of file diff --git a/03_lesson/smartphone.py b/03_lesson/smartphone.py new file mode 100644 index 0000000..c2b4c7a --- /dev/null +++ b/03_lesson/smartphone.py @@ -0,0 +1,5 @@ +class Smartphone: + def __init__(self, phone_brand, phone_model, subscription_number): + self.phone_brand = phone_brand + self.phone_model = phone_model + self.subscription_number = subscription_number \ No newline at end of file diff --git a/03_lesson/user.py b/03_lesson/user.py new file mode 100644 index 0000000..d66b7e6 --- /dev/null +++ b/03_lesson/user.py @@ -0,0 +1,13 @@ +class User: + def __init__(self, first_name, last_name): + self.first_name = first_name + self.last_name = last_name + + def get_first_name(self): + print(self.first_name) + + def get_last_name(self): + print(self.last_name) + + def get_First_last_info(self): + print(f"First_name: {self.first_name}, Last_name: {self.last_name}") \ No newline at end of file From 54b93729c364ada9aa4b74a9ab2934a0eb1fbc7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?mike985-=D0=BC=D0=B0=D0=B9=D0=BA=20985?= Date: Sat, 25 Oct 2025 17:52:08 +0300 Subject: [PATCH 2/2] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D1=8B=20=D0=B7=D0=B0=D0=B4=D0=B0=D0=BD=D0=B8=D1=8F=20?= =?UTF-8?q?=D1=83=D1=80=D0=BE=D0=BA=D0=B0=204?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 03_lesson/address.py | 12 ++++- 03_lesson/lesson_3_task_1.py | 4 +- 03_lesson/lesson_3_task_2.py | 8 +++- 03_lesson/lesson_3_task_3.py | 4 +- 03_lesson/mailing.py | 10 ++--- 03_lesson/requirements.txt | 0 03_lesson/smartphone.py | 2 +- 03_lesson/test_example.py | 2 + 03_lesson/user.py | 2 +- 04_lesson/defects.txt | 1 + 04_lesson/pytest.ini | 4 ++ 04_lesson/string_utils.py | 53 ++++++++++++++++++++++ 04_lesson/test_string_utils.py | 79 +++++++++++++++++++++++++++++++++ requirements.txt | Bin 0 -> 338 bytes 14 files changed, 168 insertions(+), 13 deletions(-) create mode 100644 03_lesson/requirements.txt create mode 100644 03_lesson/test_example.py create mode 100644 04_lesson/defects.txt create mode 100644 04_lesson/pytest.ini create mode 100644 04_lesson/string_utils.py create mode 100644 04_lesson/test_string_utils.py create mode 100644 requirements.txt diff --git a/03_lesson/address.py b/03_lesson/address.py index 5f599d4..3478925 100644 --- a/03_lesson/address.py +++ b/03_lesson/address.py @@ -1,10 +1,18 @@ class Address: - def __init__(self, index, city, street, house, flat ): + + def __init__(self, index, city, street, house, flat): + self.index = index + self.city = city + self.street = street + self.house = house + self.flat = flat def __str__(self): - return f"{self.index}, {self.city}, {self.street}, {self.house} - {self.flat}" \ No newline at end of file + + return (f"{self.index}, {self.city}, {self.street}, " + f"{self.house} - {self.flat}") diff --git a/03_lesson/lesson_3_task_1.py b/03_lesson/lesson_3_task_1.py index 277afae..f18ca8d 100644 --- a/03_lesson/lesson_3_task_1.py +++ b/03_lesson/lesson_3_task_1.py @@ -3,5 +3,7 @@ my_user = User("Михаил", "Михалыч") my_user.get_first_name() + my_user.get_last_name() -my_user.get_First_last_info() \ No newline at end of file + +my_user.get_First_last_info() diff --git a/03_lesson/lesson_3_task_2.py b/03_lesson/lesson_3_task_2.py index a02228b..7e8f75a 100644 --- a/03_lesson/lesson_3_task_2.py +++ b/03_lesson/lesson_3_task_2.py @@ -2,11 +2,17 @@ catalog = [ Smartphone("Samsung", "Galaxy S21", "+79242718265"), + Smartphone("Samsung", "Galaxy S22", "+79242718264"), + Smartphone("Samsung", "Galaxy S23", "+79242718263"), + Smartphone("Samsung", "Galaxy S24", "+79242718262"), + Smartphone("Samsung", "Galaxy S25", "+79242718261") ] for smartphone in catalog: - print(f"{smartphone.phone_brand} - {smartphone.phone_model} - {smartphone.subscription_number}") \ No newline at end of file + + print(f"{smartphone.phone_brand} - {smartphone.phone_model} - " + f"{smartphone.subscription_number}") diff --git a/03_lesson/lesson_3_task_3.py b/03_lesson/lesson_3_task_3.py index eb75281..1680e60 100644 --- a/03_lesson/lesson_3_task_3.py +++ b/03_lesson/lesson_3_task_3.py @@ -4,6 +4,6 @@ to_address = Address(751, "Питер", "Ленина", 1, 1) from_address = Address(752, "Москва", "Ленина", 2, 2) -mailing = Mailing(from_address, to_address, 500, "12") +mailing = Mailing(from_address, to_address, cost=500, track="12") -print(mailing) \ No newline at end of file +print(mailing) diff --git a/03_lesson/mailing.py b/03_lesson/mailing.py index 4ee7713..88b23ac 100644 --- a/03_lesson/mailing.py +++ b/03_lesson/mailing.py @@ -1,11 +1,11 @@ -from address import Address - class Mailing: + def __init__(self, to_address, from_address, cost, track): self.to_address = to_address self.from_address = from_address - self.cost = 500 - self.track = 12 + self.cost = cost + self.track = track def __str__(self): - return f"Отправление {self.track} из {self.from_address} в {self.to_address}. Стоимость {self.cost} рублей." \ No newline at end of file + return (f"Отправление {self.track} из {self.from_address} в " + f"{self.to_address}. Стоимость {self.cost} рублей.") diff --git a/03_lesson/requirements.txt b/03_lesson/requirements.txt new file mode 100644 index 0000000..e69de29 diff --git a/03_lesson/smartphone.py b/03_lesson/smartphone.py index c2b4c7a..5aa2438 100644 --- a/03_lesson/smartphone.py +++ b/03_lesson/smartphone.py @@ -2,4 +2,4 @@ class Smartphone: def __init__(self, phone_brand, phone_model, subscription_number): self.phone_brand = phone_brand self.phone_model = phone_model - self.subscription_number = subscription_number \ No newline at end of file + self.subscription_number = subscription_number diff --git a/03_lesson/test_example.py b/03_lesson/test_example.py new file mode 100644 index 0000000..fc0f97d --- /dev/null +++ b/03_lesson/test_example.py @@ -0,0 +1,2 @@ +def test_addition(): + assert 1 + 1 == 2 \ No newline at end of file diff --git a/03_lesson/user.py b/03_lesson/user.py index d66b7e6..b315236 100644 --- a/03_lesson/user.py +++ b/03_lesson/user.py @@ -10,4 +10,4 @@ def get_last_name(self): print(self.last_name) def get_First_last_info(self): - print(f"First_name: {self.first_name}, Last_name: {self.last_name}") \ No newline at end of file + print(f"First_name: {self.first_name}, Last_name: {self.last_name}") diff --git a/04_lesson/defects.txt b/04_lesson/defects.txt new file mode 100644 index 0000000..490e727 --- /dev/null +++ b/04_lesson/defects.txt @@ -0,0 +1 @@ +Неизвестная метка: @pytest.mark.negative не зарегистрирована \ No newline at end of file diff --git a/04_lesson/pytest.ini b/04_lesson/pytest.ini new file mode 100644 index 0000000..75ea0cd --- /dev/null +++ b/04_lesson/pytest.ini @@ -0,0 +1,4 @@ +[pytest] +markers = + positive: Тесты, которые проверяют корректное поведение функции + negative: Тесты, которые проверяют некорректное поведение функции \ No newline at end of file diff --git a/04_lesson/string_utils.py b/04_lesson/string_utils.py new file mode 100644 index 0000000..19893a7 --- /dev/null +++ b/04_lesson/string_utils.py @@ -0,0 +1,53 @@ +class StringUtils: + """ + Класс с полезными утилитами для обработки и анализа строк + """ + + def capitalize(self, string: str) -> str: + """ + Принимает на вход текст, делает первую букву заглавной + и возвращает этот же текст + Пример: `capitilize("skypro") -> "Skypro"` + """ + return string.capitalize() + + def trim(self, string: str) -> str: + """ + Принимает на вход текст и удаляет пробелы в начале, если они есть + Пример: `trim(" skypro") -> "skypro"` + """ + whitespace = " " + while string.startswith(whitespace): + string = string.removeprefix(whitespace) + return string + + def contains(self, string: str, symbol: str) -> bool: + """ + Возвращает `True`, если строка содержит искомый символ + и `False` - если нет + Параметры: + `string` - строка для обработки + `symbol` - искомый символ + Пример 1: `contains("SkyPro", "S") -> True` + Пример 2: `contains("SkyPro", "U") -> False` + """ + res = False + try: + res = string.index(symbol) > -1 + except ValueError: + pass + + return res + + def delete_symbol(self, string: str, symbol: str) -> str: + """ + Удаляет все подстроки из переданной строки + Параметры: + `string` - строка для обработки + `symbol` - искомый символ для удаления + Пример 1: `delete_symbol("SkyPro", "k") -> "SyPro"` + Пример 2: `delete_symbol("SkyPro", "Pro") -> "Sky"` + """ + if self.contains(string, symbol): + string = string.replace(symbol, "") + return string diff --git a/04_lesson/test_string_utils.py b/04_lesson/test_string_utils.py new file mode 100644 index 0000000..06e7652 --- /dev/null +++ b/04_lesson/test_string_utils.py @@ -0,0 +1,79 @@ +import pytest +from string_utils import StringUtils + + +string_utils = StringUtils() + + +@pytest.mark.positive +@pytest.mark.parametrize("input_str, expected", [ + ("skypro", "Skypro"), + ("hello world", "Hello world"), + ("python", "Python"), +]) +def test_capitalize_positive(input_str, expected): + assert string_utils.capitalize(input_str) == expected + + +@pytest.mark.negative +@pytest.mark.parametrize("input_str, expected", [ + ("123abc", "123abc"), + ("", ""), + (" ", " "), +]) +def test_capitalize_negative(input_str, expected): + assert string_utils.capitalize(input_str) == expected + + +@pytest.mark.positive +@pytest.mark.parametrize("input_str, expected", [ + (" skypro", "skypro"), + (" hello world", "hello world"), + (" python", "python"), +]) +def test_trim_positive(input_str, expected): + assert string_utils.trim(input_str) == expected + + +@pytest.mark.negative +@pytest.mark.parametrize("input_str, expected", [ + ("123abc", "123abc"), + ("", ""), +]) +def test_trim_negative(input_str, expected): + assert string_utils.trim(input_str) == expected + + +@pytest.mark.positive +@pytest.mark.parametrize("input_str, symbol, expected", [ + ("SkyPro", "S", True), + ("SkyPro", "U", False), + ("Skypro", "-1", False), +]) +def test_contains_positive(input_str, symbol, expected): + assert string_utils.contains(input_str, symbol) == expected + + +@pytest.mark.negative +@pytest.mark.parametrize("input_str, symbol, expected", [ + ("", "-1", False), +]) +def test_contains_negative(input_str, symbol, expected): + assert string_utils.contains(input_str, symbol) == expected + + +@pytest.mark.positive +@pytest.mark.parametrize("input_str, symbol, expected", [ + ("SkyPro", "k", "SyPro"), + ("SkyPro", "Pro", "Sky"), +]) +def test_delete_symbol_positive(input_str, symbol, expected): + assert string_utils.delete_symbol(input_str, symbol) == expected + + +@pytest.mark.negative +@pytest.mark.parametrize("input_str, symbol, expected", [ + ("", "a", ""), +]) +def test_delete_symbol_negative(input_str, symbol, expected): + assert string_utils.delete_symbol(input_str, symbol) == expected diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000000000000000000000000000000000000..0bd2f7b521a0e2498316174a210d62c2047b080e GIT binary patch literal 338 zcmY+AK@Ng25Jmsm#H$!UMO=6Xu7DMrMnEEU(aWoUrfq^Dv*G=DGt=+K;E93tLWhxc z;a6aX1FOas8{Ek|JkX<2dLr4g3Z)Jc9K0mWe{bfdSL&uel>=#Qk%p`{Xj=f^b zhT|$R;LZOQLHkRRdPRfIztO(HGc%+)vPG$v