Files
ci-demo/tests/test_discounts.py

37 lines
1.0 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import sys
import pytest
from app.discounts import NoDiscount, discount_for
from app.service import Order, OrderService
def make_order() -> Order:
return Order({"чай": 300, "кофе": 700})
def test_vip_discount() -> None:
service = OrderService(discount_for("vip"))
assert service.total(make_order()) == pytest.approx(900.0)
def test_employee_discount() -> None:
service = OrderService(discount_for("employee"))
assert service.total(make_order()) == pytest.approx(700.0)
def test_regular_has_no_discount() -> None:
service = OrderService(discount_for("regular"))
assert service.total(make_order()) == pytest.approx(1000.0)
def test_unknown_type_falls_back_to_regular() -> None:
assert isinstance(discount_for("unknown"), NoDiscount)
def test_python_version_supported() -> None:
# Для акта с матрицей: на Python 3.11 этот тест падает
assert sys.version_info >= (3, 12), (
f"нужен Python 3.12+, получено {sys.version.split()[0]}"
)