Fixed log.init() errors when pcbnew/yaml modules aren't installed.
Also added tests for these cases.
This commit is contained in:
parent
6bbd15eaf2
commit
263b9c41e4
|
|
@ -27,8 +27,8 @@ logger = log.get_logger(__name__)
|
|||
|
||||
try:
|
||||
import yaml
|
||||
except ImportError: # pragma: no cover
|
||||
log.init(False, False)
|
||||
except ImportError:
|
||||
log.init()
|
||||
logger.error('No yaml module for Python, install python3-yaml')
|
||||
exit(NO_YAML_MODULE)
|
||||
|
||||
|
|
|
|||
|
|
@ -38,8 +38,8 @@ if os.environ.get('KIAUS_USE_NIGHTLY'):
|
|||
sys_path.insert(0, '/usr/lib/kicad-nightly/lib/python3/dist-packages')
|
||||
try:
|
||||
import pcbnew
|
||||
except ImportError: # pragma: no cover
|
||||
log.init(False, False)
|
||||
except ImportError:
|
||||
log.init()
|
||||
logger.error("Failed to import pcbnew Python module."
|
||||
" Is KiCad installed?"
|
||||
" Do you need to add it to PYTHONPATH?")
|
||||
|
|
|
|||
|
|
@ -0,0 +1,12 @@
|
|||
#!/usr/bin/python3
|
||||
import os
|
||||
import sys
|
||||
# Setup the path to load local kibot module
|
||||
prev_dir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
if prev_dir not in sys.path:
|
||||
sys.path.insert(0, prev_dir)
|
||||
# Force the pcbnew module load to fail
|
||||
sys.modules['pcbnew'] = None
|
||||
# Import the module to test
|
||||
from kibot.kiplot import check_eeschema_do
|
||||
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
#!/usr/bin/python
|
||||
#!/usr/bin/python3
|
||||
import os
|
||||
import sys
|
||||
# Setup the path to load local kibot module
|
||||
|
|
|
|||
|
|
@ -0,0 +1,12 @@
|
|||
#!/usr/bin/python3
|
||||
import os
|
||||
import sys
|
||||
# Setup the path to load local kibot module
|
||||
prev_dir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
if prev_dir not in sys.path:
|
||||
sys.path.insert(0, prev_dir)
|
||||
# Force the pcbnew module load to fail
|
||||
sys.modules['yaml'] = None
|
||||
# Import the module to test
|
||||
from kibot.config_reader import CfgYamlReader
|
||||
|
||||
|
|
@ -42,7 +42,7 @@ prev_dir = os.path.dirname(prev_dir)
|
|||
if prev_dir not in sys.path:
|
||||
sys.path.insert(0, prev_dir)
|
||||
from kibot.misc import (EXIT_BAD_ARGS, EXIT_BAD_CONFIG, NO_PCB_FILE, NO_SCH_FILE, EXAMPLE_CFG, WONT_OVERWRITE, CORRUPTED_PCB,
|
||||
PCBDRAW_ERR)
|
||||
PCBDRAW_ERR, NO_PCBNEW_MODULE, NO_YAML_MODULE)
|
||||
|
||||
|
||||
POS_DIR = 'positiondir'
|
||||
|
|
@ -519,3 +519,18 @@ def test_wrong_global_redef():
|
|||
ctx.run(EXIT_BAD_ARGS, extra=['--global-redef', 'bogus'])
|
||||
assert ctx.search_err('Malformed global-redef option')
|
||||
ctx.clean_up()
|
||||
|
||||
|
||||
def test_no_pcbnew():
|
||||
ctx = context.TestContext('test_no_pcbnew', 'bom', 'bom', '')
|
||||
cmd = [os.path.abspath(os.path.dirname(os.path.abspath(__file__))+'/force_pcbnew_error.py')]
|
||||
ctx.do_run(cmd, NO_PCBNEW_MODULE)
|
||||
ctx.search_err('Failed to import pcbnew Python module.')
|
||||
ctx.search_err('PYTHONPATH')
|
||||
|
||||
|
||||
def test_no_yaml():
|
||||
ctx = context.TestContext('test_no_yaml', 'bom', 'bom', '')
|
||||
cmd = [os.path.abspath(os.path.dirname(os.path.abspath(__file__))+'/force_yaml_error.py')]
|
||||
ctx.do_run(cmd, NO_YAML_MODULE)
|
||||
ctx.search_err('No yaml module for Python, install python3-yaml')
|
||||
|
|
|
|||
Loading…
Reference in New Issue