From c4c33af68073aebb6f00780ff3434c03abf17d79 Mon Sep 17 00:00:00 2001 From: "Salvador E. Tropea" Date: Wed, 27 Jan 2021 16:12:46 -0300 Subject: [PATCH] Added some compress tests. Covers zip, tr.bz2 and rar creation for internal BoM, position and gerber files. --- tests/test_plot/test_gerber.py | 9 +++++---- tests/test_plot/test_int_bom.py | 1 + tests/test_plot/test_position.py | 12 +++++++---- tests/utils/context.py | 18 +++++++++++++++++ tests/yaml_samples/gerber_inner.kibot.yaml | 9 ++++++++- tests/yaml_samples/int_bom_fil_2.kibot.yaml | 10 +++++++++- .../simple_position_t2i.kibot.yaml | 20 +++++++++++++++---- 7 files changed, 65 insertions(+), 14 deletions(-) diff --git a/tests/test_plot/test_gerber.py b/tests/test_plot/test_gerber.py index f6c80eb5..2853ce12 100644 --- a/tests/test_plot/test_gerber.py +++ b/tests/test_plot/test_gerber.py @@ -66,10 +66,11 @@ def test_gerber_inner_ok(): prj = 'good-project' ctx = context.TestContext('Gerber_Inner', prj, 'gerber_inner', GERBER_DIR) ctx.run() - - ctx.expect_out_file(os.path.join(GERBER_DIR, prj+'_GND_Cu.gbr')) - ctx.expect_out_file(os.path.join(GERBER_DIR, prj+'_Signal1.gbr')) - ctx.expect_out_file(os.path.join(GERBER_DIR, 'test-'+prj+'.gbrjob')) + files = [prj+'_GND_Cu.gbr', prj+'_Signal1.gbr', 'test-'+prj+'.gbrjob'] + files = [os.path.join(GERBER_DIR, f) for f in files] + for f in files: + ctx.expect_out_file(f) + ctx.test_compress(prj+'-result.rar', files) ctx.clean_up() diff --git a/tests/test_plot/test_int_bom.py b/tests/test_plot/test_int_bom.py index d8c4a780..0b1475d3 100644 --- a/tests/test_plot/test_int_bom.py +++ b/tests/test_plot/test_int_bom.py @@ -1351,6 +1351,7 @@ def test_int_bom_fil_2(): rows, header, info = ctx.load_csv('virtual.csv') check_kibom_test_netlist(rows, ref_column, 2, None, ['R1-R2', 'C1-C2']) ctx.search_err(r".?R3.? component in board, but not in schematic") + ctx.test_compress(prj+'-result.zip', ['BoM/smd.csv', 'BoM/tht.csv', 'BoM/virtual.csv']) ctx.clean_up(keep_project=True) diff --git a/tests/test_plot/test_position.py b/tests/test_plot/test_position.py index 6a4a0f20..c3ceb5d7 100644 --- a/tests/test_plot/test_position.py +++ b/tests/test_plot/test_position.py @@ -188,14 +188,18 @@ def test_position_variant_t2i(): prj = 'kibom-variant_3' ctx = context.TestContext('test_position_variant_t2i', prj, 'simple_position_t2i', POS_DIR) ctx.run() - rows, header, info = ctx.load_csv(prj+'-both_pos.csv') + files = ['-both_pos.csv', '-both_pos_[2].csv', '-both_pos_(production).csv', '-both_pos_(test).csv'] + files = [prj+f for f in files] + rows, header, info = ctx.load_csv(files[0]) check_comps(rows, ['R1', 'R2', 'R3']) - rows, header, info = ctx.load_csv(prj+'-both_pos_[2].csv') + rows, header, info = ctx.load_csv(files[1]) check_comps(rows, ['R1', 'R2', 'R3']) - rows, header, info = ctx.load_csv(prj+'-both_pos_(production).csv') + rows, header, info = ctx.load_csv(files[2]) check_comps(rows, ['C2', 'R1', 'R2', 'R3']) - rows, header, info = ctx.load_csv(prj+'-both_pos_(test).csv') + rows, header, info = ctx.load_csv(files[3]) check_comps(rows, ['C1', 'C2', 'R1', 'R3']) + files = [POS_DIR+'/'+f for f in files] + ctx.test_compress(prj+'-result.tar.bz2', files) ctx.clean_up(keep_project=True) diff --git a/tests/utils/context.py b/tests/utils/context.py index 648d508f..c7f4f012 100644 --- a/tests/utils/context.py +++ b/tests/utils/context.py @@ -651,6 +651,24 @@ class TestContext(object): headers = rows.pop(0) return rows, headers, sh_head + def test_compress(self, fname, files): + logging.debug('Checking compressed output: '+fname) + if fname.endswith('.zip'): + cmd = ['unzip', '-t', self.get_out_path(fname)] + elif fname.endswith('.rar'): + cmd = ['rar', 't', self.get_out_path(fname)] + else: + cmd = ['tar', 'tvf', self.get_out_path(fname)] + res = subprocess.check_output(cmd, stderr=subprocess.STDOUT) + text = res.decode() + if fname.endswith('.zip'): + assert 'No errors detected' in text + elif fname.endswith('.rar'): + assert 'All OK' in text + for f in files: + assert f in text, f + logging.debug('- `'+f+'` OK') + class TestContextSCH(TestContext): diff --git a/tests/yaml_samples/gerber_inner.kibot.yaml b/tests/yaml_samples/gerber_inner.kibot.yaml index c3b4c931..abd0317d 100644 --- a/tests/yaml_samples/gerber_inner.kibot.yaml +++ b/tests/yaml_samples/gerber_inner.kibot.yaml @@ -3,7 +3,6 @@ kibot: version: 1 outputs: - - name: 'gerbers' comment: "Gerbers for the Gerber god" type: gerber @@ -38,3 +37,11 @@ outputs: suffix: Signal1 description: 'Inner signals 1' + - name: result + comment: Test rar compress + type: compress + options: + format: RAR + files: + - from_output: gerbers + diff --git a/tests/yaml_samples/int_bom_fil_2.kibot.yaml b/tests/yaml_samples/int_bom_fil_2.kibot.yaml index d299197d..890b33f2 100644 --- a/tests/yaml_samples/int_bom_fil_2.kibot.yaml +++ b/tests/yaml_samples/int_bom_fil_2.kibot.yaml @@ -37,7 +37,7 @@ outputs: use_alt: true exclude_filter: 'no tht' - - name: 'no smd' + - name: 'virtual' comment: "BoM no virtual" type: bom dir: BoM @@ -46,3 +46,11 @@ outputs: use_alt: true exclude_filter: 'no virtual' + - name: result + comment: Test zip compress + type: compress + options: + files: + - from_output: 'no smd' + - from_output: 'no tht' + - from_output: 'virtual' diff --git a/tests/yaml_samples/simple_position_t2i.kibot.yaml b/tests/yaml_samples/simple_position_t2i.kibot.yaml index a875cf1f..8833cbbb 100644 --- a/tests/yaml_samples/simple_position_t2i.kibot.yaml +++ b/tests/yaml_samples/simple_position_t2i.kibot.yaml @@ -27,7 +27,7 @@ variants: variants_whitelist: T1, Default outputs: - - name: 'bom_internal' + - name: 'pos_internal' comment: "Bill of Materials in CSV format" type: position dir: positiondir @@ -37,7 +37,7 @@ outputs: only_smd: false variant: default - - name: 'bom_internal2' + - name: 'pos_internal2' comment: "Bill of Materials in CSV format (2)" type: position dir: positiondir @@ -47,7 +47,7 @@ outputs: only_smd: false variant: default2 - - name: 'bom_internal_production' + - name: 'pos_internal_production' comment: "Bill of Materials in CSV format for production" type: position dir: positiondir @@ -57,7 +57,7 @@ outputs: only_smd: false variant: production - - name: 'bom_internal_test' + - name: 'pos_internal_test' comment: "Bill of Materials in CSV format for test" type: position dir: positiondir @@ -66,3 +66,15 @@ outputs: separate_files_for_front_and_back: false only_smd: false variant: test + + - name: result + comment: Test tarball compress + type: compress + options: + format: TAR + compression: bzip2 + files: + - from_output: pos_internal + - from_output: pos_internal2 + - from_output: pos_internal_production + - from_output: pos_internal_test