aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2017-09-30 23:05:00 +0200
committerTrygve Laugstøl <trygvis@inamo.no>2017-09-30 23:05:00 +0200
commit122850d7a90428b6d7b92fe6100a1f2a6df2a1eb (patch)
tree5408d8509b42fc6ee53b608674da3dcb8e0578f7 /test
parent88e878626eac92d255b763b1ba5da5b393bfdc2f (diff)
downloadee-python-122850d7a90428b6d7b92fe6100a1f2a6df2a1eb.tar.gz
ee-python-122850d7a90428b6d7b92fe6100a1f2a6df2a1eb.tar.bz2
ee-python-122850d7a90428b6d7b92fe6100a1f2a6df2a1eb.tar.xz
ee-python-122850d7a90428b6d7b92fe6100a1f2a6df2a1eb.zip
o Switching from YAML to INI files for downloaded facts.
o Improved fact downloader.
Diffstat (limited to 'test')
-rw-r--r--test/test_digikey.py40
1 files changed, 33 insertions, 7 deletions
diff --git a/test/test_digikey.py b/test/test_digikey.py
index 7509e2b..04b4642 100644
--- a/test/test_digikey.py
+++ b/test/test_digikey.py
@@ -1,7 +1,8 @@
import ee.digikey as dk
import os.path
-import yaml
import sys
+import io
+from itertools import groupby
basedir = os.path.dirname(os.path.abspath(__file__))
@@ -9,20 +10,45 @@ digikey = dk.Digikey()
client = dk.DigikeyClient(digikey, on_download=print)
-def test_digikey_1():
+def test_digikey_1(tmpdir):
res = client.search("TCR2LF18LM(CTTR-ND")
assert res.response_type == dk.SearchResponseTypes.SINGLE
p = res.products[0]
assert p.part_number == "TCR2LF18LM(CTTR-ND"
assert p.mpn == "TCR2LF18,LM(CT"
assert len(p.attributes) > 5
- x = p.to_yaml()
- print(str(x))
- yaml.dump(x, sys.stdout)
+ x = io.StringIO()
+ p.to_ini().write(x)
+ print(x.getvalue())
+ repo = dk.DigikeyRepository(digikey, str(tmpdir))
+ repo.save(p)
+ repo = dk.DigikeyRepository(digikey, str(tmpdir))
+ repo.load_all()
+ ps = repo.find_by_mpn(p.mpn)
+ assert len(ps) == 1
+ y = io.StringIO()
+ p.to_ini().write(y)
+ assert x.getvalue() == y.getvalue()
-def test_digikey_2():
+
+def test_digikey_2(tmpdir):
res = client.search("TCR2LF", page_size=500)
assert res.response_type == dk.SearchResponseTypes.MANY
- [print(p.part_number) for p in res.products]
+ [print("dpn={}, mpn={}".format(p.part_number, p.mpn)) for p in res.products]
assert len(res.products) == 28
+
+ print("path={}".format(tmpdir))
+ repo = dk.DigikeyRepository(digikey, tmpdir)
+
+ for mpn, parts in groupby(sorted(res.products, key=lambda p: p.mpn), lambda p: p.mpn):
+ parts = list(parts)
+ print("mpn={}, parts={}".format(mpn, [p.part_number for p in parts]))
+
+ dpn = parts[0].part_number
+ print("Downloading {} as {}".format(mpn, dpn))
+ res = client.search(dpn)
+
+ assert res.response_type == dk.SearchResponseTypes.SINGLE
+ p = res.products[0]
+ repo.save(p)