Added small test for KiBoM files

This commit is contained in:
Salvador E. Tropea 2020-05-15 10:40:29 -03:00
parent 1e4440670c
commit d8daa8b4e7
7 changed files with 257 additions and 4 deletions

View File

@ -6,6 +6,8 @@ name: Python application
on:
push:
branches: [ master ]
tags-ignore:
- "v*"
pull_request:
branches: [ master ]

View File

@ -0,0 +1 @@
(kicad_pcb (version 4) (host kicad "dummy file") )

View File

@ -0,0 +1,97 @@
EESchema Schematic File Version 4
EELAYER 30 0
EELAYER END
$Descr A4 11693 8268
encoding utf-8
Sheet 1 1
Title ""
Date ""
Rev ""
Comp ""
Comment1 ""
Comment2 ""
Comment3 ""
Comment4 ""
$EndDescr
$Comp
L Device:R R1
U 1 1 5EBE8A2E
P 3500 2200
F 0 "R1" H 3570 2246 50 0000 L CNN
F 1 "100" H 3570 2155 50 0000 L CNN
F 2 "" V 3430 2200 50 0001 C CNN
F 3 "~" H 3500 2200 50 0001 C CNN
1 3500 2200
1 0 0 -1
$EndComp
$Comp
L Device:R R2
U 1 1 5EBE8E9E
P 3500 2750
F 0 "R2" H 3570 2796 50 0000 L CNN
F 1 "200" H 3570 2705 50 0000 L CNN
F 2 "" V 3430 2750 50 0001 C CNN
F 3 "~" H 3500 2750 50 0001 C CNN
1 3500 2750
1 0 0 -1
$EndComp
$Comp
L Device:C C1
U 1 1 5EBE91AC
P 3900 2750
F 0 "C1" H 4015 2796 50 0000 L CNN
F 1 "1uF" H 4015 2705 50 0000 L CNN
F 2 "" H 3938 2600 50 0001 C CNN
F 3 "~" H 3900 2750 50 0001 C CNN
1 3900 2750
1 0 0 -1
$EndComp
Wire Wire Line
3500 2350 3500 2450
Wire Wire Line
3900 2600 3900 2450
Wire Wire Line
3900 2450 3500 2450
Connection ~ 3500 2450
Wire Wire Line
3500 2450 3500 2600
$Comp
L power:GND #PWR03
U 1 1 5EBE965A
P 3900 3000
F 0 "#PWR03" H 3900 2750 50 0001 C CNN
F 1 "GND" H 3905 2827 50 0000 C CNN
F 2 "" H 3900 3000 50 0001 C CNN
F 3 "" H 3900 3000 50 0001 C CNN
1 3900 3000
1 0 0 -1
$EndComp
$Comp
L power:GND #PWR02
U 1 1 5EBE9830
P 3500 3000
F 0 "#PWR02" H 3500 2750 50 0001 C CNN
F 1 "GND" H 3505 2827 50 0000 C CNN
F 2 "" H 3500 3000 50 0001 C CNN
F 3 "" H 3500 3000 50 0001 C CNN
1 3500 3000
1 0 0 -1
$EndComp
$Comp
L power:VCC #PWR01
U 1 1 5EBE99A0
P 3500 1950
F 0 "#PWR01" H 3500 1800 50 0001 C CNN
F 1 "VCC" H 3517 2123 50 0000 C CNN
F 2 "" H 3500 1950 50 0001 C CNN
F 3 "" H 3500 1950 50 0001 C CNN
1 3500 1950
1 0 0 -1
$EndComp
Wire Wire Line
3500 2050 3500 1950
Wire Wire Line
3500 3000 3500 2900
Wire Wire Line
3900 3000 3900 2900
$EndSCHEMATC

View File

@ -0,0 +1,95 @@
<?xml version="1.0" encoding="UTF-8"?>
<export version="D">
<design>
<source>/home/salvador/0Data/Eccosur/kiplot.INTI-CMNB/tests/board_samples/bom/bom.sch</source>
<date>vie 15 may 2020 09:26:40 -03</date>
<tool>Eeschema 5.1.5+dfsg1-2~bpo10+1</tool>
<sheet number="1" name="/" tstamps="/">
<title_block>
<title/>
<company/>
<rev/>
<date/>
<source>bom.sch</source>
<comment number="1" value=""/>
<comment number="2" value=""/>
<comment number="3" value=""/>
<comment number="4" value=""/>
</title_block>
</sheet>
</design>
<components>
<comp ref="R1">
<value>100</value>
<datasheet>~</datasheet>
<libsource lib="Device" part="R" description="Resistor"/>
<sheetpath names="/" tstamps="/"/>
<tstamp>5EBE8A2E</tstamp>
</comp>
<comp ref="R2">
<value>200</value>
<datasheet>~</datasheet>
<libsource lib="Device" part="R" description="Resistor"/>
<sheetpath names="/" tstamps="/"/>
<tstamp>5EBE8E9E</tstamp>
</comp>
<comp ref="C1">
<value>1uF</value>
<datasheet>~</datasheet>
<libsource lib="Device" part="C" description="Unpolarized capacitor"/>
<sheetpath names="/" tstamps="/"/>
<tstamp>5EBE91AC</tstamp>
</comp>
</components>
<libparts>
<libpart lib="Device" part="C">
<description>Unpolarized capacitor</description>
<docs>~</docs>
<footprints>
<fp>C_*</fp>
</footprints>
<fields>
<field name="Reference">C</field>
<field name="Value">C</field>
</fields>
<pins>
<pin num="1" name="~" type="passive"/>
<pin num="2" name="~" type="passive"/>
</pins>
</libpart>
<libpart lib="Device" part="R">
<description>Resistor</description>
<docs>~</docs>
<footprints>
<fp>R_*</fp>
</footprints>
<fields>
<field name="Reference">R</field>
<field name="Value">R</field>
</fields>
<pins>
<pin num="1" name="~" type="passive"/>
<pin num="2" name="~" type="passive"/>
</pins>
</libpart>
</libparts>
<libraries>
<library logical="Device">
<uri>/usr/share/kicad/library/Device.lib</uri>
</library>
</libraries>
<nets>
<net code="1" name="Net-(C1-Pad1)">
<node ref="R1" pin="2"/>
<node ref="R2" pin="1"/>
<node ref="C1" pin="1"/>
</net>
<net code="2" name="GND">
<node ref="R2" pin="2"/>
<node ref="C1" pin="2"/>
</net>
<net code="3" name="VCC">
<node ref="R1" pin="1"/>
</net>
</nets>
</export>

View File

@ -0,0 +1,37 @@
"""
Tests of KiBoM BoM files
The 3Rs.kicad_pcb has R1 on top, R2 on bottom and a thru-hole component R3 on top.
We test:
- Separated N/PTH files with DRL, Gerber and PDF map
For debug information use:
pytest-3 --log-cli-level debug
"""
import os
import sys
# Look for the 'utils' module from where the script is running
script_dir = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, os.path.dirname(script_dir))
# Utils import
from utils import context
BOM_DIR = 'BoM'
def test_bom():
prj = 'bom'
ctx = context.TestContext('BoM_simple', prj, prj, BOM_DIR)
ctx.run()
# Check all outputs are there
# Default format is PRJ_bom_REVISION
name = os.path.join(BOM_DIR, prj+'_bom_')
csv = name+'.csv'
html = name+'.html'
ctx.expect_out_file(csv)
ctx.expect_out_file(html)
ctx.search_in_file(csv, ['R,R1,100', 'R,R2,200', 'C,C1,1uF'])
os.remove(os.path.join(ctx.get_board_dir(), 'bom.ini'))
ctx.clean_up()

View File

@ -39,12 +39,12 @@ class TestContext(object):
self.err = None
self.proc = None
def _get_board_dir(self):
def get_board_dir(self):
this_dir = os.path.dirname(os.path.realpath(__file__))
return os.path.join(this_dir, '../board_samples')
def _get_board_file(self):
self.board_file = os.path.abspath(os.path.join(self._get_board_dir(),
self.board_file = os.path.abspath(os.path.join(self.get_board_dir(),
self.board_name +
(KICAD_PCB_EXT if self.mode == MODE_PCB else KICAD_SCH_EXT)))
logging.info('KiCad file: '+self.board_file)
@ -116,6 +116,7 @@ class TestContext(object):
file = self.get_out_path(filename)
assert os.path.isfile(file)
assert os.path.getsize(file) > 0
logging.debug(filename+' OK')
return file
def dont_expect_out_file(self, filename):
@ -132,6 +133,7 @@ class TestContext(object):
# Change the command to be local and add the board and output arguments
cmd = [COVERAGE_SCRIPT, 'run', '-a']
cmd.append(os.path.abspath(os.path.dirname(os.path.abspath(__file__))+'/../../src/kiplot'))
cmd.append('-vv')
cmd = cmd+['-b', filename if filename else self.board_file]
cmd = cmd+['-c', self.yaml_file]
cmd = cmd+['-d', self.output_dir]
@ -306,7 +308,7 @@ class TestContext(object):
class TestContextSCH(TestContext):
def __init__(self, test_name, board_name, yaml_name):
super().__init__(test_name, board_name, yaml_name)
def __init__(self, test_name, board_name, yaml_name, sub_dir):
super().__init__(test_name, board_name, yaml_name, sub_dir)
self.mode = MODE_SCH
self._get_board_file()

View File

@ -0,0 +1,19 @@
# Example KiPlot config file
kiplot:
version: 1
outputs:
- name: 'bom_html'
comment: "Bill of Materials in HTML format"
type: kibom
dir: BoM
options:
format: HTML # HTML or CSV
- name: 'bom_csv'
comment: "Bill of Materials in CSV format"
type: kibom
dir: BoM
options:
format: CSV # HTML or CSV