diff --git a/03_lesson/address.py b/03_lesson/address.py new file mode 100644 index 0000000..3478925 --- /dev/null +++ b/03_lesson/address.py @@ -0,0 +1,18 @@ +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}, " + f"{self.house} - {self.flat}") diff --git a/03_lesson/lesson_3_task_1.py b/03_lesson/lesson_3_task_1.py new file mode 100644 index 0000000..f18ca8d --- /dev/null +++ b/03_lesson/lesson_3_task_1.py @@ -0,0 +1,9 @@ +from user import User + +my_user = User("Михаил", "Михалыч") + +my_user.get_first_name() + +my_user.get_last_name() + +my_user.get_First_last_info() diff --git a/03_lesson/lesson_3_task_2.py b/03_lesson/lesson_3_task_2.py new file mode 100644 index 0000000..7e8f75a --- /dev/null +++ b/03_lesson/lesson_3_task_2.py @@ -0,0 +1,18 @@ +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} - " + f"{smartphone.subscription_number}") diff --git a/03_lesson/lesson_3_task_3.py b/03_lesson/lesson_3_task_3.py new file mode 100644 index 0000000..1680e60 --- /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, cost=500, track="12") + +print(mailing) diff --git a/03_lesson/mailing.py b/03_lesson/mailing.py new file mode 100644 index 0000000..88b23ac --- /dev/null +++ b/03_lesson/mailing.py @@ -0,0 +1,11 @@ +class Mailing: + + def __init__(self, to_address, from_address, cost, track): + self.to_address = to_address + self.from_address = from_address + self.cost = cost + self.track = track + + def __str__(self): + 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 new file mode 100644 index 0000000..5aa2438 --- /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 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 new file mode 100644 index 0000000..b315236 --- /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}") 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 0000000..0bd2f7b Binary files /dev/null and b/requirements.txt differ