WIP
This commit is contained in:
@@ -6,6 +6,8 @@ module.exports = {
|
|||||||
const main = (...body) => {
|
const main = (...body) => {
|
||||||
return `
|
return `
|
||||||
{% main %}
|
{% main %}
|
||||||
|
${params.at /* parametric position given by ergogen */}
|
||||||
|
|
||||||
${...body.join('\n')}
|
${...body.join('\n')}
|
||||||
`
|
`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
from kiutils.footprint import Footprint
|
from kiutils.footprint import Footprint
|
||||||
|
from kiutils.items.fpitems import FpText
|
||||||
|
|
||||||
class Converter:
|
class Converter:
|
||||||
footprint: Footprint
|
footprint: Footprint
|
||||||
@@ -10,6 +11,9 @@ class Converter:
|
|||||||
|
|
||||||
def convert(self) -> str:
|
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()
|
main = self.footprint.to_sexpr()
|
||||||
|
|
||||||
# replace new footprint name with module to be consistent
|
# replace new footprint name with module to be consistent
|
||||||
|
|||||||
@@ -3,46 +3,55 @@ from ergogen_footprint_converter.converter import Converter
|
|||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from kiutils.footprint import Footprint
|
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
|
@pytest.fixture
|
||||||
def footprint():
|
def footprint():
|
||||||
footprint = Footprint.create_new("test", "test")
|
footprint = Footprint.create_new("test", "test")
|
||||||
footprint.tedit = "64de79c2"
|
footprint.tedit = "64de79c2"
|
||||||
print(footprint)
|
footprint.graphicItems = []
|
||||||
|
|
||||||
return footprint
|
return footprint
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def template() -> str:
|
def template() -> str:
|
||||||
return open("res/template.js").read()
|
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)
|
converter = Converter(footprint)
|
||||||
|
|
||||||
strip = lambda s: ''.join([x.strip() for x in s.split()])
|
|
||||||
res = strip(converter.convert().strip('\n').strip())
|
res = strip(converter.convert().strip('\n').strip())
|
||||||
|
|
||||||
main = """
|
expected = strip(Converter.replace_template(template, "", main_rendered, "", ""))
|
||||||
(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, "", ""))
|
|
||||||
|
|
||||||
assert res == expected
|
assert res == expected
|
||||||
|
|
||||||
def test_caption(template):
|
def test_contains_caption(footprint: Footprint, template: str, main_rendered):
|
||||||
None
|
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):
|
def test_replace_template(template: str):
|
||||||
|
|||||||
Reference in New Issue
Block a user