From 400d5e436d3696b7a19e2a83cc7fe8051c11b644 Mon Sep 17 00:00:00 2001 From: SET Date: Sat, 15 Aug 2020 15:24:18 -0300 Subject: [PATCH] Fixed the KiCad config error tests. They modified the environment and didn't undo the changes. --- tests/data/{kicad_1 => kicad}/kicad_common | 0 tests/test_plot/test_kicad_config_errors.py | 37 +++++++++++++++------ tests/utils/context.py | 2 +- 3 files changed, 28 insertions(+), 11 deletions(-) rename tests/data/{kicad_1 => kicad}/kicad_common (100%) diff --git a/tests/data/kicad_1/kicad_common b/tests/data/kicad/kicad_common similarity index 100% rename from tests/data/kicad_1/kicad_common rename to tests/data/kicad/kicad_common diff --git a/tests/test_plot/test_kicad_config_errors.py b/tests/test_plot/test_kicad_config_errors.py index e7f3e622..9a69dc9e 100644 --- a/tests/test_plot/test_kicad_config_errors.py +++ b/tests/test_plot/test_kicad_config_errors.py @@ -12,11 +12,15 @@ 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)) +prev_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) +if prev_dir not in sys.path: + sys.path.insert(0, prev_dir) # Utils import from utils import context -sys.path.insert(0, os.path.dirname(prev_dir)) +# One more level for the project +prev_dir = os.path.dirname(prev_dir) +if prev_dir not in sys.path: + sys.path.insert(0, prev_dir) from kiplot.misc import EXIT_BAD_CONFIG from kiplot.kicad.config import KiConf @@ -41,20 +45,33 @@ def test_kicad_conf_no_instance(): cov.load() cov.start() with pytest.raises(AssertionError) as pytest_wrapped_e: - o = KiConf() + o = KiConf() # noqa: F841 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' +def check_load_conf(caplog): + caplog.set_level(logging.DEBUG) cov.load() cov.start() - KiConf.init(ctx.sch_file) + KiConf.init(os.path.join(context.BOARDS_DIR, 'v5_errors/kibom-test.sch')) cov.stop() cov.save() - assert 'Reading KiCad config from `tests/data/kicad_1/kicad_common`' in caplog.text + assert len(caplog.text) + assert 'Reading KiCad config from `tests/data/kicad/kicad_common`' in caplog.text + + +def test_kicad_conf_user(caplog): + """ Check we can load the KiCad configuration from $KICAD_CONFIG_HOME """ + os.environ['KICAD_CONFIG_HOME'] = 'tests/data/kicad' + check_load_conf(caplog) + del os.environ['KICAD_CONFIG_HOME'] + + +def test_kicad_conf_xdg(caplog): + """ Check we can load the KiCad configuration from $KICAD_CONFIG_HOME """ + os.environ['XDG_CONFIG_HOME'] = 'tests/data' + check_load_conf(caplog) + del os.environ['XDG_CONFIG_HOME'] diff --git a/tests/utils/context.py b/tests/utils/context.py index d39081eb..6725bca4 100644 --- a/tests/utils/context.py +++ b/tests/utils/context.py @@ -14,7 +14,7 @@ COVERAGE_SCRIPT = 'python3-coverage' KICAD_PCB_EXT = '.kicad_pcb' KICAD_SCH_EXT = '.sch' REF_DIR = 'tests/reference' - +BOARDS_DIR = 'tests/board_samples' MODE_SCH = 1 MODE_PCB = 0