diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/test_digikey.py | 40 |
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) |