Fixed the KiCad config error tests.

They modified the environment and didn't undo the changes.
This commit is contained in:
SET 2020-08-15 15:24:18 -03:00
parent d277bbbc0b
commit 400d5e436d
3 changed files with 28 additions and 11 deletions

View File

@ -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']

View File

@ -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