From 24ba23d2032911dea65d3013d7253908ec89c317 Mon Sep 17 00:00:00 2001 From: "Salvador E. Tropea" Date: Mon, 10 Jan 2022 20:48:11 -0300 Subject: [PATCH] Separated YAML tests that makes reference to SCH files - Avoiding KiCad 5 and 6 mixes --- kibot/kiplot.py | 31 ++++++++++--------- kibot/out_bom.py | 4 +-- tests/test_plot/test_int_bom.py | 20 +++++++++--- tests/test_plot/test_kicost.py | 5 ++- tests/test_plot/test_yaml_errors.py | 5 ++- .../error_aggregate_miss_file_k6.kibot.yaml | 22 +++++++++++++ .../int_bom_kicost_merge_xlsx_k6.kibot.yaml | 31 +++++++++++++++++++ .../int_bom_merge_csv_1_k6.kibot.yaml | 23 ++++++++++++++ .../int_bom_merge_html_1_k6.kibot.yaml | 23 ++++++++++++++ .../int_bom_merge_xlsx_1_k6.kibot.yaml | 23 ++++++++++++++ .../int_bom_merge_xml_1_k6.kibot.yaml | 23 ++++++++++++++ 11 files changed, 186 insertions(+), 24 deletions(-) create mode 100644 tests/yaml_samples/error_aggregate_miss_file_k6.kibot.yaml create mode 100644 tests/yaml_samples/int_bom_kicost_merge_xlsx_k6.kibot.yaml create mode 100644 tests/yaml_samples/int_bom_merge_csv_1_k6.kibot.yaml create mode 100644 tests/yaml_samples/int_bom_merge_html_1_k6.kibot.yaml create mode 100644 tests/yaml_samples/int_bom_merge_xlsx_1_k6.kibot.yaml create mode 100644 tests/yaml_samples/int_bom_merge_xml_1_k6.kibot.yaml diff --git a/kibot/kiplot.py b/kibot/kiplot.py index 062d84ab..e284bc47 100644 --- a/kibot/kiplot.py +++ b/kibot/kiplot.py @@ -224,10 +224,17 @@ def load_board(pcb_file=None): return board -def load_any_sch(sch, file, project): +def load_any_sch(file, project): + if file[-9:] == 'kicad_sch': + sch = SchematicV6() + load_libs = False + else: + sch = Schematic() + load_libs = True try: sch.load(file, project) - sch.load_libs(file) + if load_libs: + sch.load_libs(file) if GS.debug_level > 1: logger.debug('Schematic dependencies: '+str(sch.get_files())) except SchFileError as e: @@ -235,30 +242,24 @@ def load_any_sch(sch, file, project): logger.error('At line {} of `{}`: {}'.format(e.line, e.file, e.msg)) logger.error('Line content: `{}`'.format(e.code)) exit(CORRUPTED_SCH) + except SchError as e: + trace_dump() + logger.error('While loading `{}`'.format(file)) + logger.error(str(e)) + exit(CORRUPTED_SCH) except KiConfError as e: trace_dump() logger.error('At line {} of `{}`: {}'.format(e.line, e.file, e.msg)) logger.error('Line content: `{}`'.format(e.code)) exit(EXIT_BAD_CONFIG) + return sch def load_sch(): if GS.sch: # Already loaded return GS.check_sch() - # We can't yet load the new format - if GS.sch_file[-9:] == 'kicad_sch': - GS.sch = SchematicV6() - try: - GS.sch.load(GS.sch_file, GS.sch_basename) - except SchError as e: - trace_dump() - logger.error('While loading `{}`'.format(GS.sch_file)) - logger.error(str(e)) - exit(CORRUPTED_SCH) - return # pragma: no cover (Ki6) - GS.sch = Schematic() - load_any_sch(GS.sch, GS.sch_file, GS.sch_basename) + GS.sch = load_any_sch(GS.sch_file, GS.sch_basename) def get_board_comps_data(comps): diff --git a/kibot/out_bom.py b/kibot/out_bom.py index def7c60d..4eec04fe 100644 --- a/kibot/out_bom.py +++ b/kibot/out_bom.py @@ -18,7 +18,6 @@ from .kiplot import get_board_comps_data, load_any_sch from .bom.columnlist import ColumnList, BoMError from .bom.bom import do_bom from .var_kibom import KiBoM -from .kicad.v5_sch import Schematic from .fil_base import BaseFilter, apply_exclude_filter, apply_fitted_filter, apply_fixed_filter, reset_filters from .macros import macros, document, output_class # noqa: F401 from . import log @@ -563,8 +562,7 @@ class BoMOptions(BaseOptions): logger.debug('Adding components from project {} ({}) using reference id `{}`'. format(prj.name, prj.file, prj.ref_id)) self.qtys[prj.name] = prj.number - prj.sch = Schematic() - load_any_sch(prj.sch, prj.file, prj.name) + prj.sch = load_any_sch(prj.file, prj.name) new_comps = prj.sch.get_components() for c in new_comps: c.ref = prj.ref_id+c.ref diff --git a/tests/test_plot/test_int_bom.py b/tests/test_plot/test_int_bom.py index 1b47458f..91988474 100644 --- a/tests/test_plot/test_int_bom.py +++ b/tests/test_plot/test_int_bom.py @@ -1534,7 +1534,10 @@ def test_int_bom_variant_5(test_dir): def test_int_bom_merge_csv_1(test_dir): prj = 'merge_1' - ctx = context.TestContextSCH(test_dir, 'test_int_bom_merge_csv_1', prj, 'int_bom_merge_csv_1', BOM_DIR) + yaml = 'int_bom_merge_csv_1' + if context.ki6(): + yaml += '_k6' + ctx = context.TestContextSCH(test_dir, 'test_int_bom_merge_csv_1', prj, yaml, BOM_DIR) ctx.run(extra_debug=True) rows, header, info = ctx.load_csv(prj+'-bom.csv') ref_column = header.index(REF_COLUMN_NAME) @@ -1547,7 +1550,10 @@ def test_int_bom_merge_csv_1(test_dir): def test_int_bom_merge_html_1(test_dir): prj = 'merge_1' - ctx = context.TestContextSCH(test_dir, 'test_int_bom_merge_html_1', prj, 'int_bom_merge_html_1', BOM_DIR) + yaml = 'int_bom_merge_html_1' + if context.ki6(): + yaml += '_k6' + ctx = context.TestContextSCH(test_dir, 'test_int_bom_merge_html_1', prj, yaml, BOM_DIR) ctx.run() rows, header, info = ctx.load_html(prj+'-bom.html') logging.debug(rows[0]) @@ -1560,7 +1566,10 @@ def test_int_bom_merge_html_1(test_dir): def test_int_bom_merge_xlsx_1(test_dir): prj = 'merge_1' - ctx = context.TestContextSCH(test_dir, 'test_int_bom_merge_xlsx_1', prj, 'int_bom_merge_xlsx_1', BOM_DIR) + yaml = 'int_bom_merge_xlsx_1' + if context.ki6(): + yaml += '_k6' + ctx = context.TestContextSCH(test_dir, 'test_int_bom_merge_xlsx_1', prj, yaml, BOM_DIR) ctx.run() rows, header, info = ctx.load_xlsx(prj+'-bom.xlsx') ref_column = header.index(REF_COLUMN_NAME) @@ -1572,7 +1581,10 @@ def test_int_bom_merge_xlsx_1(test_dir): def test_int_bom_merge_xml_1(test_dir): prj = 'merge_1' - ctx = context.TestContextSCH(test_dir, 'test_int_bom_merge_xml_1', prj, 'int_bom_merge_xml_1', BOM_DIR) + yaml = 'int_bom_merge_xml_1' + if context.ki6(): + yaml += '_k6' + ctx = context.TestContextSCH(test_dir, 'test_int_bom_merge_xml_1', prj, yaml, BOM_DIR) ctx.run() rows, header = ctx.load_xml(prj+'-bom.xml') ref_column = header.index(REF_COLUMN_NAME) diff --git a/tests/test_plot/test_kicost.py b/tests/test_plot/test_kicost.py index de34ebca..5f7476fb 100644 --- a/tests/test_plot/test_kicost.py +++ b/tests/test_plot/test_kicost.py @@ -97,7 +97,10 @@ def test_kicost_bom_sel_dist_1(test_dir): def test_kicost_bom_merge_1(test_dir): ''' Internal BoM + KiCost, merging 3 projects. ''' prj = 'merge_1' - ctx = context.TestContextSCH(test_dir, 'test_kicost_bom_merge_1', prj, 'int_bom_kicost_merge_xlsx', OUT_DIR) + yaml = 'int_bom_kicost_merge_xlsx' + if context.ki6(): + yaml += '_k6' + ctx = context.TestContextSCH(test_dir, 'test_kicost_bom_merge_1', prj, yaml, OUT_DIR) ctx.run(kicost=True) # , extra_debug=True output = op.join(OUT_DIR, prj+'-bom.xlsx') ctx.expect_out_file(output) diff --git a/tests/test_plot/test_yaml_errors.py b/tests/test_plot/test_yaml_errors.py index dd260d73..b3a71525 100644 --- a/tests/test_plot/test_yaml_errors.py +++ b/tests/test_plot/test_yaml_errors.py @@ -665,7 +665,10 @@ def test_error_aggregate_no_file(test_dir): def test_error_aggregate_miss_file(test_dir): - ctx = context.TestContext(test_dir, 'test_error_aggregate_miss_file', 'bom', 'error_aggregate_miss_file', '') + yaml = 'error_aggregate_miss_file' + if context.ki6(): + yaml += '_k6' + ctx = context.TestContext(test_dir, 'test_error_aggregate_miss_file', 'bom', yaml, '') ctx.run(EXIT_BAD_CONFIG) assert ctx.search_err("Missing `dummy`") ctx.clean_up() diff --git a/tests/yaml_samples/error_aggregate_miss_file_k6.kibot.yaml b/tests/yaml_samples/error_aggregate_miss_file_k6.kibot.yaml new file mode 100644 index 00000000..83422946 --- /dev/null +++ b/tests/yaml_samples/error_aggregate_miss_file_k6.kibot.yaml @@ -0,0 +1,22 @@ +# Example KiBot config file +kibot: + version: 1 + +outputs: + - name: 'bom_csv' + comment: "Bill of Materials in CSV format" + type: bom + dir: BoM + options: + format: CSV + ref_id: 'A:' + source_by_id: true + use_alt: true + aggregate: + - file: tests/board_samples/kicad_6/merge_3.kicad_sch + number: 4 + - file: dummy + name: 2nd project + ref_id: 'B:' + number: 2 + diff --git a/tests/yaml_samples/int_bom_kicost_merge_xlsx_k6.kibot.yaml b/tests/yaml_samples/int_bom_kicost_merge_xlsx_k6.kibot.yaml new file mode 100644 index 00000000..c5cebf72 --- /dev/null +++ b/tests/yaml_samples/int_bom_kicost_merge_xlsx_k6.kibot.yaml @@ -0,0 +1,31 @@ +# Example KiBot config file +kibot: + version: 1 + +outputs: + - name: 'bom_internal' + comment: "Bill of Materials in XLSX format" + type: bom + dir: KiCost + options: + use_alt: true + ref_id: 'prj0:' + number: 50 + source_by_id: true + aggregate: + - file: tests/board_samples/kicad_6/merge_2.kicad_sch + name: 2nd project + ref_id: 'prj1:' + number: 20 + - file: tests/board_samples/kicad_6/merge_3.kicad_sch + ref_id: 'prj2:' + number: 30 + columns: + - References + - Part + - Value + - Quantity Per PCB + - field: manf# + name: Manufacturer P/N + xlsx: + kicost: true diff --git a/tests/yaml_samples/int_bom_merge_csv_1_k6.kibot.yaml b/tests/yaml_samples/int_bom_merge_csv_1_k6.kibot.yaml new file mode 100644 index 00000000..87a05e43 --- /dev/null +++ b/tests/yaml_samples/int_bom_merge_csv_1_k6.kibot.yaml @@ -0,0 +1,23 @@ +# Example KiBot config file +kibot: + version: 1 + +outputs: + - name: 'bom_csv' + comment: "Bill of Materials in CSV format" + type: bom + dir: BoM + options: + format: CSV + ref_id: 'A:' + source_by_id: true + use_alt: true + aggregate: + - file: tests/board_samples/kicad_6/merge_2.kicad_sch + name: 2nd project + ref_id: 'B:' + number: 2 + - file: tests/board_samples/kicad_6/merge_3.kicad_sch + ref_id: 'C:' + number: 4 + diff --git a/tests/yaml_samples/int_bom_merge_html_1_k6.kibot.yaml b/tests/yaml_samples/int_bom_merge_html_1_k6.kibot.yaml new file mode 100644 index 00000000..9849dfa1 --- /dev/null +++ b/tests/yaml_samples/int_bom_merge_html_1_k6.kibot.yaml @@ -0,0 +1,23 @@ +# Example KiBot config file +kibot: + version: 1 + +outputs: + - name: 'bom_csv' + comment: "Bill of Materials in CSV format" + type: bom + dir: BoM + options: + format: HTML + ref_id: 'A:' + source_by_id: true + use_alt: true + aggregate: + - file: tests/board_samples/kicad_6/merge_2.kicad_sch + name: 2nd project + ref_id: 'B:' + number: 2 + - file: tests/board_samples/kicad_6/merge_3.kicad_sch + ref_id: 'C:' + number: 4 + diff --git a/tests/yaml_samples/int_bom_merge_xlsx_1_k6.kibot.yaml b/tests/yaml_samples/int_bom_merge_xlsx_1_k6.kibot.yaml new file mode 100644 index 00000000..7e8433b5 --- /dev/null +++ b/tests/yaml_samples/int_bom_merge_xlsx_1_k6.kibot.yaml @@ -0,0 +1,23 @@ +# Example KiBot config file +kibot: + version: 1 + +outputs: + - name: 'bom_csv' + comment: "Bill of Materials in CSV format" + type: bom + dir: BoM + options: + format: XLSX + ref_id: 'A:' + source_by_id: true + use_alt: true + aggregate: + - file: tests/board_samples/kicad_6/merge_2.kicad_sch + name: 2nd project + ref_id: 'B:' + number: 2 + - file: tests/board_samples/kicad_6/merge_3.kicad_sch + ref_id: 'C:' + number: 4 + diff --git a/tests/yaml_samples/int_bom_merge_xml_1_k6.kibot.yaml b/tests/yaml_samples/int_bom_merge_xml_1_k6.kibot.yaml new file mode 100644 index 00000000..cda2f1eb --- /dev/null +++ b/tests/yaml_samples/int_bom_merge_xml_1_k6.kibot.yaml @@ -0,0 +1,23 @@ +# Example KiBot config file +kibot: + version: 1 + +outputs: + - name: 'bom_csv' + comment: "Bill of Materials in CSV format" + type: bom + dir: BoM + options: + format: XML + ref_id: 'A:' + source_by_id: true + use_alt: true + aggregate: + - file: tests/board_samples/kicad_6/merge_2.kicad_sch + name: 2nd project + ref_id: 'B:' + number: 2 + - file: tests/board_samples/kicad_6/merge_3.kicad_sch + ref_id: 'C:' + number: 4 +