aboutsummaryrefslogtreecommitdiff
path: root/test
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
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')
-rw-r--r--test/test_digikey.py6
-rw-r--r--test/test_money.py60
2 files changed, 65 insertions, 1 deletions
diff --git a/test/test_digikey.py b/test/test_digikey.py
index ccdc083..2e9b1f1 100644
--- a/test/test_digikey.py
+++ b/test/test_digikey.py
@@ -5,6 +5,7 @@ from pathlib import Path
import pytest
import ee.digikey as dk
+from ee.money import Money
basedir = Path(__file__).parent
static_copies = basedir / "digikey" / "static-copies" # type: Path
@@ -26,6 +27,10 @@ def test_digikey_1(tmpdir):
assert p.mpn == "TCR2LF18,LM(CT"
assert len(p.attributes) > 5
+ assert len(p.price_breaks) == 6
+ assert p.price_breaks[0].quantity == 3000
+ assert p.price_breaks[0].price == Money("USD 0.07")
+
repo = dk.DigikeyRepository(digikey, str(tmpdir))
x = io.StringIO()
p.to_ini(repo._make_configparser()).write(x)
@@ -78,4 +83,3 @@ def test_digikey_3():
p = next((p for p in res.products if p.part_number == "1655-1501-1-ND"), None)
assert p.mpn == "RS1MTR"
assert p.url == "/product-detail/en/smc-diode-solutions/RS1MTR/1655-1501-1-ND/6022946"
-
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