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

8
pdm.lock generated
View File

@@ -5,7 +5,7 @@
groups = ["default", "test", "dev"] groups = ["default", "test", "dev"]
strategy = ["cross_platform", "inherit_metadata"] strategy = ["cross_platform", "inherit_metadata"]
lock_version = "4.4.1" lock_version = "4.4.1"
content_hash = "sha256:007db48b3ef077fcedf2de70b1d3f8d3cc0e26f145fbb40868b84d4847717834" content_hash = "sha256:3fa91e80a653abfaf653ee5ca1604ecb90d017144568af9ce50b04d47871092f"
[[package]] [[package]]
name = "argparse" name = "argparse"
@@ -198,7 +198,7 @@ files = [
[[package]] [[package]]
name = "pytest" name = "pytest"
version = "8.1.1" version = "8.1.2"
requires_python = ">=3.8" requires_python = ">=3.8"
summary = "pytest: simple powerful testing with Python" summary = "pytest: simple powerful testing with Python"
groups = ["default", "dev", "test"] groups = ["default", "dev", "test"]
@@ -209,8 +209,8 @@ dependencies = [
"pluggy<2.0,>=1.4", "pluggy<2.0,>=1.4",
] ]
files = [ files = [
{file = "pytest-8.1.1-py3-none-any.whl", hash = "sha256:2a8386cfc11fa9d2c50ee7b2a57e7d898ef90470a7a34c4b949ff59662bb78b7"}, {file = "pytest-8.1.2-py3-none-any.whl", hash = "sha256:6c06dc309ff46a05721e6fd48e492a775ed8165d2ecdf57f156a80c7e95bb142"},
{file = "pytest-8.1.1.tar.gz", hash = "sha256:ac978141a75948948817d360297b7aae0fcb9d6ff6bc9ec6d514b85d5a65c044"}, {file = "pytest-8.1.2.tar.gz", hash = "sha256:f3c45d1d5eed96b01a2aea70dee6a4a366d51d38f9957768083e4fecfc77f3ef"},
] ]
[[package]] [[package]]

View File

@@ -25,7 +25,7 @@ classifiers = [
dependencies = [ dependencies = [
"argparse", "argparse",
"pathlib", "pathlib",
"pytest>=8.1.1", "pytest>=8.1.2",
"mypy>=1.10.0", "mypy>=1.10.0",
"kiutils>=1.4.8", "kiutils>=1.4.8",
] ]

View File

@@ -2,17 +2,22 @@ from kiutils.footprint import Footprint
class Converter: class Converter:
footprint: Footprint footprint: Footprint
template: str
def __init__(self, footprint: Footprint): def __init__(self, footprint: Footprint):
self.footprint = footprint self.footprint = footprint
self.template = open("res/template.js").read()
def convert(self) -> str: def convert(self) -> str:
return ""
main = self.footprint.to_sexpr()
# replace new footprint name with module to be consistent
main = main.replace("footprint", "module")
return self.replace_template(self.template, "", main, "", "")
@staticmethod @staticmethod
def replace_template(params, main, captions, pins) -> str: def replace_template(template: str, params: str, main: str, captions: str, pins: str) -> str:
template = open("res/template.js").read()
replacements = { replacements = {
"{% params %}": params, "{% params %}": params,
"{% main %}": main, "{% main %}": main,

View File

@@ -6,23 +6,45 @@ from kiutils.footprint import Footprint
@pytest.fixture @pytest.fixture
def footprint(): def footprint():
return Footprint.create_new("test", "test") footprint = Footprint.create_new("test", "test")
footprint.tedit = "64de79c2"
print(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, template): def test_empty_footprint(footprint, template):
converter = Converter(footprint) 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 = """ main = """
(module test) (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):
None
def test_replace_template(template: str): def test_replace_template(template: str):
replacements = { replacements = {
"{% params %}": "one", "{% params %}": "one",
@@ -31,12 +53,13 @@ def test_replace_template(template: str):
"{% pins %}": "four" "{% pins %}": "four"
} }
expected = template
for key in replacements: 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