Added test for XLSX header information.

Covering various situations, not all.
This commit is contained in:
SET 2020-08-12 12:05:40 -03:00
parent e353158c29
commit 88940119f6
7 changed files with 245 additions and 5 deletions

View File

@ -77,6 +77,8 @@ KIBOM_TEST_GROUPS = 5
LINKS_COMPONENTS = ['J1', 'J2', 'R1']
LINKS_EXCLUDE = ['C1']
LINKS_GROUPS = 2
INFO_ROWS = ['Schematic:', 'Variant:', 'Revision:', 'Date:', 'KiCad Version:']
STATS_ROWS = ['Component Groups:', 'Component Count:', 'Fitted Components:', 'Number of PCBs:', 'Total components:']
def check_kibom_test_netlist(rows, ref_column, groups, exclude, comps):
@ -119,6 +121,30 @@ def check_path(rows, comp, ref, sp, val):
return
def check_head_xlsx(r, info, stats, title='KiBot Bill of Materials'):
rn = 0
if title:
# First row is just the title
assert r[rn][0] == title
rn += 1
logging.debug('Title Ok')
if info:
info_col = 0
for i, txt in enumerate(info):
assert r[rn+i][info_col] == INFO_ROWS[i]
if txt:
assert r[rn+i][info_col+1] == txt
logging.debug('Info block Ok')
if stats:
stats_col = 0
if info:
stats_col += 2
for i, txt in enumerate(stats):
assert r[rn+i][stats_col] == STATS_ROWS[i]
assert r[rn+i][stats_col+1] == txt, 'index: {} title: {}'.format(i, STATS_ROWS[i])
logging.debug('Stats block Ok')
def test_int_bom_simple_csv():
prj = 'kibom-test'
ext = 'csv'
@ -189,7 +215,14 @@ def test_int_bom_simple_xlsx():
ctx = context.TestContextSCH('test_int_bom_simple_xlsx', prj, 'int_bom_simple_xlsx', BOM_DIR)
ctx.run()
out = prj + '-bom.' + ext
rows, header = ctx.load_xlsx(out)
rows, header, sh_head = ctx.load_xlsx(out)
check_head_xlsx(sh_head,
[prj, 'default', 'A', '2020-03-12', None],
[KIBOM_TEST_GROUPS+len(KIBOM_TEST_EXCLUDE),
len(KIBOM_TEST_COMPONENTS)+len(KIBOM_TEST_EXCLUDE),
len(KIBOM_TEST_COMPONENTS),
1,
len(KIBOM_TEST_COMPONENTS)])
assert header == KIBOM_TEST_HEAD
ref_column = header.index(REF_COLUMN_NAME)
qty_column = header.index(QTY_COLUMN_NAME)
@ -620,3 +653,115 @@ def test_int_bom_sub_sheet_alt():
check_path(rows, 'U1', ref_column, sp_column, '/Sub Sheet')
check_path(rows, 'U2', ref_column, sp_column, '/Sub Sheet 2')
ctx.clean_up()
def test_int_bom_simple_xlsx_2():
""" No title """
prj = 'kibom-test'
ext = 'xlsx'
ctx = context.TestContextSCH('test_int_bom_simple_xlsx_2', prj, 'int_bom_simple_xlsx_2', BOM_DIR)
ctx.run()
out = prj + '-bom.' + ext
rows, header, sh_head = ctx.load_xlsx(out)
check_head_xlsx(sh_head,
[prj, 'default', 'A', '2020-03-12', None],
[KIBOM_TEST_GROUPS+len(KIBOM_TEST_EXCLUDE),
len(KIBOM_TEST_COMPONENTS)+len(KIBOM_TEST_EXCLUDE),
len(KIBOM_TEST_COMPONENTS),
1,
len(KIBOM_TEST_COMPONENTS)],
title=None)
assert header == KIBOM_TEST_HEAD
ref_column = header.index(REF_COLUMN_NAME)
qty_column = header.index(QTY_COLUMN_NAME)
check_kibom_test_netlist(rows, ref_column, KIBOM_TEST_GROUPS, KIBOM_TEST_EXCLUDE, KIBOM_TEST_COMPONENTS)
check_dnc(rows, 'R7', ref_column, qty_column)
ctx.clean_up()
def test_int_bom_simple_xlsx_3():
""" No logo """
prj = 'kibom-test'
ext = 'xlsx'
ctx = context.TestContextSCH('test_int_bom_simple_xlsx_3', prj, 'int_bom_simple_xlsx_3', BOM_DIR)
ctx.run()
out = prj + '-bom.' + ext
rows, header, sh_head = ctx.load_xlsx(out)
check_head_xlsx(sh_head,
[prj, 'default', 'A', '2020-03-12', None],
[KIBOM_TEST_GROUPS+len(KIBOM_TEST_EXCLUDE),
len(KIBOM_TEST_COMPONENTS)+len(KIBOM_TEST_EXCLUDE),
len(KIBOM_TEST_COMPONENTS),
1,
len(KIBOM_TEST_COMPONENTS)])
assert header == KIBOM_TEST_HEAD
ref_column = header.index(REF_COLUMN_NAME)
qty_column = header.index(QTY_COLUMN_NAME)
check_kibom_test_netlist(rows, ref_column, KIBOM_TEST_GROUPS, KIBOM_TEST_EXCLUDE, KIBOM_TEST_COMPONENTS)
check_dnc(rows, 'R7', ref_column, qty_column)
ctx.clean_up()
def test_int_bom_simple_xlsx_4():
""" No title, no logo """
prj = 'kibom-test'
ext = 'xlsx'
ctx = context.TestContextSCH('test_int_bom_simple_xlsx_4', prj, 'int_bom_simple_xlsx_4', BOM_DIR)
ctx.run()
out = prj + '-bom.' + ext
rows, header, sh_head = ctx.load_xlsx(out)
check_head_xlsx(sh_head,
[prj, 'default', 'A', '2020-03-12', None],
[KIBOM_TEST_GROUPS+len(KIBOM_TEST_EXCLUDE),
len(KIBOM_TEST_COMPONENTS)+len(KIBOM_TEST_EXCLUDE),
len(KIBOM_TEST_COMPONENTS),
1,
len(KIBOM_TEST_COMPONENTS)],
title=None)
assert header == KIBOM_TEST_HEAD
ref_column = header.index(REF_COLUMN_NAME)
qty_column = header.index(QTY_COLUMN_NAME)
check_kibom_test_netlist(rows, ref_column, KIBOM_TEST_GROUPS, KIBOM_TEST_EXCLUDE, KIBOM_TEST_COMPONENTS)
check_dnc(rows, 'R7', ref_column, qty_column)
ctx.clean_up()
def test_int_bom_simple_xlsx_5():
""" No title, no logo, no info """
prj = 'kibom-test'
ext = 'xlsx'
ctx = context.TestContextSCH('test_int_bom_simple_xlsx_5', prj, 'int_bom_simple_xlsx_5', BOM_DIR)
ctx.run()
out = prj + '-bom.' + ext
rows, header, sh_head = ctx.load_xlsx(out)
check_head_xlsx(sh_head,
None,
[KIBOM_TEST_GROUPS+len(KIBOM_TEST_EXCLUDE),
len(KIBOM_TEST_COMPONENTS)+len(KIBOM_TEST_EXCLUDE),
len(KIBOM_TEST_COMPONENTS),
1,
len(KIBOM_TEST_COMPONENTS)],
title=None)
assert header == KIBOM_TEST_HEAD
ref_column = header.index(REF_COLUMN_NAME)
qty_column = header.index(QTY_COLUMN_NAME)
check_kibom_test_netlist(rows, ref_column, KIBOM_TEST_GROUPS, KIBOM_TEST_EXCLUDE, KIBOM_TEST_COMPONENTS)
check_dnc(rows, 'R7', ref_column, qty_column)
ctx.clean_up()
def test_int_bom_simple_xlsx_6():
""" No title, no logo, no info, no stats """
prj = 'kibom-test'
ext = 'xlsx'
ctx = context.TestContextSCH('test_int_bom_simple_xlsx_6', prj, 'int_bom_simple_xlsx_6', BOM_DIR)
ctx.run()
out = prj + '-bom.' + ext
rows, header, sh_head = ctx.load_xlsx(out)
assert len(sh_head) == 0
assert header == KIBOM_TEST_HEAD
ref_column = header.index(REF_COLUMN_NAME)
qty_column = header.index(QTY_COLUMN_NAME)
check_kibom_test_netlist(rows, ref_column, KIBOM_TEST_GROUPS, KIBOM_TEST_EXCLUDE, KIBOM_TEST_COMPONENTS)
check_dnc(rows, 'R7', ref_column, qty_column)
ctx.clean_up()

View File

@ -408,24 +408,45 @@ class TestContext(object):
root = ET.parse(worksheet).getroot()
ns = '{http://schemas.openxmlformats.org/spreadsheetml/2006/main}'
rnum = 1
sh_head = []
for r in root.iter(ns+'row'):
rcur = int(r.attrib['r'])
if rcur > rnum:
sh_head = rows
# Discard the sheet header
rows = []
rnum = rcur
rows.append([int(cell.text) for cell in r.iter(ns+'v')])
this_row = []
for cell in r.iter(ns+'c'):
if 't' in cell.attrib:
type = cell.attrib['t']
else:
type = 'n' # default: number
value = cell.find(ns+'v')
if value is not None:
if type == 'n':
# Numbers as integers
value = int(value.text)
else:
value = value.text
this_row.append(value)
rows.append(this_row)
rnum += 1
# Read the strings
strings = self.get_out_path(os.path.join('desc', 'xl', 'sharedStrings.xml'))
strs = [t.text for t in ET.parse(strings).getroot().iter(ns+'t')]
# Replace the indexes by the strings
for r in rows:
for i in range(len(r)):
r[i] = strs[r[i]]
for i, val in enumerate(r):
if isinstance(val, str):
r[i] = strs[int(val)]
for r in sh_head:
for i, val in enumerate(r):
if isinstance(val, str):
r[i] = strs[int(val)]
# Separate the headers
headers = rows.pop(0)
return rows, headers
return rows, headers, sh_head
class TestContextSCH(TestContext):

View File

@ -0,0 +1,14 @@
# Example KiPlot config file
kiplot:
version: 1
outputs:
- name: 'bom_internal'
comment: "Bill of Materials in HTML format"
type: bom
dir: BoM
options:
format: XLSX
xlsx:
title: ''

View File

@ -0,0 +1,14 @@
# Example KiPlot config file
kiplot:
version: 1
outputs:
- name: 'bom_internal'
comment: "Bill of Materials in HTML format"
type: bom
dir: BoM
options:
format: XLSX
xlsx:
logo: false

View File

@ -0,0 +1,15 @@
# Example KiPlot config file
kiplot:
version: 1
outputs:
- name: 'bom_internal'
comment: "Bill of Materials in HTML format"
type: bom
dir: BoM
options:
format: XLSX
xlsx:
title: ''
logo: false

View File

@ -0,0 +1,15 @@
# Example KiPlot config file
kiplot:
version: 1
outputs:
- name: 'bom_internal'
comment: "Bill of Materials in HTML format"
type: bom
dir: BoM
options:
format: XLSX
xlsx:
title: ''
logo: false
hide_pcb_info: true

View File

@ -0,0 +1,16 @@
# Example KiPlot config file
kiplot:
version: 1
outputs:
- name: 'bom_internal'
comment: "Bill of Materials in HTML format"
type: bom
dir: BoM
options:
format: XLSX
xlsx:
title: ''
logo: false
hide_pcb_info: true
hide_stats_info: true