Added tests for various schematic strange cases.
- Component withour lib - Missing component - Poligon without points - Pin with unknown direction
This commit is contained in:
parent
018d99e3b2
commit
220e2f252e
|
|
@ -9,6 +9,7 @@ F1 "R" 0 0 50 V V C CNN
|
||||||
F2 "" -70 0 50 V I C CNN
|
F2 "" -70 0 50 V I C CNN
|
||||||
F3 "" 0 0 50 H I C CNN
|
F3 "" 0 0 50 H I C CNN
|
||||||
F4 "Hi!" 0 0 50 H I C CNN "Test"
|
F4 "Hi!" 0 0 50 H I C CNN "Test"
|
||||||
|
ALIAS Resistor
|
||||||
$FPLIST
|
$FPLIST
|
||||||
R_*
|
R_*
|
||||||
R_*
|
R_*
|
||||||
|
|
@ -37,4 +38,22 @@ P 5 0 0 0 -50 -75 75 -75 0 100 -75 -75 -50 -75 f
|
||||||
ENDDRAW
|
ENDDRAW
|
||||||
ENDDEF
|
ENDDEF
|
||||||
#
|
#
|
||||||
|
# C
|
||||||
|
#
|
||||||
|
DEF C C 0 10 N Y 1 F N
|
||||||
|
F0 "C" 25 100 50 H V L CNN
|
||||||
|
F1 "C" 25 -100 50 H V L CNN
|
||||||
|
F2 "" 38 -150 50 H I C CNN
|
||||||
|
F3 "" 0 0 50 H I C CNN
|
||||||
|
$FPLIST
|
||||||
|
C_*
|
||||||
|
$ENDFPLIST
|
||||||
|
DRAW
|
||||||
|
P 2 0 1 20 -80 -30 80 -30 N
|
||||||
|
P 2 0 1 20 -80 30 80 30 N
|
||||||
|
X ~ 1 0 150 110 D 50 50 1 1 P
|
||||||
|
X ~ 2 0 -150 110 U 50 50 1 1 P
|
||||||
|
ENDDRAW
|
||||||
|
ENDDEF
|
||||||
|
#
|
||||||
#End Library
|
#End Library
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,66 @@
|
||||||
|
EESchema Schematic File Version 4
|
||||||
|
EELAYER 30 0
|
||||||
|
EELAYER END
|
||||||
|
$Descr A4 11693 8268
|
||||||
|
encoding utf-8
|
||||||
|
Sheet 1 1
|
||||||
|
Title "KiBom Test Schematic"
|
||||||
|
Date "2020-03-12"
|
||||||
|
Rev "A"
|
||||||
|
Comp "https://github.com/SchrodingersGat/KiBom"
|
||||||
|
Comment1 ""
|
||||||
|
Comment2 ""
|
||||||
|
Comment3 ""
|
||||||
|
Comment4 ""
|
||||||
|
$EndDescr
|
||||||
|
Text Notes 550 1050 0 118 ~ 0
|
||||||
|
This schematic serves as a test file for the KiBot export script.\nHere we have a component without lib (from old KiCad?) \nand another that isn't in any lib.
|
||||||
|
$Comp
|
||||||
|
L l1:C C1
|
||||||
|
U 1 1 5F43BEC2
|
||||||
|
P 1000 1700
|
||||||
|
F 0 "C1" H 1115 1746 50 0000 L CNN
|
||||||
|
F 1 "1nF" H 1115 1655 50 0000 L CNN
|
||||||
|
F 2 "Capacitor_SMD:C_0805_2012Metric" H 1038 1550 50 0001 C CNN
|
||||||
|
F 3 "~" H 1000 1700 50 0001 C CNN
|
||||||
|
F 4 "T2" H 1000 1700 50 0001 C CNN "Config"
|
||||||
|
1 1000 1700
|
||||||
|
1 0 0 -1
|
||||||
|
$EndComp
|
||||||
|
$Comp
|
||||||
|
L l1:C C2
|
||||||
|
U 1 1 5F43CE1C
|
||||||
|
P 1450 1700
|
||||||
|
F 0 "C2" H 1565 1746 50 0000 L CNN
|
||||||
|
F 1 "1000 pF" H 1565 1655 50 0000 L CNN
|
||||||
|
F 2 "Capacitor_SMD:C_0805_2012Metric" H 1488 1550 50 0001 C CNN
|
||||||
|
F 3 "~" H 1450 1700 50 0001 C CNN
|
||||||
|
F 4 "T3" H 1450 1700 50 0001 C CNN "Config"
|
||||||
|
1 1450 1700
|
||||||
|
1 0 0 -1
|
||||||
|
$EndComp
|
||||||
|
$Comp
|
||||||
|
L Resistor R1
|
||||||
|
U 1 1 5F43D144
|
||||||
|
P 2100 1700
|
||||||
|
F 0 "R1" H 2170 1746 50 0000 L CNN
|
||||||
|
F 1 "1k" H 2170 1655 50 0000 L CNN
|
||||||
|
F 2 "Resistor_SMD:R_0805_2012Metric" V 2030 1700 50 0001 C CNN
|
||||||
|
F 3 "~" H 2100 1700 50 0001 C CNN
|
||||||
|
F 4 "default" H 2100 1700 50 0001 C CNN "Config"
|
||||||
|
1 2100 1700
|
||||||
|
1 0 0 -1
|
||||||
|
$EndComp
|
||||||
|
$Comp
|
||||||
|
L l1:FooBar R2
|
||||||
|
U 1 1 5F43D4BB
|
||||||
|
P 2500 1700
|
||||||
|
F 0 "R2" H 2570 1746 50 0000 L CNN
|
||||||
|
F 1 "1000" H 2570 1655 50 0000 L CNN
|
||||||
|
F 2 "Resistor_SMD:R_0805_2012Metric" V 2430 1700 50 0001 C CNN
|
||||||
|
F 3 "~" H 2500 1700 50 0001 C CNN
|
||||||
|
F 4 "T1" H 2500 1700 50 0001 C CNN "Config"
|
||||||
|
1 2500 1700
|
||||||
|
1 0 0 -1
|
||||||
|
$EndComp
|
||||||
|
$EndSCHEMATC
|
||||||
|
|
@ -1908,7 +1908,7 @@ B8 00 A2 1F 41 E0 C7 2A 65 BE 7E E1 F5 E7 46 4B 3D 22 C6 18 DB CE 36 66 F9 2E 00
|
||||||
EndData
|
EndData
|
||||||
$EndBitmap
|
$EndBitmap
|
||||||
$Comp
|
$Comp
|
||||||
L l1:R R1
|
L l1:Resistor R1
|
||||||
U 1 1 5F33EC02
|
U 1 1 5F33EC02
|
||||||
P 1300 3450
|
P 1300 3450
|
||||||
F 0 "R1" V 1093 3450 50 0000 C CNN
|
F 0 "R1" V 1093 3450 50 0000 C CNN
|
||||||
|
|
|
||||||
|
|
@ -12,12 +12,13 @@ pytest-3 --log-cli-level debug
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import logging
|
import logging
|
||||||
|
import coverage
|
||||||
# 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
|
from kibot.kicad.v5_sch import Schematic, SchFileError, DrawPoligon, Pin
|
||||||
# Utils import
|
# Utils import
|
||||||
from utils import context
|
from utils import context
|
||||||
|
|
||||||
|
|
@ -25,6 +26,7 @@ PDF_DIR = ''
|
||||||
PDF_FILE = 'Schematic.pdf'
|
PDF_FILE = 'Schematic.pdf'
|
||||||
SVG_FILE = 'Schematic.svg'
|
SVG_FILE = 'Schematic.svg'
|
||||||
NI_DIR = 'no_inductor'
|
NI_DIR = 'no_inductor'
|
||||||
|
cov = coverage.Coverage()
|
||||||
|
|
||||||
|
|
||||||
def test_print_sch_ok():
|
def test_print_sch_ok():
|
||||||
|
|
@ -115,3 +117,35 @@ def test_print_sch_variant_ni_2():
|
||||||
ctx.expect_out_file(o_name)
|
ctx.expect_out_file(o_name)
|
||||||
ctx.compare_pdf(o_name, r_name)
|
ctx.compare_pdf(o_name, r_name)
|
||||||
ctx.clean_up()
|
ctx.clean_up()
|
||||||
|
|
||||||
|
|
||||||
|
def test_sch_missing():
|
||||||
|
""" R1 exists in l1.lib, but the lib isn't specified.
|
||||||
|
R2 is bogus, completely missing """
|
||||||
|
prj = 'missing'
|
||||||
|
ctx = context.TestContextSCH('test_sch_missing', prj, 'sch_no_inductors_1', PDF_DIR)
|
||||||
|
ctx.run()
|
||||||
|
o_name = os.path.join(NI_DIR, prj+'.sch')
|
||||||
|
ctx.expect_out_file(o_name)
|
||||||
|
ctx.search_err("Component .?Resistor.? doesn't specify its library")
|
||||||
|
ctx.search_err("Missing component .?l1:FooBar.?")
|
||||||
|
ctx.search_err("Missing component(.*)Resistor", invert=True)
|
||||||
|
ctx.clean_up()
|
||||||
|
|
||||||
|
|
||||||
|
def test_sch_bizarre_cases():
|
||||||
|
""" Poligon without points.
|
||||||
|
Pin with unknown direction. """
|
||||||
|
pol = DrawPoligon()
|
||||||
|
pol.points = 0
|
||||||
|
pol.coords = []
|
||||||
|
pin = Pin()
|
||||||
|
pin.dir = 'bogus'
|
||||||
|
cov.load()
|
||||||
|
cov.start()
|
||||||
|
x1, y1, x2, y2, ok_pol = pol.get_rect()
|
||||||
|
x1, y1, x2, y2, ok_pin = pin.get_rect()
|
||||||
|
cov.stop()
|
||||||
|
cov.save()
|
||||||
|
assert ok_pol is False
|
||||||
|
assert ok_pin is False
|
||||||
|
|
|
||||||
|
|
@ -263,17 +263,25 @@ class TestContext(object):
|
||||||
logging.debug('output match: `{}` OK'.format(text))
|
logging.debug('output match: `{}` OK'.format(text))
|
||||||
return m
|
return m
|
||||||
|
|
||||||
def search_err(self, text):
|
def search_err(self, text, invert=False):
|
||||||
if isinstance(text, list):
|
if isinstance(text, list):
|
||||||
res = []
|
res = []
|
||||||
for t in text:
|
for t in text:
|
||||||
m = re.search(t, self.err, re.MULTILINE)
|
m = re.search(t, self.err, re.MULTILINE)
|
||||||
|
if invert:
|
||||||
|
assert m is None, t
|
||||||
|
logging.debug('error no match: `{}` OK'.format(t))
|
||||||
|
else:
|
||||||
assert m is not None, t
|
assert m is not None, t
|
||||||
logging.debug('error match: `{}` (`{}`) OK'.format(t, m.group(0)))
|
logging.debug('error match: `{}` (`{}`) OK'.format(t, m.group(0)))
|
||||||
res.append(m)
|
res.append(m)
|
||||||
return res
|
return res
|
||||||
m = re.search(text, self.err, re.MULTILINE)
|
m = re.search(text, self.err, re.MULTILINE)
|
||||||
assert m is not None
|
if invert:
|
||||||
|
assert m is None, text
|
||||||
|
logging.debug('error no match: `{}` OK'.format(text))
|
||||||
|
else:
|
||||||
|
assert m is not None, text
|
||||||
logging.debug('error match: `{}` (`{}`) OK'.format(text, m.group(0)))
|
logging.debug('error match: `{}` (`{}`) OK'.format(text, m.group(0)))
|
||||||
return m
|
return m
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue