aboutsummaryrefslogtreecommitdiff
path: root/test/test_money.py
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2019-03-14 12:23:57 +0100
committerTrygve Laugstøl <trygvis@inamo.no>2019-03-15 08:22:01 +0100
commita8ec679349c3eb9c33a9d33e247fd86cb8e53f81 (patch)
tree094a498b7b30e402c419e8a588e86769f7d408c9 /test/test_money.py
parent3a90ab0dbf5826bc7476971cd163c9a080d2fb2f (diff)
downloadee-python-a8ec679349c3eb9c33a9d33e247fd86cb8e53f81.tar.gz
ee-python-a8ec679349c3eb9c33a9d33e247fd86cb8e53f81.tar.bz2
ee-python-a8ec679349c3eb9c33a9d33e247fd86cb8e53f81.tar.xz
ee-python-a8ec679349c3eb9c33a9d33e247fd86cb8e53f81.zip
o Adding PriceBreak. Parsing price breaks from DK.
o Adding Money type with parsing.
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