From 84470bbc116d869fd6db3ac2754c309a72edbbda Mon Sep 17 00:00:00 2001 From: "Salvador E. Tropea" Date: Thu, 28 Jan 2021 12:43:01 -0300 Subject: [PATCH] Added first makefile generation test --- kibot/kiplot.py | 1 + tests/board_samples/kicad_5/test_v5.kicad_pcb | 1 + tests/test_plot/test_misc.py | 25 +++++++++++++++++++ tests/utils/context.py | 9 +++++++ tests/yaml_samples/makefile_1.kibot.yaml | 12 +++++++++ 5 files changed, 48 insertions(+) create mode 120000 tests/board_samples/kicad_5/test_v5.kicad_pcb create mode 100644 tests/yaml_samples/makefile_1.kibot.yaml diff --git a/kibot/kiplot.py b/kibot/kiplot.py index 8e959c80..10beb378 100644 --- a/kibot/kiplot.py +++ b/kibot/kiplot.py @@ -300,6 +300,7 @@ def adapt_file_name(name): def generate_makefile(makefile, cfg_file, outputs): + cfg_file = os.path.relpath(cfg_file) logger.info('- Creating makefile `{}` from `{}`'.format(makefile, cfg_file)) with open(makefile, 'wt') as f: f.write('#!/usr/bin/make\n') diff --git a/tests/board_samples/kicad_5/test_v5.kicad_pcb b/tests/board_samples/kicad_5/test_v5.kicad_pcb new file mode 120000 index 00000000..4ee82b5d --- /dev/null +++ b/tests/board_samples/kicad_5/test_v5.kicad_pcb @@ -0,0 +1 @@ +kibom-variante.kicad_pcb \ No newline at end of file diff --git a/tests/test_plot/test_misc.py b/tests/test_plot/test_misc.py index 4c49a628..6073351f 100644 --- a/tests/test_plot/test_misc.py +++ b/tests/test_plot/test_misc.py @@ -46,6 +46,7 @@ from kibot.misc import (EXIT_BAD_ARGS, EXIT_BAD_CONFIG, NO_PCB_FILE, NO_SCH_FILE POS_DIR = 'positiondir' +MK_TARGETS = ['position'] def test_skip_pre_and_outputs(): @@ -541,3 +542,27 @@ def test_no_colorama(): cmd = [os.path.abspath(os.path.dirname(os.path.abspath(__file__))+'/force_colorama_error.py')] ctx.do_run(cmd, use_a_tty=True) ctx.search_err(r'\[31m.\[1mERROR:Testing 1 2 3') + + +def test_makefile_1(): + prj = 'test_v5' + ctx = context.TestContext('test_makefile_1', prj, 'makefile_1', '') + mkfile = ctx.get_out_path('Makefile') + ctx.run(extra=['-m', mkfile]) + ctx.expect_out_file('Makefile') + targets = ctx.read_mk_targets(mkfile) + all = targets['all'] + phony = targets['.PHONY'] + for target in MK_TARGETS: + assert target in all + assert target in phony + assert target in targets + logging.debug('- Target `'+target+'` in all, .PHONY and itself OK') + # position target + deps = targets['position'].split(' ') + assert len(deps) == 2, deps + assert ctx.get_out_path(os.path.join(POS_DIR, prj+'-top_pos.csv')) + assert ctx.get_out_path(os.path.join(POS_DIR, prj+'-bottom_pos.csv')) + assert os.path.abspath(targets[targets['position']]) == ctx.board_file + logging.debug('- Target `position` OK') + ctx.clean_up() diff --git a/tests/utils/context.py b/tests/utils/context.py index c7f4f012..51ea0737 100644 --- a/tests/utils/context.py +++ b/tests/utils/context.py @@ -669,6 +669,15 @@ class TestContext(object): assert f in text, f logging.debug('- `'+f+'` OK') + def read_mk_targets(self, mkfile): + targets = {} + with open(mkfile, 'rt') as f: + for line in f.readlines(): + parts = line.split(':') + if len(parts) == 2: + targets[parts[0].strip()] = parts[1].strip() + return targets + class TestContextSCH(TestContext): diff --git a/tests/yaml_samples/makefile_1.kibot.yaml b/tests/yaml_samples/makefile_1.kibot.yaml new file mode 100644 index 00000000..aaeb0987 --- /dev/null +++ b/tests/yaml_samples/makefile_1.kibot.yaml @@ -0,0 +1,12 @@ +kibot: + version: 1 + +outputs: + - name: 'position' + type: position + dir: positiondir + options: + format: CSV # CSV or ASCII format + units: millimeters # millimeters or inches + separate_files_for_front_and_back: true + only_smd: true