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
18 changes: 18 additions & 0 deletions 03_lesson/address.py
Original file line number Diff line number Diff line change
@@ -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}")
9 changes: 9 additions & 0 deletions 03_lesson/lesson_3_task_1.py
Original file line number Diff line number Diff line change
@@ -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()
18 changes: 18 additions & 0 deletions 03_lesson/lesson_3_task_2.py
Original file line number Diff line number Diff line change
@@ -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}")
9 changes: 9 additions & 0 deletions 03_lesson/lesson_3_task_3.py
Original file line number Diff line number Diff line change
@@ -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)
11 changes: 11 additions & 0 deletions 03_lesson/mailing.py
Original file line number Diff line number Diff line change
@@ -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} рублей.")
Empty file added 03_lesson/requirements.txt
Empty file.
5 changes: 5 additions & 0 deletions 03_lesson/smartphone.py
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions 03_lesson/test_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def test_addition():
assert 1 + 1 == 2
13 changes: 13 additions & 0 deletions 03_lesson/user.py
Original file line number Diff line number Diff line change
@@ -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}")
1 change: 1 addition & 0 deletions 04_lesson/defects.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Неизвестная метка: @pytest.mark.negative не зарегистрирована
4 changes: 4 additions & 0 deletions 04_lesson/pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[pytest]
markers =
positive: Тесты, которые проверяют корректное поведение функции
negative: Тесты, которые проверяют некорректное поведение функции
53 changes: 53 additions & 0 deletions 04_lesson/string_utils.py
Original file line number Diff line number Diff line change
@@ -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
79 changes: 79 additions & 0 deletions 04_lesson/test_string_utils.py
Original file line number Diff line number Diff line change
@@ -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
Binary file added requirements.txt
Binary file not shown.