From c895e6c051cfda77a22b31367cf5c0bbedce4249 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Sun, 13 Aug 2017 11:22:07 +0200 Subject: o Going more jupyter. --- test/test_bom.py | 41 +++++++++++++++++++++++++++++++++++++++++ test/test_digikey.py | 16 ++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 test/test_digikey.py (limited to 'test') diff --git a/test/test_bom.py b/test/test_bom.py index 1a54a9e..6da7798 100644 --- a/test/test_bom.py +++ b/test/test_bom.py @@ -1,11 +1,22 @@ import pytest import os.path +import sys from ee.kicad.bom import * from ee.kicad.bom.io import read_bom basedir = os.path.dirname(os.path.abspath(__file__)) +@pytest.mark.parametrize("s, ref, val, rest", [ + ("C12", "C", 12, ""), + ("C12n", "C", 12, "n"), + ("C", "C", sys.maxsize, ""), + ("Foo", "Foo", sys.maxsize, ""), + ("+3.0VA1", "+3.0VA1", sys.maxsize, ""), + ]) +def test_split_ref(s, ref, val, rest): + assert split_ref(s) == (ref, val, rest) + def test_read_bom_1(): bom = read_bom(basedir + '/../demo/kicad/bom/A64-OlinuXino_Rev_C.xml') assert len(bom.get_components()) == 425 @@ -17,7 +28,37 @@ def test_read_bom_2(): r5 = bom.get_component("R5") assert r5.ref == "R5" assert r5.value == "R0402_100R" + assert r5["value"] == "R0402_100R" assert r5.footprint == "Resistors_SMD:R_0402" assert r5.library.name == "gw-cache" assert len(r5.fields) == 4 assert r5.fields["Part Number"] == "CRCW0402100RFKED" + assert r5["Part Number"] == "CRCW0402100RFKED" + assert set(['ref', 'value', 'Capacitance', 'Color', 'Description', 'Frequency', 'Impedance', 'Inductance', 'Manufacturer', 'Part Number', 'Resistance']) == bom.all_field_names() + + assert not "foo" in r5 + with pytest.raises(KeyError): + r5["foo"] + +def test_read_bom_2_pandas(): + bom = read_bom(basedir + '/../demo/kicad/bom/gw.xml').to_pandas() + assert len(bom) == 165 + + print("bom") + print(str(bom)) + r5 = bom.loc["R5"] + print(str(r5.index)) +# assert r5.index == "R5" + assert r5["ref"] == "R5" + assert r5["value"] == "R0402_100R" + assert r5["value"] == "R0402_100R" +# assert r5["footprint"] == "Resistors_SMD:R_0402" +# assert r5.library.name == "gw-cache" +# assert len(r5.fields) == 4 +# assert r5.fields["Part Number"] == "CRCW0402100RFKED" + assert r5["Part Number"] == "CRCW0402100RFKED" +# assert set(['ref', 'value', 'Capacitance', 'Color', 'Description', 'Frequency', 'Impedance', 'Inductance', 'Manufacturer', 'Part Number', 'Resistance']) == bom.all_field_names() + + assert not "foo" in r5 + with pytest.raises(KeyError): + r5["foo"] diff --git a/test/test_digikey.py b/test/test_digikey.py new file mode 100644 index 0000000..148f56e --- /dev/null +++ b/test/test_digikey.py @@ -0,0 +1,16 @@ +from ee.kicad.bom import * +from ee.kicad.bom.io import read_bom +import ee.kicad.bom_tool as bom_tool +import ee.kicad.bom_tool.predef as predef +import os.path +import pytest + +basedir = os.path.dirname(os.path.abspath(__file__)) + +@pytest.mark.skip(reason="disabled for now") +def test_digikey(): + print("") + bom = read_bom(basedir + '/../demo/kicad/bom/A64-OlinuXino_Rev_C.xml') + settings = bom_tool.Settings(suppliers = [predef.digikey]) + pd = bom_tool.to_panda(bom, settings, predef.digikeyCsvFormat(predef.digikey)) + print(pd.to_csv(index = False)) -- cgit v1.2.3