Added tests for sch_variant and pdf_print_sch
For the filter and variant stuff.
This commit is contained in:
parent
c26481790a
commit
7f6144e32e
3
Makefile
3
Makefile
|
|
@ -106,6 +106,9 @@ gen_ref:
|
||||||
cp -a $(REFILL).refill $(REFILL)
|
cp -a $(REFILL).refill $(REFILL)
|
||||||
src/kibot -c tests/yaml_samples/pdf_zone-refill.kibot.yaml -b tests/board_samples/zone-refill.kicad_pcb -d $(REFDIR)
|
src/kibot -c tests/yaml_samples/pdf_zone-refill.kibot.yaml -b tests/board_samples/zone-refill.kicad_pcb -d $(REFDIR)
|
||||||
src/kibot -c tests/yaml_samples/print_pcb_zone-refill.kibot.yaml -b tests/board_samples/zone-refill.kicad_pcb -d $(REFDIR)
|
src/kibot -c tests/yaml_samples/print_pcb_zone-refill.kibot.yaml -b tests/board_samples/zone-refill.kicad_pcb -d $(REFDIR)
|
||||||
|
src/kibot -c tests/yaml_samples/sch_no_inductors.kibot.yaml -e tests/board_samples/test_v5.sch -d $(REFDIR)
|
||||||
|
mv "$(REFDIR)no_inductor/test_v5-schematic_(no_L).pdf" $(REFDIR)
|
||||||
|
rmdir $(REFDIR)no_inductor/
|
||||||
cp -a $(REFILL).ok $(REFILL)
|
cp -a $(REFILL).ok $(REFILL)
|
||||||
|
|
||||||
doc:
|
doc:
|
||||||
|
|
|
||||||
Binary file not shown.
|
|
@ -11,17 +11,20 @@ pytest-3 --log-cli-level debug
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
import logging
|
||||||
# Look for the 'utils' module from where the script is running
|
# Look for the 'utils' module from where the script is running
|
||||||
prev_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
prev_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||||
if prev_dir not in sys.path:
|
if prev_dir not in sys.path:
|
||||||
sys.path.insert(0, prev_dir)
|
sys.path.insert(0, prev_dir)
|
||||||
from kibot.misc import (PDF_SCH_PRINT, SVG_SCH_PRINT)
|
from kibot.misc import (PDF_SCH_PRINT, SVG_SCH_PRINT)
|
||||||
|
from kibot.kicad.v5_sch import Schematic, SchFileError
|
||||||
# Utils import
|
# Utils import
|
||||||
from utils import context
|
from utils import context
|
||||||
|
|
||||||
PDF_DIR = ''
|
PDF_DIR = ''
|
||||||
PDF_FILE = 'Schematic.pdf'
|
PDF_FILE = 'Schematic.pdf'
|
||||||
SVG_FILE = 'Schematic.svg'
|
SVG_FILE = 'Schematic.svg'
|
||||||
|
NI_DIR = 'no_inductor'
|
||||||
|
|
||||||
|
|
||||||
def test_print_sch_ok():
|
def test_print_sch_ok():
|
||||||
|
|
@ -54,3 +57,61 @@ def test_print_sch_svg_fail():
|
||||||
ctx = context.TestContext('PrSCHFail_SVG', prj, 'print_sch_svg', PDF_DIR)
|
ctx = context.TestContext('PrSCHFail_SVG', prj, 'print_sch_svg', PDF_DIR)
|
||||||
ctx.run(SVG_SCH_PRINT, no_board_file=True, extra=['-e', os.path.join(ctx.get_board_dir(), 'print_err.sch')])
|
ctx.run(SVG_SCH_PRINT, no_board_file=True, extra=['-e', os.path.join(ctx.get_board_dir(), 'print_err.sch')])
|
||||||
ctx.clean_up()
|
ctx.clean_up()
|
||||||
|
|
||||||
|
|
||||||
|
def check_l1(ctx):
|
||||||
|
ctx.run()
|
||||||
|
o_name = os.path.join(NI_DIR, 'test_v5.sch')
|
||||||
|
ctx.expect_out_file(o_name)
|
||||||
|
sch = Schematic()
|
||||||
|
try:
|
||||||
|
sch.load(ctx.get_out_path(o_name))
|
||||||
|
except SchFileError as e:
|
||||||
|
logging.error('At line {} of `{}`: {}'.format(e.line, e.file, e.msg))
|
||||||
|
logging.error('Line content: `{}`'.format(e.code))
|
||||||
|
assert False
|
||||||
|
comps = sch.get_components()
|
||||||
|
l1 = next(c for c in comps if c.ref == 'L1')
|
||||||
|
assert l1
|
||||||
|
logging.debug('Found L1')
|
||||||
|
assert l1.lib == 'n'
|
||||||
|
logging.debug('L1 is crossed')
|
||||||
|
ctx.clean_up()
|
||||||
|
|
||||||
|
|
||||||
|
def test_sch_variant_ni_1():
|
||||||
|
""" Using a variant """
|
||||||
|
prj = 'test_v5' # Is the most complete, contains every KiCad object I know
|
||||||
|
ctx = context.TestContextSCH('test_sch_variant_ni_1', prj, 'sch_no_inductors_1', PDF_DIR)
|
||||||
|
check_l1(ctx)
|
||||||
|
|
||||||
|
|
||||||
|
def test_sch_variant_ni_2():
|
||||||
|
""" Using a filter """
|
||||||
|
prj = 'test_v5' # Is the most complete, contains every KiCad object I know
|
||||||
|
ctx = context.TestContextSCH('test_sch_variant_ni_2', prj, 'sch_no_inductors_2', PDF_DIR)
|
||||||
|
check_l1(ctx)
|
||||||
|
|
||||||
|
|
||||||
|
def test_print_sch_variant_ni_1():
|
||||||
|
""" Using a variant """
|
||||||
|
prj = 'test_v5' # Is the most complete, contains every KiCad object I know
|
||||||
|
ctx = context.TestContextSCH('test_print_sch_variant_ni_1', prj, 'print_pdf_no_inductors_1', PDF_DIR)
|
||||||
|
ctx.run()
|
||||||
|
r_name = 'test_v5-schematic_(no_L).pdf'
|
||||||
|
o_name = os.path.join(NI_DIR, r_name)
|
||||||
|
ctx.expect_out_file(o_name)
|
||||||
|
ctx.compare_pdf(o_name, r_name)
|
||||||
|
ctx.clean_up()
|
||||||
|
|
||||||
|
|
||||||
|
def test_print_sch_variant_ni_2():
|
||||||
|
""" Using a filter """
|
||||||
|
prj = 'test_v5' # Is the most complete, contains every KiCad object I know
|
||||||
|
ctx = context.TestContextSCH('test_print_sch_variant_ni_2', prj, 'print_pdf_no_inductors_2', PDF_DIR)
|
||||||
|
ctx.run()
|
||||||
|
r_name = 'test_v5-schematic_(no_L).pdf'
|
||||||
|
o_name = os.path.join(NI_DIR, 'test_v5-schematic.pdf')
|
||||||
|
ctx.expect_out_file(o_name)
|
||||||
|
ctx.compare_pdf(o_name, r_name)
|
||||||
|
ctx.clean_up()
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,10 @@ MODE_SCH = 1
|
||||||
MODE_PCB = 0
|
MODE_PCB = 0
|
||||||
|
|
||||||
|
|
||||||
|
def quote(s):
|
||||||
|
return '"'+s+'"'
|
||||||
|
|
||||||
|
|
||||||
class TestContext(object):
|
class TestContext(object):
|
||||||
|
|
||||||
def __init__(self, test_name, board_name, yaml_name, sub_dir, yaml_compressed=False):
|
def __init__(self, test_name, board_name, yaml_name, sub_dir, yaml_compressed=False):
|
||||||
|
|
@ -296,17 +300,21 @@ class TestContext(object):
|
||||||
m = re.search(t, txt, re.MULTILINE)
|
m = re.search(t, txt, re.MULTILINE)
|
||||||
assert m is None
|
assert m is None
|
||||||
|
|
||||||
def compare_image(self, image, reference=None, diff='diff.png'):
|
def compare_image(self, image, reference=None, diff='diff.png', ref_out_dir=False):
|
||||||
""" For images and single page PDFs """
|
""" For images and single page PDFs """
|
||||||
if reference is None:
|
if reference is None:
|
||||||
reference = image
|
reference = image
|
||||||
|
if ref_out_dir:
|
||||||
|
reference = self.get_out_path(reference)
|
||||||
|
else:
|
||||||
|
reference = os.path.join(REF_DIR, reference)
|
||||||
cmd = ['compare',
|
cmd = ['compare',
|
||||||
# Tolerate 5 % error in color
|
# Tolerate 5 % error in color
|
||||||
'-fuzz', '5%',
|
'-fuzz', '5%',
|
||||||
# Count how many pixels differ
|
# Count how many pixels differ
|
||||||
'-metric', 'AE',
|
'-metric', 'AE',
|
||||||
self.get_out_path(image),
|
self.get_out_path(image),
|
||||||
os.path.join(REF_DIR, reference),
|
reference,
|
||||||
# Avoid the part where KiCad version is printed
|
# Avoid the part where KiCad version is printed
|
||||||
'-crop', '100%x92%+0+0', '+repage',
|
'-crop', '100%x92%+0+0', '+repage',
|
||||||
'-colorspace', 'RGB',
|
'-colorspace', 'RGB',
|
||||||
|
|
@ -344,16 +352,7 @@ class TestContext(object):
|
||||||
assert len(ref_pages) == len(gen_pages)
|
assert len(ref_pages) == len(gen_pages)
|
||||||
# Compare each page
|
# Compare each page
|
||||||
for page in range(len(ref_pages)):
|
for page in range(len(ref_pages)):
|
||||||
cmd = ['compare', '-metric', 'MSE',
|
self.compare_image('gen-'+str(page)+'.png', 'ref-'+str(page)+'.png', diff.format(page), ref_out_dir=True)
|
||||||
self.get_out_path('ref-'+str(page)+'.png'),
|
|
||||||
self.get_out_path('gen-'+str(page)+'.png'),
|
|
||||||
self.get_out_path(diff.format(page))]
|
|
||||||
logging.debug('Comparing images with: '+str(cmd))
|
|
||||||
res = subprocess.check_output(cmd, stderr=subprocess.STDOUT)
|
|
||||||
m = re.match(r'([\d\.]+) \(([\d\.]+)\)', res.decode())
|
|
||||||
assert m
|
|
||||||
logging.debug('MSE={} ({})'.format(m.group(1), m.group(2)))
|
|
||||||
assert float(m.group(2)) == 0.0
|
|
||||||
|
|
||||||
def compare_txt(self, text, reference=None, diff='diff.txt'):
|
def compare_txt(self, text, reference=None, diff='diff.txt'):
|
||||||
if reference is None:
|
if reference is None:
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,25 @@
|
||||||
|
# Example KiBot config file
|
||||||
|
kibot:
|
||||||
|
version: 1
|
||||||
|
|
||||||
|
filters:
|
||||||
|
- name: 'no_inductor'
|
||||||
|
comment: 'Inductors removed'
|
||||||
|
type: generic
|
||||||
|
exclude_refs:
|
||||||
|
- L*
|
||||||
|
|
||||||
|
variants:
|
||||||
|
- name: 'no_inductor'
|
||||||
|
comment: 'Inductors removed'
|
||||||
|
type: kibom
|
||||||
|
file_id: '_(no_L)'
|
||||||
|
dnf_filter: 'no_inductor'
|
||||||
|
|
||||||
|
outputs:
|
||||||
|
- name: 'no_inductor'
|
||||||
|
comment: "Inductors removed"
|
||||||
|
type: pdf_sch_print
|
||||||
|
dir: no_inductor
|
||||||
|
options:
|
||||||
|
variant: 'no_inductor'
|
||||||
|
|
@ -0,0 +1,18 @@
|
||||||
|
# Example KiBot config file
|
||||||
|
kibot:
|
||||||
|
version: 1
|
||||||
|
|
||||||
|
filters:
|
||||||
|
- name: 'no_inductor'
|
||||||
|
comment: 'Inductors removed'
|
||||||
|
type: generic
|
||||||
|
exclude_refs:
|
||||||
|
- L*
|
||||||
|
|
||||||
|
outputs:
|
||||||
|
- name: 'no_inductor'
|
||||||
|
comment: "Inductors removed"
|
||||||
|
type: pdf_sch_print
|
||||||
|
dir: no_inductor
|
||||||
|
options:
|
||||||
|
dnf_filter: 'no_inductor'
|
||||||
|
|
@ -0,0 +1,25 @@
|
||||||
|
# Example KiBot config file
|
||||||
|
kibot:
|
||||||
|
version: 1
|
||||||
|
|
||||||
|
filters:
|
||||||
|
- name: 'no_inductor'
|
||||||
|
comment: 'Inductors removed'
|
||||||
|
type: generic
|
||||||
|
exclude_refs:
|
||||||
|
- L*
|
||||||
|
|
||||||
|
variants:
|
||||||
|
- name: 'no_inductor'
|
||||||
|
comment: 'Inductors removed'
|
||||||
|
type: kibom
|
||||||
|
file_id: '_(no_L)'
|
||||||
|
dnf_filter: 'no_inductor'
|
||||||
|
|
||||||
|
outputs:
|
||||||
|
- name: 'no_inductor'
|
||||||
|
comment: "Inductors removed"
|
||||||
|
type: sch_variant
|
||||||
|
dir: no_inductor
|
||||||
|
options:
|
||||||
|
variant: 'no_inductor'
|
||||||
|
|
@ -0,0 +1,18 @@
|
||||||
|
# Example KiBot config file
|
||||||
|
kibot:
|
||||||
|
version: 1
|
||||||
|
|
||||||
|
filters:
|
||||||
|
- name: 'no_inductor'
|
||||||
|
comment: 'Inductors removed'
|
||||||
|
type: generic
|
||||||
|
exclude_refs:
|
||||||
|
- L*
|
||||||
|
|
||||||
|
outputs:
|
||||||
|
- name: 'no_inductor'
|
||||||
|
comment: "Inductors removed"
|
||||||
|
type: sch_variant
|
||||||
|
dir: no_inductor
|
||||||
|
options:
|
||||||
|
dnf_filter: 'no_inductor'
|
||||||
Loading…
Reference in New Issue