aboutsummaryrefslogtreecommitdiff
path: root/test/test_money.py
diff options
context:
space:
mode:
Diffstat (limited to 'test/test_money.py')
-rw-r--r--test/test_money.py60
1 files changed, 60 insertions, 0 deletions
diff --git a/test/test_money.py b/test/test_money.py
new file mode 100644
index 0000000..636d7ce
--- /dev/null
+++ b/test/test_money.py
@@ -0,0 +1,60 @@
+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