1
0
fin-defs/test/test_parse_price.py
Jon Michael Aanes 066b8cdac7
Some checks failed
Python Ruff Code Quality / ruff (push) Failing after 22s
Run Python tests (through Pytest) / Test (push) Failing after 24s
Verify Python project can be installed, loaded and have version checked / Test (push) Successful in 21s
Restructure by moving data stuff into data module, and added price parsing
2025-05-14 20:33:15 +02:00

37 lines
1.0 KiB
Python

import pytest
from decimal import Decimal
from fin_defs import DKK, USD, AssetAmount, FiatCurrency
from fin_defs.parse_price import parse_price
def dkk(amount):
return AssetAmount(DKK, Decimal(amount))
PRICES_PARSABLE = [
('DKK100', dkk(100)),
('100;-', dkk(100)),
('100 kr', dkk(100)),
(' 100 kr ', dkk(100)),
('349.-', dkk(349)),
('3.000 kr.', dkk(3000)),
('25,00 kr.', dkk(25)),
('300,00 kr.', dkk(300)),
('300kr.', dkk(300)),
('300kr', dkk(300)),
('5,00 dkk', dkk(5)),
('9,99 dkk', dkk('9.99')),
('17900 kr', dkk(17900)),
]
PRICES_UNPARSABLE = [
'007',
]
@pytest.mark.parametrize(('price_string', 'parsed_amount'), PRICES_PARSABLE)
def test_parse_price(price_string: str, parsed_amount: AssetAmount):
result = parse_price(price_string, parsed_amount.asset)
assert result == parsed_amount
@pytest.mark.parametrize('price_string', PRICES_UNPARSABLE)
def test_parse_unparsable(price_string: str):
assert parse_price(price_string, USD) is None