from decimal import Decimal import pytest from ee import EeException from ee.money import get_default_context money = get_default_context() @pytest.mark.parametrize("text, dec, cur, to_str", [ ("", None, None, None), (" ", None, None, None), ("1", 1, None, "1"), ("1.0", 1, None, "1"), ("1.1", "1.1", None, "1.1"), ("1.", "1", None, "1"), ("0.002", "0.002", None, "0.002"), ("0,002", "0.002", None, "0.002"), (",002", "0.002", None, "0.002"), (".002", "0.002", None, "0.002"), (".00200", "0.002", None, "0.002"), ("0,86000", "0.86", None, "0.86"), ("0,02141", "0.02141", None, "0.02141"), ("100", "100", None, "100"), ("100.0", "100", None, "100"), ("1 000", "1000", None, "1000"), ("1 000.", "1000", None, "1000"), ("1 000.0", "1000", None, "1000"), ("USD 1", 1, "USD", "USD 1"), ("1 USD", 1, "USD", "USD 1"), ("USD 1.0", 1, "USD", "USD 1"), ("USD1.1", "1.1", "USD", "USD 1.1"), ("1,234.56", "1234.56", None, "1234.56"), ("1.234,56", "1234.56", None, "1234.56"), ("1 234,56", "1234.56", None, "1234.56"), ("USD 1,234.56", "1234.56", "USD", "USD 1234.56"), ("USD 1.234,56", "1234.56", "USD", "USD 1234.56"), ("USD 1 234,56", "1234.56", "USD", "USD 1234.56"), ("1,234.56 USD", "1234.56", "USD", "USD 1234.56"), ("1.234,56 USD", "1234.56", "USD", "USD 1234.56"), ("1 234,56 USD", "1234.56", "USD", "USD 1234.56"), ("1 234 567,891 USD", "1234567.891", "USD", "USD 1234567.891"), ("1 234 567,8901 USD", "1234567.8901", "USD", "USD 1234567.8901"), ("1.1 USD", "1.1", "USD", "USD 1.1"), ("$ 1.1", "1.1", "USD", "USD 1.1"), ("1.1 $", "1.1", "USD", "USD 1.1"), ]) def test_parsing(text, dec, cur, to_str): if dec is not None: m = money.parse(text) assert Decimal(dec) == m.amount assert cur == m.currency assert to_str == str(m) else: try: money.parse(text) pytest.fail("Expected exception") except EeException: pass