Test + Impl: empty footprint

This commit is contained in:
Jonas Zeunert
2024-04-27 22:10:24 +02:00
parent ebcd74cd5c
commit b4b13ec175
4 changed files with 45 additions and 17 deletions

View File

@@ -6,23 +6,45 @@ from kiutils.footprint import Footprint
@pytest.fixture
def footprint():
return Footprint.create_new("test", "test")
footprint = Footprint.create_new("test", "test")
footprint.tedit = "64de79c2"
print(footprint)
return footprint
@pytest.fixture
def template() -> str:
return open("res/template.js").read()
def test_empty(footprint, template):
def test_empty_footprint(footprint, template):
converter = Converter(footprint)
res = converter.convert()
strip = lambda s: ''.join([x.strip() for x in s.split()])
res = strip(converter.convert().strip('\n').strip())
expected = """
(module test)
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, "", ""))
assert res == expected
def test_caption(template):
None
def test_replace_template(template: str):
replacements = {
"{% params %}": "one",
@@ -31,12 +53,13 @@ def test_replace_template(template: str):
"{% pins %}": "four"
}
expected = template
for key in replacements:
template = template.replace(key, replacements[key])
expected = expected.replace(key, replacements[key])
res = Converter.replace_template("one", "two", "three", "four")
res = Converter.replace_template(template, "one", "two", "three", "four")
assert res == template
assert res == expected