Test + Impl: empty footprint
This commit is contained in:
8
pdm.lock
generated
8
pdm.lock
generated
@@ -5,7 +5,7 @@
|
||||
groups = ["default", "test", "dev"]
|
||||
strategy = ["cross_platform", "inherit_metadata"]
|
||||
lock_version = "4.4.1"
|
||||
content_hash = "sha256:007db48b3ef077fcedf2de70b1d3f8d3cc0e26f145fbb40868b84d4847717834"
|
||||
content_hash = "sha256:3fa91e80a653abfaf653ee5ca1604ecb90d017144568af9ce50b04d47871092f"
|
||||
|
||||
[[package]]
|
||||
name = "argparse"
|
||||
@@ -198,7 +198,7 @@ files = [
|
||||
|
||||
[[package]]
|
||||
name = "pytest"
|
||||
version = "8.1.1"
|
||||
version = "8.1.2"
|
||||
requires_python = ">=3.8"
|
||||
summary = "pytest: simple powerful testing with Python"
|
||||
groups = ["default", "dev", "test"]
|
||||
@@ -209,8 +209,8 @@ dependencies = [
|
||||
"pluggy<2.0,>=1.4",
|
||||
]
|
||||
files = [
|
||||
{file = "pytest-8.1.1-py3-none-any.whl", hash = "sha256:2a8386cfc11fa9d2c50ee7b2a57e7d898ef90470a7a34c4b949ff59662bb78b7"},
|
||||
{file = "pytest-8.1.1.tar.gz", hash = "sha256:ac978141a75948948817d360297b7aae0fcb9d6ff6bc9ec6d514b85d5a65c044"},
|
||||
{file = "pytest-8.1.2-py3-none-any.whl", hash = "sha256:6c06dc309ff46a05721e6fd48e492a775ed8165d2ecdf57f156a80c7e95bb142"},
|
||||
{file = "pytest-8.1.2.tar.gz", hash = "sha256:f3c45d1d5eed96b01a2aea70dee6a4a366d51d38f9957768083e4fecfc77f3ef"},
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
||||
@@ -25,7 +25,7 @@ classifiers = [
|
||||
dependencies = [
|
||||
"argparse",
|
||||
"pathlib",
|
||||
"pytest>=8.1.1",
|
||||
"pytest>=8.1.2",
|
||||
"mypy>=1.10.0",
|
||||
"kiutils>=1.4.8",
|
||||
]
|
||||
|
||||
@@ -2,17 +2,22 @@ from kiutils.footprint import Footprint
|
||||
|
||||
class Converter:
|
||||
footprint: Footprint
|
||||
template: str
|
||||
|
||||
def __init__(self, footprint: Footprint):
|
||||
self.footprint = footprint
|
||||
self.template = open("res/template.js").read()
|
||||
|
||||
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
|
||||
def replace_template(params, main, captions, pins) -> str:
|
||||
template = open("res/template.js").read()
|
||||
|
||||
def replace_template(template: str, params: str, main: str, captions: str, pins: str) -> str:
|
||||
replacements = {
|
||||
"{% params %}": params,
|
||||
"{% main %}": main,
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user