diff options
author | jaseg <git@jaseg.de> | 2023-04-15 17:09:20 +0200 |
---|---|---|
committer | jaseg <git@jaseg.de> | 2023-04-15 17:09:20 +0200 |
commit | 2400ff8e5fea41c1f8c6251d37a02209ec253f93 (patch) | |
tree | 395968d05156c094709fda605a9fe572aed32b1d /gerbonara/tests/conftest.py | |
parent | b43e4e2eec99b92a1e87f6388703db1ca33518d1 (diff) | |
download | gerbonara-2400ff8e5fea41c1f8c6251d37a02209ec253f93.tar.gz gerbonara-2400ff8e5fea41c1f8c6251d37a02209ec253f93.tar.bz2 gerbonara-2400ff8e5fea41c1f8c6251d37a02209ec253f93.zip |
cad: Add KiCad symbol/footprint parser
Diffstat (limited to 'gerbonara/tests/conftest.py')
-rw-r--r-- | gerbonara/tests/conftest.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/gerbonara/tests/conftest.py b/gerbonara/tests/conftest.py index b999027..bd89901 100644 --- a/gerbonara/tests/conftest.py +++ b/gerbonara/tests/conftest.py @@ -1,4 +1,5 @@ +import os from pathlib import Path import pytest @@ -33,3 +34,30 @@ def pytest_sessionstart(session): run_cargo_cmd('resvg', '--help') except FileNotFoundError: pytest.exit('resvg binary not found, aborting test.', 2) + +def pytest_addoption(parser): + parser.addoption('--kicad-symbol-library', nargs='*', help='Run symbol library tests on given symbol libraries. May be given multiple times.') + parser.addoption('--kicad-footprint-files', nargs='*', help='Run footprint library tests on given footprint files. May be given multiple times.') + +def pytest_generate_tests(metafunc): + if 'kicad_library_file' in metafunc.fixturenames: + if not (library_files := metafunc.config.getoption('symbol_library', None)): + if (lib_dir := os.environ.get('KICAD_SYMBOLS')): + lib_dir = Path(lib_dir).expanduser() + if not lib_dir.is_dir(): + raise ValueError(f'Path "{lib_dir}" given by KICAD_SYMBOLS environment variable does not exist or is not a directory.') + library_files = list(lib_dir.glob('*.kicad_sym')) + else: + raise ValueError('Either --kicad-symbol-library command line parameter or KICAD_SYMBOLS environment variable must be given.') + metafunc.parametrize('kicad_library_file', library_files, ids=list(map(str, library_files))) + + if 'kicad_mod_file' in metafunc.fixturenames: + if not (mod_files := metafunc.config.getoption('footprint_files', None)): + if (lib_dir := os.environ.get('KICAD_FOOTPRINTS')): + lib_dir = Path(lib_dir).expanduser() + if not lib_dir.is_dir(): + raise ValueError(f'Path "{lib_dir}" given by KICAD_FOOTPRINTS environment variable does not exist or is not a directory.') + mod_files = list(lib_dir.glob('**/*.kicad_mod')) + else: + raise ValueError('Either --kicad-footprint-files command line parameter or KICAD_FOOTPRINTS environment variable must be given.') + metafunc.parametrize('kicad_mod_file', mod_files, ids=list(map(str, mod_files))) |