finance-telegram-bot/tests/test_parser.py
2026-07-14 12:21:12 +07:00

41 lines
1.5 KiB
Python
Raw 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 pytest
from app.domain import TransactionKind
from app.parser import ParseError, format_money, parse_money_amount, parse_transaction
@pytest.mark.parametrize(
("text", "kopecks", "description", "kind"),
[
("467 ярче", 46_700, "ярче", TransactionKind.EXPENSE),
("3 000 бензин", 300_000, "бензин", TransactionKind.EXPENSE),
("199,90 кофе", 19_990, "кофе", TransactionKind.EXPENSE),
("+ 85 000 зарплата", 8_500_000, "зарплата", TransactionKind.INCOME),
("доход 5000 подработка", 500_000, "подработка", TransactionKind.INCOME),
("расход 1200 кино", 120_000, "кино", TransactionKind.EXPENSE),
],
)
def test_parse_transaction(text, kopecks, description, kind):
parsed = parse_transaction(text)
assert parsed.amount_kopecks == kopecks
assert parsed.description == description
assert parsed.kind is kind
@pytest.mark.parametrize("text", ["просто текст", "0 кофе", "500", "- доход 500 премия"])
def test_rejects_invalid_input(text):
with pytest.raises(ParseError):
parse_transaction(text)
def test_format_money():
assert format_money(123_456_00) == "123 456 ₽"
assert format_money(-199_90, signed=True) == "199,90 ₽"
@pytest.mark.parametrize(
("text", "kopecks"),
[("530713", 53_071_300), ("530 713 ₽", 53_071_300), ("1250,50 руб", 125_050)],
)
def test_parse_money_amount(text, kopecks):
assert parse_money_amount(text) == kopecks