From 89197dad4f5f427faa7fba12971b20037ad5ba71 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Fri, 14 Jun 2019 10:40:31 +0200 Subject: split-parts-by-supplier: rename to split-bom-by-supplier. digikey-create-bom: Implementing CSV generation for Digi-Key. --- test/part/test_bom.py | 12 +++++++++ test/test_bom.py | 66 -------------------------------------------------- test/test_digikey.py | 2 +- test/test_kicad_bom.py | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 79 insertions(+), 67 deletions(-) create mode 100644 test/part/test_bom.py delete mode 100644 test/test_bom.py create mode 100644 test/test_kicad_bom.py (limited to 'test') diff --git a/test/part/test_bom.py b/test/part/test_bom.py new file mode 100644 index 0000000..85eb932 --- /dev/null +++ b/test/part/test_bom.py @@ -0,0 +1,12 @@ +import pytest +from ee.part.bom import join_refs + + +@pytest.mark.parametrize("inputs, output", [ + [[], ""], + [["C1"], "C1"], + [["C1", "C2"], "C1,2"], + [["C1", "C2", "C3", "C5", "C6", "C9"], "C1-3,5,6,9"], +]) +def test_basic(inputs, output): + assert output == join_refs(inputs) diff --git a/test/test_bom.py b/test/test_bom.py deleted file mode 100644 index 50cae9f..0000000 --- a/test/test_bom.py +++ /dev/null @@ -1,66 +0,0 @@ -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 - - -def test_read_bom_2(): - bom = read_bom(basedir + '/../demo/kicad/bom/gw.xml') - assert len(bom.get_components()) == 165 - - 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 {'ref', 'value', 'Capacitance', 'Color', 'Description', 'Frequency', 'Impedance', 'Inductance', - 'Manufacturer', 'Part Number', 'Resistance'} == bom.all_field_names() - - assert "foo" not 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 - - r5 = bom.loc["R5"] - # 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 "foo" not in r5 - with pytest.raises(KeyError): - r5["foo"] diff --git a/test/test_digikey.py b/test/test_digikey.py index f1b010b..4961a9d 100644 --- a/test/test_digikey.py +++ b/test/test_digikey.py @@ -83,7 +83,7 @@ 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" + assert p.url == "https://www.digikey.com/product-detail/en/smc-diode-solutions/RS1MTR/1655-1501-1-ND/6022946" @pytest.mark.digikey diff --git a/test/test_kicad_bom.py b/test/test_kicad_bom.py new file mode 100644 index 0000000..50cae9f --- /dev/null +++ b/test/test_kicad_bom.py @@ -0,0 +1,66 @@ +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 + + +def test_read_bom_2(): + bom = read_bom(basedir + '/../demo/kicad/bom/gw.xml') + assert len(bom.get_components()) == 165 + + 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 {'ref', 'value', 'Capacitance', 'Color', 'Description', 'Frequency', 'Impedance', 'Inductance', + 'Manufacturer', 'Part Number', 'Resistance'} == bom.all_field_names() + + assert "foo" not 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 + + r5 = bom.loc["R5"] + # 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 "foo" not in r5 + with pytest.raises(KeyError): + r5["foo"] -- cgit v1.2.3