Added a test for missing xlsxwriter module.

Is reported as an error, not fatal, but error.
This commit is contained in:
SET 2020-08-13 19:17:17 -03:00
parent 45a117afe5
commit d904dc516f
3 changed files with 71 additions and 38 deletions

View File

@ -0,0 +1,19 @@
#!/usr/bin/python
import os
import sys
# Setup the path to load local kiplot 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 xlsxwriter module load to fail
sys.modules['xlsxwriter'] = None
# Initialize the logger
from kiplot import log
log.set_domain('kiplot')
logger = log.init(True, False)
logger.debug("Testing bom_writer without xlsxwriter")
# Import the module to test
from kiplot.bom.bom_writer import write_bom
# Run it
write_bom('bogus', 'xlsx', [], [], {})

View File

@ -47,6 +47,7 @@ pytest-3 --log-cli-level debug
import os
import sys
import logging
import subprocess
# Look for the 'utils' module from where the script is running
prev_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
if prev_dir not in sys.path:
@ -355,9 +356,9 @@ def test_int_bom_sort_1():
check_kibom_test_netlist(rows, ref_column, 23, None, exp)
# Check the sorting
assert get_column(rows, ref_column) == exp
ctx.search_err('Malformed value: .?10Q.?')
ctx.search_err('Malformed value: .?\.G.?')
ctx.search_err('Malformed value: .?2\.2k2.?')
ctx.search_err(r'Malformed value: .?10Q.?')
ctx.search_err(r'Malformed value: .?\.G.?')
ctx.search_err(r'Malformed value: .?2\.2k2.?')
ctx.clean_up()
@ -1017,3 +1018,11 @@ def test_int_bom_digikey_links_xlsx():
assert 'digikey' in c
logging.debug(c + ' OK')
ctx.clean_up()
def test_int_bom_no_xlsx_support():
ctx = context.TestContextSCH('test_int_bom_no_xlsx_support', 'links', 'int_bom_digikey_links_xlsx', BOM_DIR)
cmd = [os.path.abspath(os.path.dirname(os.path.abspath(__file__))+'/force_xlsx_error.py')]
ctx.do_run(cmd)
ctx.search_err('Python xlsxwriter module not installed')
ctx.search_err('writing XLSX output')

View File

@ -153,43 +153,12 @@ class TestContext(object):
with open(file, 'w') as f:
f.write('Dummy file\n')
def run(self, ret_val=None, extra=None, use_a_tty=False, filename=None, no_out_dir=False, no_board_file=False,
no_yaml_file=False, chdir_out=False, no_verbose=False, extra_debug=False, do_locale=False):
logging.debug('Running '+self.test_name)
# Change the command to be local and add the board and output arguments
cmd = [COVERAGE_SCRIPT, 'run', '-a']
def do_run(self, cmd, ret_val=None, use_a_tty=False, chdir_out=False):
cmd_base = [COVERAGE_SCRIPT, 'run', '-a']
if chdir_out:
cmd.append('--rcfile=../../.coveragerc')
cmd_base.append('--rcfile=../../.coveragerc')
os.environ['COVERAGE_FILE'] = os.path.join(os.getcwd(), '.coverage')
cmd.append(os.path.abspath(os.path.dirname(os.path.abspath(__file__))+'/../../src/kiplot'))
if not no_verbose:
# One is enough, 2 can generate tons of data when loading libs
cmd.append('-v')
if extra_debug:
cmd.append('-v')
if not no_board_file:
if self.mode == MODE_PCB:
cmd = cmd+['-b', filename if filename else self.board_file]
else:
cmd = cmd+['-e', filename if filename else self.sch_file]
if not no_yaml_file:
cmd = cmd+['-c', self.yaml_file]
if not no_out_dir:
cmd = cmd+['-d', self.output_dir]
if extra is not None:
cmd = cmd+extra
# Do we need a custom locale?
old_LOCPATH = None
old_LANG = None
if do_locale:
# Setup an Spanish for Argentina using UTF-8 locale
old_LOCPATH = os.environ.get('LOCPATH')
old_LANG = os.environ.get('LANG')
os.environ['LOCPATH'] = os.path.abspath('tests/data')
os.environ['LANG'] = 'es_AR.UTF-8'
#os.environ['LANG'] = 'en_US.UTF-8'
logging.debug('LOCPATH='+os.environ['LOCPATH'])
logging.debug('LANG='+os.environ['LANG'])
cmd = cmd_base+cmd
logging.debug(cmd)
out_filename = self.get_out_path('output.txt')
err_filename = self.get_out_path('error.txt')
@ -236,6 +205,42 @@ class TestContext(object):
self.err = os.read(f_err, 1000000)
os.close(f_err)
self.err = self.err.decode()
def run(self, ret_val=None, extra=None, use_a_tty=False, filename=None, no_out_dir=False, no_board_file=False,
no_yaml_file=False, chdir_out=False, no_verbose=False, extra_debug=False, do_locale=False):
logging.debug('Running '+self.test_name)
# Change the command to be local and add the board and output arguments
cmd = [os.path.abspath(os.path.dirname(os.path.abspath(__file__))+'/../../src/kiplot')]
if not no_verbose:
# One is enough, 2 can generate tons of data when loading libs
cmd.append('-v')
if extra_debug:
cmd.append('-v')
if not no_board_file:
if self.mode == MODE_PCB:
cmd = cmd+['-b', filename if filename else self.board_file]
else:
cmd = cmd+['-e', filename if filename else self.sch_file]
if not no_yaml_file:
cmd = cmd+['-c', self.yaml_file]
if not no_out_dir:
cmd = cmd+['-d', self.output_dir]
if extra is not None:
cmd = cmd+extra
# Do we need a custom locale?
old_LOCPATH = None
old_LANG = None
if do_locale:
# Setup an Spanish for Argentina using UTF-8 locale
old_LOCPATH = os.environ.get('LOCPATH')
old_LANG = os.environ.get('LANG')
os.environ['LOCPATH'] = os.path.abspath('tests/data')
os.environ['LANG'] = 'es_AR.UTF-8'
#os.environ['LANG'] = 'en_US.UTF-8'
logging.debug('LOCPATH='+os.environ['LOCPATH'])
logging.debug('LANG='+os.environ['LANG'])
self.do_run(cmd, use_a_tty, chdir_out)
# Do we need to restore the locale?
if do_locale:
if old_LOCPATH: