From 0665cea3ffa6802ebcd2af0aa423db892df28a8a Mon Sep 17 00:00:00 2001 From: "Salvador E. Tropea" Date: Tue, 23 Jan 2024 10:49:12 -0300 Subject: [PATCH] [Tests][BoM][Added] HRTXT simple test --- tests/test_plot/test_int_bom.py | 9 +++++++++ tests/utils/context.py | 15 +++++++++++++++ .../yaml_samples/int_bom_simple_hrtxt.kibot.yaml | 12 ++++++++++++ 3 files changed, 36 insertions(+) create mode 100644 tests/yaml_samples/int_bom_simple_hrtxt.kibot.yaml diff --git a/tests/test_plot/test_int_bom.py b/tests/test_plot/test_int_bom.py index b0be8fad..24b05a24 100644 --- a/tests/test_plot/test_int_bom.py +++ b/tests/test_plot/test_int_bom.py @@ -288,6 +288,15 @@ def test_int_bom_simple_csv(test_dir): ctx.clean_up() +def test_int_bom_simple_hrtxt(test_dir): + ctx, out = kibom_setup(test_dir, 'int_bom_simple_hrtxt', ext='txt') + ctx.expect_out_file(out, sub=True) + rows, header, info = ctx.load_hrtxt(out) + check_csv_info(info, KIBOM_PRJ_INFO, KIBOM_STATS) + kibom_verif(rows, header) + ctx.clean_up() + + def test_int_bom_csv_no_info(test_dir): """ No PCB info """ ctx, out = kibom_setup(test_dir, 'int_bom_csv_no_info') diff --git a/tests/utils/context.py b/tests/utils/context.py index e21f48af..6bc4530a 100644 --- a/tests/utils/context.py +++ b/tests/utils/context.py @@ -690,6 +690,21 @@ class TestContext(object): info.append(r) return rows, header, info + def load_hrtxt(self, filename): + nm = self.expect_out_file(os.path.join(self.sub_dir, filename)) + nm_csv = nm.replace('.txt', '.csv') + with open(nm) as f: + with open(nm_csv, 'wt') as d: + for ln in f: + if ln.startswith('I---'): + continue + if ln[0] == 'I': + ln = ln[1:-2] + ln = ln.strip() + d.write(','.join(re.split(r'\s*I', ln))) + d.write('\n') + return self.load_csv(filename.replace('.txt', '.csv')) + def load_html(self, filename): file = self.expect_out_file(os.path.join(self.sub_dir, filename)) with open(file) as f: diff --git a/tests/yaml_samples/int_bom_simple_hrtxt.kibot.yaml b/tests/yaml_samples/int_bom_simple_hrtxt.kibot.yaml new file mode 100644 index 00000000..f448b298 --- /dev/null +++ b/tests/yaml_samples/int_bom_simple_hrtxt.kibot.yaml @@ -0,0 +1,12 @@ +# Example KiBot config file +kibot: + version: 1 + +outputs: + - name: 'bom_internal' + comment: "Bill of Materials in Human Readable Text format" + type: bom + dir: BoM + options: + group_fields: ['Part', 'Part Lib', 'Value', 'Footprint', 'Footprint Lib'] + format: HRTXT