def test_eql(): """Тест метода сравнения пицц с помощью равенства.""" margherita_l1 = Margherita(size="L") margherita_l2 = Margherita(size="L") margherita_xl = Margherita(size="XL") pepperoni_xl = Pepperoni(size="XL") assert ( margherita_l1 == margherita_l2 and margherita_l1 != margherita_xl and margherita_xl != pepperoni_xl )
def menu() -> None: """Наше меню.""" print(" " * 60, "😋 Наше меню 😋\n", end="") pizzas_list = [ Pepperoni(size="L"), Pepperoni(size="XL"), Margherita(size="L"), Margherita(size="XL"), Hawaii(size="L"), Hawaii(size="XL"), ] for p in pizzas_list: print("-{pizza}".format(pizza=p))
def test_eq(): margherita_1 = Margherita() margherita_2 = Margherita() hawaiian_1 = Hawaiian() hawaiian_2 = Hawaiian() pepperoni_1 = Pepperoni() pepperoni_2 = Pepperoni() assert margherita_1 == margherita_2 assert hawaiian_1 == hawaiian_2 assert pepperoni_1 == pepperoni_2 assert margherita_1 != hawaiian_1 assert margherita_1 != pepperoni_1 assert hawaiian_1 != pepperoni_1
def menu() -> None: """Выводит меню""" pizzas = [ Margherita(size="L"), Margherita(size="XL"), Hawaiian(size="L"), Hawaiian(size="XL"), Pepperoni(size="L"), Pepperoni(size="XL") ] print("🍕 Меню:") for pizza in pizzas: print('-', pizza, '(' + pizza.size + ') \n', ', '.join(pizza.ingredients.keys()))
def test_name(): margherita_1 = Margherita() hawaiian_1 = Hawaiian() pepperoni_1 = Pepperoni() assert margherita_1.name == 'Margherita 🧀' assert hawaiian_1.name == 'Hawaiian 🍍' assert pepperoni_1.name == 'Pepperoni 🍕'
def test_deco_delivery(): """Тест функции delivery, после применения декоратора.""" my_randint = 10 # Вызываем randint() из random, заменив возвращаемое значение на my_randint with patch.object(random, "randint", return_value=my_randint): assert ( delivery(Margherita(size="L")) == "🛵 Доставили Margherita🧀 L за ⌚ 10мин!" )
def menu() -> None: """ Pizzeria menu """ print("Меню:\n", end="") pizza_list = [ Pepperoni(size="L"), Pepperoni(size="XL"), Margherita(size="L"), Margherita(size="XL"), Hawaii(size="L"), Hawaii(size="XL"), ] for element in pizza_list: print("-{pizza}".format(pizza=element)) print( "Чтобы заказать пиццу, " "наберите в терминале: python cli.py order " "название_пиццы размер_пиццы, " "и если вы хотите доставку, " "допишите --delivery :\n", end="")
def order(pizza: str, size: str = 'L', delivery_order: bool = False): """Готовит и доставляет пиццу""" Menu = {'Margherita': Margherita(size), 'Pepperoni': Pepperoni(size), 'Hawaiian': Hawaiian(size)} if pizza not in Menu.keys(): print( "Такой пиццы нет в меню. " "Выберите одну из других пицц: ") for element in MENU.values(): print('--', element.name, element.symbol, ':') element.dict() return pizza_to_make = Menu[pizza] if delivery_order is False: bake(pizza_to_make) else: bake(pizza_to_make) delivery(pizza_to_make)
def test_orig_delivery(): """Тест функции delivery, без применения декоратора.""" original_delivery = delivery.__wrapped__ assert original_delivery(Margherita(size="XL")) == "🛵 Доставили"
def test_pickup(): margherita_1 = Margherita() assert processing.pickup(margherita_1)[:25] == '💁 Забрали Margherita 🧀 за'
def test_delivery(): margherita_1 = Margherita() assert processing.delivery(margherita_1)[:27] == '🛵 Доставили Margherita 🧀 за'
def test_bake(): margherita_1 = Margherita() assert processing.bake(margherita_1)[:31] == '👨🍳 Приготовили Margherita 🧀 за'
def test_size(): margherita_1 = Margherita() margherita_2 = Margherita('XL') assert margherita_1.size == 'L' assert margherita_2.size == 'XL'
import click from pizza import Margherita, Pepperoni, Hawaiian from random import randint MENU = {'Margherita': Margherita(), 'Pepperoni': Pepperoni(), 'Hawaiian': Hawaiian()} def log(template: str): def decorator(func): def wrapper(*args, **kwargs): result = func(*args, **kwargs) print(template.format(randint(50, 1200))) return result return wrapper return decorator @click.group() def cli(): pass @cli.command() @click.option('--delivery_order', default=False, is_flag=True) @click.argument('pizza', nargs=1) @click.argument('size', nargs=1) def order(pizza: str, size: str = 'L', delivery_order: bool = False):
def test_delivery_decorated(): my_randint = 19 with patch.object(random, "randint", return_value=my_randint): assert (delivery( Margherita(size="L")) == "🛵 🚚 Доставка Margherita🧀 L за 19 мин.!")
def test_delivery_no_decorator(): original_delivery = delivery.__wrapped__ assert original_delivery(Margherita(size="XL")) == "🛵 🚚 Доставка"