kiacd 9.0 compatibility WIP
This commit is contained in:
parent
75905f7d0c
commit
9d2d635eee
7 changed files with 161 additions and 51 deletions
|
|
@ -77,6 +77,8 @@ def pytest_addoption(parser):
|
|||
parser.addini('kicad_footprints_tag', 'git tag or branch for KiCad footprint library repo used as testdata', default='main')
|
||||
parser.addini('kicad_symbols_tag', 'git tag or branch for KiCad symbol library repo used as testdata', default='main')
|
||||
parser.addini('kicad_container_tag', 'docker hub tag for the KiCad container to use for exporting footprint images', default='main')
|
||||
parser.addini('kicad_source_tag', 'git tag for the KiCad source repo whose demos directory is used as testdata', default='main')
|
||||
parser.addoption("--use-cached-data", action="store_true", help="Do not re-check git repo caches and podman image")
|
||||
|
||||
|
||||
def pytest_configure(config):
|
||||
|
|
@ -95,8 +97,13 @@ def pytest_configure(config):
|
|||
else:
|
||||
config.kicad_symbols_libdir = config.cache.mkdir('kicad-symbols') / 'repo'
|
||||
|
||||
if (lib_dir := os.environ.get('KICAD_SOURCE')):
|
||||
config.kicad_source_dir = Path(lib_dir).expanduser()
|
||||
else:
|
||||
config.kicad_source_dir = config.cache.mkdir('kicad-source') / 'repo'
|
||||
|
||||
is_pytest_controller = 'PYTEST_XDIST_WORKER' not in os.environ
|
||||
if is_pytest_controller:
|
||||
if is_pytest_controller and not config.getoption("--use-cached-data"):
|
||||
# Update cached library repos unless they are overridden from outside.
|
||||
if not os.environ.get('KICAD_FOOTPRINTS'):
|
||||
tag = config.getini('kicad_footprints_tag')
|
||||
|
|
@ -106,16 +113,20 @@ def pytest_configure(config):
|
|||
tag = config.getini('kicad_symbols_tag')
|
||||
_update_repo_cache(config.kicad_symbols_libdir, 'https://gitlab.com/kicad/libraries/kicad-symbols', tag)
|
||||
|
||||
if not os.environ.get('KICAD_SOURCE'):
|
||||
tag = config.getini('kicad_source_tag')
|
||||
_update_repo_cache(config.kicad_source_dir, 'https://gitlab.com/kicad/code/kicad', tag)
|
||||
|
||||
tag = config.getini("kicad_container_tag")
|
||||
config.kicad_container = os.environ.get('KICAD_CONTAINER', f'registry.hub.docker.com/kicad/kicad:{tag}')
|
||||
|
||||
if is_pytest_controller:
|
||||
if is_pytest_controller and not config.getoption("--use-cached-data"):
|
||||
print('Updating podman image')
|
||||
subprocess.run(['podman', 'pull', config.kicad_container], check=True)
|
||||
|
||||
config.image_support = ImageSupport(config.cache.mkdir('image_cache'), config.kicad_container)
|
||||
|
||||
if is_pytest_controller:
|
||||
if is_pytest_controller and not config.getoption("--use-cached-data"):
|
||||
print('Checking KiCad footprint library render cache')
|
||||
with multiprocessing.pool.ThreadPool() as pool: # use thread pool here since we're only monitoring podman processes
|
||||
lib_dirs = list(config.kicad_footprints_libdir.glob('*.pretty'))
|
||||
|
|
@ -130,3 +141,14 @@ def pytest_generate_tests(metafunc):
|
|||
if 'kicad_mod_file' in metafunc.fixturenames:
|
||||
mod_files = list(metafunc.config.kicad_footprints_libdir.glob('*.pretty/*.kicad_mod'))
|
||||
metafunc.parametrize('kicad_mod_file', mod_files, ids=list(map(str, mod_files)))
|
||||
|
||||
if 'kicad_sch_file' in metafunc.fixturenames:
|
||||
files = list(metafunc.config.kicad_source_dir.glob('demos/*.kicad_sch'))
|
||||
files += list(metafunc.config.kicad_source_dir.glob('qa/data/**/*.kicad_sch'))
|
||||
metafunc.parametrize('kicad_sch_file', files, ids=list(map(str, files)))
|
||||
|
||||
if 'kicad_pcb_file' in metafunc.fixturenames:
|
||||
files = list(metafunc.config.kicad_source_dir.glob('demos/*.kicad_pcb'))
|
||||
files += list(metafunc.config.kicad_source_dir.glob('qa/data/**/*.kicad_pcb'))
|
||||
metafunc.parametrize('kicad_pcb_file', files, ids=list(map(str, files)))
|
||||
|
||||
|
|
|
|||
30
tests/test_kicad_schematic.py
Normal file
30
tests/test_kicad_schematic.py
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
import math
|
||||
from itertools import zip_longest
|
||||
import pytest
|
||||
import subprocess
|
||||
import re
|
||||
|
||||
import bs4
|
||||
|
||||
from .utils import tmpfile, print_on_error
|
||||
from .image_support import run_cargo_cmd, svg_soup
|
||||
|
||||
from gerbonara import graphic_objects as go
|
||||
from gerbonara.utils import MM, arc_bounds, sum_bounds
|
||||
from gerbonara.layers import LayerStack
|
||||
from gerbonara.cad.kicad.sexp import build_sexp, Atom
|
||||
from gerbonara.cad.kicad.sexp_mapper import sexp
|
||||
from gerbonara.cad.kicad.tmtheme import *
|
||||
from gerbonara.cad.kicad.schematic import Schematic
|
||||
|
||||
|
||||
def test_load_kicad_schematic(kicad_sch_file):
|
||||
if kicad_sch_file.name in [
|
||||
# contains legacy syntax
|
||||
]:
|
||||
pytest.skip()
|
||||
sch = Schematic.open(kicad_sch_file)
|
||||
print('Loaded schematic with', len(sch.wires), 'wires and', len(sch.symbols), 'symbols.')
|
||||
for subsh in sch.subsheets:
|
||||
subsh = subsh.open()
|
||||
print('Loaded sub-sheet with', len(subsh.wires), 'wires and', len(subsh.symbols), 'symbols.')
|
||||
Loading…
Add table
Add a link
Reference in a new issue