diff --git a/res/template.js b/res/template.js index aacb8c9..b03f4bc 100644 --- a/res/template.js +++ b/res/template.js @@ -6,6 +6,8 @@ module.exports = { const main = (...body) => { return ` {% main %} + ${params.at /* parametric position given by ergogen */} + ${...body.join('\n')} ` } diff --git a/src/ergogen_footprint_converter/converter.py b/src/ergogen_footprint_converter/converter.py index 9ea196c..8d6ac97 100644 --- a/src/ergogen_footprint_converter/converter.py +++ b/src/ergogen_footprint_converter/converter.py @@ -1,4 +1,5 @@ from kiutils.footprint import Footprint +from kiutils.items.fpitems import FpText class Converter: footprint: Footprint @@ -10,6 +11,9 @@ class Converter: def convert(self) -> str: + captions = self.footprint.graphicItems + captions_str = ''.join(list(map(lambda x: x.to_sexpr().join('\n'), captions))) + self.footprint.graphicItems = [] main = self.footprint.to_sexpr() # replace new footprint name with module to be consistent diff --git a/tests/unit/test_converter.py b/tests/unit/test_converter.py index 21e3bea..0c63abe 100644 --- a/tests/unit/test_converter.py +++ b/tests/unit/test_converter.py @@ -3,46 +3,55 @@ from ergogen_footprint_converter.converter import Converter import pytest from kiutils.footprint import Footprint +from kiutils.items.fpitems import FpText + +@pytest.fixture +def main_rendered (): + return """ + (module "test" (version 20211014) (generator kiutils) + (layer "F.Cu") + (tedit 64de79c2) + ) + """ @pytest.fixture def footprint(): footprint = Footprint.create_new("test", "test") footprint.tedit = "64de79c2" - print(footprint) + footprint.graphicItems = [] + return footprint @pytest.fixture def template() -> str: return open("res/template.js").read() -def test_empty_footprint(footprint, template): +strip = lambda s: ''.join([x.strip() for x in s.split()]) + +def test_empty_footprint(footprint, template, main_rendered): converter = Converter(footprint) - strip = lambda s: ''.join([x.strip() for x in s.split()]) res = strip(converter.convert().strip('\n').strip()) - main = """ - (module "test" (version 20211014) (generator kiutils) - (layer "F.Cu") - (tedit 64de79c2) - (fp_text reference "REF**" (at 0 -0.5 unlocked) (layer "F.SilkS") - (effects (font (size 1.0 1.0) (thickness 0.15))) - ) - (fp_text value "test" (at 0 1 unlocked) (layer "F.Fab") - (effects (font (size 1.0 1.0) (thickness 0.15))) - ) - (fp_text user "${REFERENCE}" (at 0 2.5 unlocked) (layer "F.Fab") - (effects (font (size 1.0 1.0) (thickness 0.15))) - ) - ) - """ - - expected = strip(Converter.replace_template(template, "", main, "", "")) + expected = strip(Converter.replace_template(template, "", main_rendered, "", "")) assert res == expected -def test_caption(template): - None +def test_contains_caption(footprint: Footprint, template: str, main_rendered): + first_item = FpText("Test 1") + second_item =FpText("Test 2") + captions = [first_item, second_item] + captions_str = ''.join(list(map(lambda x: x.to_sexpr().join('\n'), captions))) + print(captions_str) + + footprint.graphicItems = captions + + result = strip(Converter(footprint).convert()) + + + expected = strip(Converter.replace_template(template, "", main_rendered, captions_str, "")) + + assert result == expected def test_replace_template(template: str):