diff --git a/tests/data/kicad_1/kicad_common b/tests/data/kicad_1/kicad_common new file mode 100644 index 00000000..4cb5b095 --- /dev/null +++ b/tests/data/kicad_1/kicad_common @@ -0,0 +1,22 @@ +UseIconsInMenus=1 +IconScale=-1 +MousewheelPAN=0 +ZoomNoCenter=0 +AutoPAN=1 +OpenGLAntialiasingMode=2 +CairoAntialiasingMode=0 +WorkingDir=/home/salvador/0Data/Eccosur/kiplot.INTI-CMNB +ShowEnvVarWarningDialog=1 +AutoSaveInterval=600 +FileHistorySize=9 +CanvasScale=0 +Editor= +PdfBrowserName= +UseSystemBrowser=1 +[EnvironmentVariables] +KICAD_SYMBOL_DIR=/usr/share/kicad/library +KICAD_TEMPLATE_DIR=/usr/share/kicad/template +KICAD_USER_TEMPLATE_DIR=/home/salvador/kicad/template +KIGITHUB=https://github.com/KiCad +KISYS3DMOD=/usr/share/kicad/modules/packages3d/ +KISYSMOD=/usr/share/kicad/modules diff --git a/tests/test_plot/test_kicad_config_errors.py b/tests/test_plot/test_kicad_config_errors.py new file mode 100644 index 00000000..e7f3e622 --- /dev/null +++ b/tests/test_plot/test_kicad_config_errors.py @@ -0,0 +1,60 @@ +""" +Tests for KiCad configuration load + + +For debug information use: +pytest-3 --log-cli-level debug +""" + +import os +import sys +import pytest +import coverage +import logging +# Look for the 'utils' module from where the script is running +prev_dir = os.path.dirname(os.path.abspath(__file__)) +sys.path.insert(0, os.path.dirname(prev_dir)) +# Utils import +from utils import context +sys.path.insert(0, os.path.dirname(prev_dir)) +from kiplot.misc import EXIT_BAD_CONFIG +from kiplot.kicad.config import KiConf + + +cov = coverage.Coverage() + + +def test_kicad_conf_bad_sym_lib_table(): + """ Check various problems in the sym-lib-table file """ + sch = 'sym-lib-table_errors/kibom-test' + test = 'test_kicad_conf_bad_sym_lib_table' + ctx = context.TestContextSCH(test, sch, 'int_bom_simple_csv', None) + ctx.run(EXIT_BAD_CONFIG, extra_debug=True) + ctx.search_err('Malformed lib entry') + ctx.search_err(r'Unable to expand .?BOGUS.? in') + ctx.search_err(r'unnamed LibAlias') + ctx.clean_up() + + +def test_kicad_conf_no_instance(): + """ Check we can't create a KiConf instance """ + cov.load() + cov.start() + with pytest.raises(AssertionError) as pytest_wrapped_e: + o = KiConf() + cov.stop() + cov.save() + assert pytest_wrapped_e.type == AssertionError + assert str(pytest_wrapped_e.value) == 'KiConf is fully static, no instances allowed' + + +def test_kicad_conf_user(caplog): + """ Check we can load the KiCad configuration from $KICAD_CONFIG_HOME """ + ctx = context.TestContextSCH('test_kicad_conf_user', 'v5_errors/kibom-test', 'int_bom_simple_csv', None) + os.environ['KICAD_CONFIG_HOME'] = 'tests/data/kicad_1' + cov.load() + cov.start() + KiConf.init(ctx.sch_file) + cov.stop() + cov.save() + assert 'Reading KiCad config from `tests/data/kicad_1/kicad_common`' in caplog.text diff --git a/tests/test_plot/test_sch_errors.py b/tests/test_plot/test_sch_errors.py index 0e7cea99..ba562539 100644 --- a/tests/test_plot/test_sch_errors.py +++ b/tests/test_plot/test_sch_errors.py @@ -14,7 +14,7 @@ sys.path.insert(0, os.path.dirname(prev_dir)) # Utils import from utils import context sys.path.insert(0, os.path.dirname(prev_dir)) -from kiplot.misc import CORRUPTED_SCH, EXIT_BAD_CONFIG +from kiplot.misc import CORRUPTED_SCH def setup_ctx(test, error): @@ -245,14 +245,3 @@ def test_sch_errors_bad_snum(): def test_sch_errors_bad_tbentry(): setup_ctx('bad_tbentry', 'Wrong entry in title block') - - -def test_sch_errors_bad_sym_lib_table(): - sch = 'sym-lib-table_errors/kibom-test' - test = 'test_sch_errors_bad_sym_lib_table' - ctx = context.TestContextSCH(test, sch, 'int_bom_simple_csv', None) - ctx.run(EXIT_BAD_CONFIG, extra_debug=True) - ctx.search_err('Malformed lib entry') - ctx.search_err(r'Unable to expand .?BOGUS.? in') - ctx.search_err(r'unnamed LibAlias') - ctx.clean_up()