From 0f0aa71baabfd1a05817a4b7689bcddd6e2cae2c Mon Sep 17 00:00:00 2001 From: "Salvador E. Tropea" Date: Sun, 30 Aug 2020 11:55:35 -0300 Subject: [PATCH] Added more tests for the filters and variants --- tests/board_samples/kibom-test-4.sch | 116 ++++++++++++++++++ tests/test_plot/test_int_bom.py | 61 ++++++++- tests/test_plot/test_yaml_errors.py | 49 ++++++++ .../yaml_samples/error_fil_no_list.kibot.yaml | 6 + .../yaml_samples/error_fil_unknown.kibot.yaml | 14 +++ .../error_var_empty_name.kibot.yaml | 6 + .../yaml_samples/error_var_no_list.kibot.yaml | 6 + .../yaml_samples/error_var_no_name.kibot.yaml | 5 + .../yaml_samples/error_var_no_type.kibot.yaml | 6 + .../error_var_wrong_type.kibot.yaml | 6 + tests/yaml_samples/int_bom_fil_1.kibot.yaml | 86 +++++++++++++ .../yaml_samples/int_bom_fil_dummy.kibot.yaml | 13 ++ .../int_bom_var_t2i_csv.kibot.yaml | 1 + .../int_bom_var_t2is_csv.kibot.yaml | 27 ++++ .../int_bom_var_t2s_csv.kibot.yaml | 31 +++++ .../int_bom_wrong_variant.kibot.yaml | 11 ++ 16 files changed, 442 insertions(+), 2 deletions(-) create mode 100644 tests/board_samples/kibom-test-4.sch create mode 100644 tests/yaml_samples/error_fil_no_list.kibot.yaml create mode 100644 tests/yaml_samples/error_fil_unknown.kibot.yaml create mode 100644 tests/yaml_samples/error_var_empty_name.kibot.yaml create mode 100644 tests/yaml_samples/error_var_no_list.kibot.yaml create mode 100644 tests/yaml_samples/error_var_no_name.kibot.yaml create mode 100644 tests/yaml_samples/error_var_no_type.kibot.yaml create mode 100644 tests/yaml_samples/error_var_wrong_type.kibot.yaml create mode 100644 tests/yaml_samples/int_bom_fil_1.kibot.yaml create mode 100644 tests/yaml_samples/int_bom_fil_dummy.kibot.yaml create mode 100644 tests/yaml_samples/int_bom_var_t2is_csv.kibot.yaml create mode 100644 tests/yaml_samples/int_bom_var_t2s_csv.kibot.yaml create mode 100644 tests/yaml_samples/int_bom_wrong_variant.kibot.yaml diff --git a/tests/board_samples/kibom-test-4.sch b/tests/board_samples/kibom-test-4.sch new file mode 100644 index 00000000..e583b402 --- /dev/null +++ b/tests/board_samples/kibom-test-4.sch @@ -0,0 +1,116 @@ +EESchema Schematic File Version 4 +EELAYER 30 0 +EELAYER END +$Descr A4 11693 8268 +encoding utf-8 +Sheet 1 1 +Title "KiBot Filters Test Schematic" +Date "2020-08-30" +Rev "r1" +Comp "https://github.com/INTI-CMNB/KiBot" +Comment1 "" +Comment2 "" +Comment3 "" +Comment4 "" +$EndDescr +$Comp +L Device:R R1 +U 1 1 5E6A2873 +P 2200 2550 +F 0 "R1" V 2280 2550 50 0000 C CNN +F 1 " " V 2200 2550 50 0000 C CNN +F 2 "Resistor_SMD:R_0805_2012Metric" V 2130 2550 50 0001 C CNN +F 3 "~" H 2200 2550 50 0001 C CNN + 1 2200 2550 + 1 0 0 -1 +$EndComp +$Comp +L Device:R R2 +U 1 1 5E6A330D +P 2500 2550 +F 0 "R2" V 2580 2550 50 0000 C CNN +F 1 "~" V 2500 2550 50 0000 C CNN +F 2 "Resistor_SMD:R_0805_2012Metric" V 2430 2550 50 0001 C CNN +F 3 "~" H 2500 2550 50 0001 C CNN + 1 2500 2550 + 1 0 0 -1 +$EndComp +Text Notes 2750 2600 0 50 ~ 0 +Empty value +$Comp +L Device:R R3 +U 1 1 5E6A3CA0 +P 2200 3100 +F 0 "R3" V 2280 3100 50 0000 C CNN +F 1 "4K7" V 2200 3100 50 0000 C CNN +F 2 "Resistor_SMD:R_0805_2012Metric" V 2130 3100 50 0001 C CNN +F 3 "~" H 2200 3100 50 0001 C CNN +F 4 "" V 2200 3100 50 0001 C CNN "K K" + 1 2200 3100 + 1 0 0 -1 +$EndComp +$Comp +L Device:R R4 +U 1 1 5E6A3F38 +P 2500 3100 +F 0 "R4" V 2580 3100 50 0000 C CNN +F 1 "4700" V 2500 3100 50 0000 C CNN +F 2 "Resistor_SMD:R_0805_2012Metric" V 2430 3100 50 0001 C CNN +F 3 "http://www.google.com/" H 2500 3100 50 0001 C CNN +F 4 "" V 2500 3100 50 0001 C CNN "Q,Q" + 1 2500 3100 + 1 0 0 -1 +$EndComp +Text Notes 2750 3150 0 50 ~ 0 +With "K K" and "Q,Q" field +$Comp +L Device:R R5 +U 1 1 5E6A448B +P 2200 3650 +F 0 "R5" V 2280 3650 50 0000 C CNN +F 1 "1k" V 2200 3650 50 0000 C CNN +F 2 "Resistor_SMD:R_0603_1608Metric" V 2130 3650 50 0001 C CNN +F 3 "~" H 2200 3650 50 0001 C CNN +F 4 "K K" V 2200 3650 50 0001 C CNN "BB" + 1 2200 3650 + 1 0 0 -1 +$EndComp +$Comp +L Device:R R6 +U 1 1 5E6A491A +P 2500 3650 +F 0 "R6" V 2580 3650 50 0000 C CNN +F 1 "1000" V 2500 3650 50 0000 C CNN +F 2 "Resistor_SMD:R_0603_1608Metric" V 2430 3650 50 0001 C CNN +F 3 "~" H 2500 3650 50 0001 C CNN +F 4 "Q,Q" V 2500 3650 50 0001 C CNN "BB" + 1 2500 3650 + 1 0 0 -1 +$EndComp +Text Notes 2750 3700 0 50 ~ 0 +BB field containing "K K" and "Q,Q" +Text Notes 600 1250 0 157 ~ 0 +This schematic serves as a test-file for the KiBot export script.\n\nHere we play with filters. +$Comp +L Device:C C1 +U 1 1 5E6A62CC +P 6650 2550 +F 0 "C1" H 6675 2650 50 0000 L CNN +F 1 "10nF" H 6675 2450 50 0000 L CNN +F 2 "Capacitor_SMD:C_0603_1608Metric" H 6688 2400 50 0001 C CNN +F 3 "This is a long text, wrap check" H 6650 2550 50 0001 C CNN + 1 6650 2550 + 1 0 0 -1 +$EndComp +$Comp +L Device:C C2 +U 1 1 5E6A6854 +P 7050 2550 +F 0 "C2" H 7075 2650 50 0000 L CNN +F 1 "10n" H 7075 2450 50 0000 L CNN +F 2 "Capacitor_SMD:C_0603_1608Metric" H 7088 2400 50 0001 C CNN +F 3 "~" H 7050 2550 50 0001 C CNN + 1 7050 2550 + 1 0 0 -1 +$EndComp +$EndSCHEMATC diff --git a/tests/test_plot/test_int_bom.py b/tests/test_plot/test_int_bom.py index 8ff12597..316da62b 100644 --- a/tests/test_plot/test_int_bom.py +++ b/tests/test_plot/test_int_bom.py @@ -31,9 +31,7 @@ Tests of Internal BoM files - No XLSX support Missing: -- Variants - number_boards - - XLSX/HTML colors (for real) For debug information use: @@ -1212,6 +1210,18 @@ def test_int_bom_variant_t2(): ctx.clean_up() +def test_int_bom_variant_t2s(): + prj = 'kibom-variant_2' + ctx = context.TestContextSCH('test_int_bom_variant_t2s', prj, 'int_bom_var_t2s_csv', BOM_DIR) + ctx.run(extra_debug=True) + rows, header, info = ctx.load_csv(prj+'-bom_(dummy).csv') + ref_column = header.index(REF_COLUMN_NAME) + check_kibom_test_netlist(rows, ref_column, 1, ['C1', 'C2'], ['R1', 'R2']) + rows, header, info = ctx.load_csv(prj+'-bom_(dummy2).csv') + check_kibom_test_netlist(rows, ref_column, 1, ['C1', 'C2'], ['R1', 'R2']) + ctx.clean_up() + + def test_int_bom_variant_t2i(): prj = 'kibom-variant_3' ctx = context.TestContextSCH('test_int_bom_variant_t2i', prj, 'int_bom_var_t2i_csv', BOM_DIR) @@ -1226,3 +1236,50 @@ def test_int_bom_variant_t2i(): rows, header, info = ctx.load_csv(prj+'-bom_(test).csv') check_kibom_test_netlist(rows, ref_column, 2, ['R2'], ['R1', 'C1', 'C2']) ctx.clean_up() + + +def test_int_bom_variant_t2is(): + prj = 'kibom-variant_3' + ctx = context.TestContextSCH('test_int_bom_variant_t2is', prj, 'int_bom_var_t2is_csv', BOM_DIR) + ctx.run(extra_debug=True) + rows, header, info = ctx.load_csv('filter_R1.csv') + ref_column = header.index(REF_COLUMN_NAME) + check_kibom_test_netlist(rows, ref_column, 1, ['R2', 'R1'], ['C1', 'C2']) + ctx.clean_up() + + +def test_int_bom_wrong_variant(): + ctx = context.TestContextSCH('test_int_bom_wrong_variant', 'links', 'int_bom_wrong_variant', '') + ctx.run(EXIT_BAD_CONFIG) + assert ctx.search_err("Unknown variant name") + ctx.clean_up() + + +def test_int_bom_fil_dummy(): + prj = 'kibom-test-4' + ctx = context.TestContextSCH('test_int_bom_fil_dummy', prj, 'int_bom_fil_dummy', BOM_DIR) + ctx.run() + rows, header, info = ctx.load_csv(prj+'-bom.csv') + ref_column = header.index(REF_COLUMN_NAME) + check_kibom_test_netlist(rows, ref_column, 4, None, ['R1-R2', 'R3-R4', 'R5-R6', 'C1-C2']) + ctx.clean_up() + + +def test_int_bom_fil_1(): + prj = 'kibom-test-4' + ctx = context.TestContextSCH('test_int_bom_fil_1', prj, 'int_bom_fil_1', BOM_DIR) + ctx.run() + rows, header, info = ctx.load_csv('empty_val.csv') + ref_column = header.index(REF_COLUMN_NAME) + check_kibom_test_netlist(rows, ref_column, 3, None, ['R3-R4', 'R5-R6', 'C1-C2']) + rows, header, info = ctx.load_csv('by_prefix.csv') + check_kibom_test_netlist(rows, ref_column, 3, None, ['R2', 'R3-R4', 'R5-R6']) + rows, header, info = ctx.load_csv('no_kk.csv') + check_kibom_test_netlist(rows, ref_column, 3, None, ['R1-R2', 'R5-R6', 'C1-C2']) + rows, header, info = ctx.load_csv('no_conf_kk.csv') + check_kibom_test_netlist(rows, ref_column, 3, None, ['R1-R2', 'R3-R4', 'C1-C2']) + rows, header, info = ctx.load_csv('no_by_prefix.csv') + check_kibom_test_netlist(rows, ref_column, 2, None, ['R1', 'C1-C2']) + rows, header, info = ctx.load_csv('multi.csv') + check_kibom_test_netlist(rows, ref_column, 1, None, ['C1-C2']) + ctx.clean_up() diff --git a/tests/test_plot/test_yaml_errors.py b/tests/test_plot/test_yaml_errors.py index e532ee02..864c3621 100644 --- a/tests/test_plot/test_yaml_errors.py +++ b/tests/test_plot/test_yaml_errors.py @@ -529,3 +529,52 @@ def test_error_int_bom_logo_format(): ctx.run(EXIT_BAD_CONFIG) assert ctx.search_err("Only PNG images are supported for the logo") ctx.clean_up() + + +def test_error_var_no_name(): + ctx = context.TestContextSCH('test_error_var_no_name', 'links', 'error_var_no_name', '') + ctx.run(EXIT_BAD_CONFIG) + assert ctx.search_err("Variant needs a name in:") + ctx.clean_up() + + +def test_error_var_empty_name(): + ctx = context.TestContextSCH('test_error_var_empty_name', 'links', 'error_var_empty_name', '') + ctx.run(EXIT_BAD_CONFIG) + assert ctx.search_err("Variant needs a name in:") + ctx.clean_up() + + +def test_error_var_wrong_type(): + ctx = context.TestContextSCH('test_error_var_wrong_type', 'links', 'error_var_wrong_type', '') + ctx.run(EXIT_BAD_CONFIG) + assert ctx.search_err("Unknown variant type") + ctx.clean_up() + + +def test_error_var_no_type(): + ctx = context.TestContextSCH('test_error_var_no_type', 'links', 'error_var_no_type', '') + ctx.run(EXIT_BAD_CONFIG) + assert ctx.search_err("Variant (.*) needs a type") + ctx.clean_up() + + +def test_error_var_no_list(): + ctx = context.TestContextSCH('test_error_var_no_list', 'links', 'error_var_no_list', '') + ctx.run(EXIT_BAD_CONFIG) + assert ctx.search_err(".?variants.? must be a list") + ctx.clean_up() + + +def test_error_fil_no_list(): + ctx = context.TestContextSCH('test_error_fil_no_list', 'links', 'error_fil_no_list', '') + ctx.run(EXIT_BAD_CONFIG) + assert ctx.search_err(".?filters.? must be a list") + ctx.clean_up() + + +def test_error_fil_unknown(): + ctx = context.TestContextSCH('test_error_fil_unknown', 'links', 'error_fil_unknown', '') + ctx.run(EXIT_BAD_CONFIG) + assert ctx.search_err("Unknown filter (.*) used for ") + ctx.clean_up() diff --git a/tests/yaml_samples/error_fil_no_list.kibot.yaml b/tests/yaml_samples/error_fil_no_list.kibot.yaml new file mode 100644 index 00000000..70a0eb5a --- /dev/null +++ b/tests/yaml_samples/error_fil_no_list.kibot.yaml @@ -0,0 +1,6 @@ +kibot: + version: 1 + +filters: + name: ok + type: 'generic' diff --git a/tests/yaml_samples/error_fil_unknown.kibot.yaml b/tests/yaml_samples/error_fil_unknown.kibot.yaml new file mode 100644 index 00000000..c362ed6b --- /dev/null +++ b/tests/yaml_samples/error_fil_unknown.kibot.yaml @@ -0,0 +1,14 @@ +# Example KiBot config file +kibot: + version: 1 + +outputs: + - name: 'empty_val' + comment: "BoM no empty val" + type: bom + dir: BoM + options: + output: 'empty_val.csv' + use_alt: true + exclude_filter: 'empty val' + diff --git a/tests/yaml_samples/error_var_empty_name.kibot.yaml b/tests/yaml_samples/error_var_empty_name.kibot.yaml new file mode 100644 index 00000000..e5583cdd --- /dev/null +++ b/tests/yaml_samples/error_var_empty_name.kibot.yaml @@ -0,0 +1,6 @@ +kibot: + version: 1 + +variants: + - name: '' + - type: 'generic' diff --git a/tests/yaml_samples/error_var_no_list.kibot.yaml b/tests/yaml_samples/error_var_no_list.kibot.yaml new file mode 100644 index 00000000..af47e04a --- /dev/null +++ b/tests/yaml_samples/error_var_no_list.kibot.yaml @@ -0,0 +1,6 @@ +kibot: + version: 1 + +variants: + name: ok + type: 'generic' diff --git a/tests/yaml_samples/error_var_no_name.kibot.yaml b/tests/yaml_samples/error_var_no_name.kibot.yaml new file mode 100644 index 00000000..f91c7cd5 --- /dev/null +++ b/tests/yaml_samples/error_var_no_name.kibot.yaml @@ -0,0 +1,5 @@ +kibot: + version: 1 + +variants: + - type: 'generic' diff --git a/tests/yaml_samples/error_var_no_type.kibot.yaml b/tests/yaml_samples/error_var_no_type.kibot.yaml new file mode 100644 index 00000000..0b9b1f43 --- /dev/null +++ b/tests/yaml_samples/error_var_no_type.kibot.yaml @@ -0,0 +1,6 @@ +kibot: + version: 1 + +variants: + - name: ok + diff --git a/tests/yaml_samples/error_var_wrong_type.kibot.yaml b/tests/yaml_samples/error_var_wrong_type.kibot.yaml new file mode 100644 index 00000000..e66dac94 --- /dev/null +++ b/tests/yaml_samples/error_var_wrong_type.kibot.yaml @@ -0,0 +1,6 @@ +kibot: + version: 1 + +variants: + - name: ok + type: '' diff --git a/tests/yaml_samples/int_bom_fil_1.kibot.yaml b/tests/yaml_samples/int_bom_fil_1.kibot.yaml new file mode 100644 index 00000000..dde54311 --- /dev/null +++ b/tests/yaml_samples/int_bom_fil_1.kibot.yaml @@ -0,0 +1,86 @@ +# Example KiBot config file +kibot: + version: 1 + +filters: + - name: 'empty val' + type: 'generic' + comment: 'Remove components with empty value' + exclude_empty_val: true + + - name: 'by prefix' + type: 'generic' + comment: 'Remove components by prefix' + exclude_refs: + - R1 + - C* + + - name: no_KK_Q,Q + type: 'generic' + comment: 'Remove components with K K and Q,Q fields' + keys: ['K K', 'Q,Q'] + exclude_field: true + + - name: no Conf KK + type: 'generic' + comment: 'Remove components with K K and Q,Q in config' + keys: ['K K', 'Q,Q'] + exclude_config: true + config_separators: '' + config_field: BB + +outputs: + - name: 'empty_val' + comment: "BoM no empty val" + type: bom + dir: BoM + options: + output: 'empty_val.csv' + use_alt: true + exclude_filter: 'empty val' + + - name: 'by_prefix' + comment: "BoM no R1 C*" + type: bom + dir: BoM + options: + output: 'by_prefix.csv' + use_alt: true + exclude_filter: 'by prefix' + + - name: 'no_KK' + comment: "BoM no K K/Q,Q" + type: bom + dir: BoM + options: + output: 'no_kk.csv' + use_alt: true + exclude_filter: 'no_KK_Q,Q' + + - name: 'no conf KK' + comment: "BoM no K K/Q,Q in config" + type: bom + dir: BoM + options: + output: 'no_conf_kk.csv' + use_alt: true + exclude_filter: 'no Conf KK' + + - name: 'no_by_prefix' + comment: "BoM R1 C*" + type: bom + dir: BoM + options: + output: 'no_by_prefix.csv' + use_alt: true + exclude_filter: '!by prefix' + + - name: 'multi' + comment: "BoM C*" + type: bom + dir: BoM + options: + output: 'multi.csv' + use_alt: true + exclude_filter: ['!by prefix', 'empty val'] + diff --git a/tests/yaml_samples/int_bom_fil_dummy.kibot.yaml b/tests/yaml_samples/int_bom_fil_dummy.kibot.yaml new file mode 100644 index 00000000..8d1edc67 --- /dev/null +++ b/tests/yaml_samples/int_bom_fil_dummy.kibot.yaml @@ -0,0 +1,13 @@ +# Example KiBot config file +kibot: + version: 1 + +outputs: + - name: 'bom_internal' + comment: "Bill of Materials in CSV format" + type: bom + dir: BoM + options: + use_alt: true + exclude_filter: '' + diff --git a/tests/yaml_samples/int_bom_var_t2i_csv.kibot.yaml b/tests/yaml_samples/int_bom_var_t2i_csv.kibot.yaml index e14042fd..580f18ad 100644 --- a/tests/yaml_samples/int_bom_var_t2i_csv.kibot.yaml +++ b/tests/yaml_samples/int_bom_var_t2i_csv.kibot.yaml @@ -19,6 +19,7 @@ variants: comment: 'Default variant' type: ibom variants_blacklist: T2,T3 + variants_whitelist: '' - name: 'default2' comment: 'Default variant 2' diff --git a/tests/yaml_samples/int_bom_var_t2is_csv.kibot.yaml b/tests/yaml_samples/int_bom_var_t2is_csv.kibot.yaml new file mode 100644 index 00000000..7e3542ea --- /dev/null +++ b/tests/yaml_samples/int_bom_var_t2is_csv.kibot.yaml @@ -0,0 +1,27 @@ +# Example KiBot config file +kibot: + version: 1 + +filters: + - name: 'no R1' + type: 'generic' + comment: 'Remove components by prefix' + exclude_refs: + - R1 + +variants: + - name: 'test' + comment: 'Test variant' + type: ibom + file_id: '_(test)' + variants_blacklist: T1 + +outputs: + - name: 'bom filtered' + comment: "Bill of Materials test, no R1" + type: bom + dir: BoM + options: + exclude_filter: no R1 + variant: test + output: filter_R1.csv diff --git a/tests/yaml_samples/int_bom_var_t2s_csv.kibot.yaml b/tests/yaml_samples/int_bom_var_t2s_csv.kibot.yaml new file mode 100644 index 00000000..c055aeaf --- /dev/null +++ b/tests/yaml_samples/int_bom_var_t2s_csv.kibot.yaml @@ -0,0 +1,31 @@ +# Example KiBot config file +kibot: + version: 1 + +variants: + - name: 'dummy' + comment: 'Dummy variant' + type: kibom + file_id: '_(dummy)' + variant: '' + + - name: 'dummy2' + comment: 'Dummy 2 variant' + type: kibom + file_id: '_(dummy2)' + +outputs: + - name: 'bom_internal_dummy' + comment: "Bill of Materials in CSV format" + type: bom + dir: BoM + options: + variant: dummy + + - name: 'bom_internal_dummy2' + comment: "Bill of Materials in CSV format" + type: bom + dir: BoM + options: + variant: dummy2 + diff --git a/tests/yaml_samples/int_bom_wrong_variant.kibot.yaml b/tests/yaml_samples/int_bom_wrong_variant.kibot.yaml new file mode 100644 index 00000000..1a52e57e --- /dev/null +++ b/tests/yaml_samples/int_bom_wrong_variant.kibot.yaml @@ -0,0 +1,11 @@ +# Example KiBot config file +kibot: + version: 1 + +outputs: + - name: 'bom_internal2' + comment: "Bill of Materials in CSV format (2)" + type: bom + dir: BoM + options: + variant: foobar