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