Test: convert_template
This commit is contained in:
0
promicro.js
Normal file
0
promicro.js
Normal file
0
promicro.kicad_mod
Normal file
0
promicro.kicad_mod
Normal file
@@ -8,3 +8,7 @@ class Converter:
|
|||||||
|
|
||||||
def convert(self) -> str:
|
def convert(self) -> str:
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def replace_template(params, main, captions, pins) -> str:
|
||||||
|
return ""
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ from kiutils.footprint import Footprint
|
|||||||
def main (args) -> None:
|
def main (args) -> None:
|
||||||
check_args(args)
|
check_args(args)
|
||||||
|
|
||||||
print("> Converting " + args["in_file"].__str__())
|
print("> Input: " + args["in_file"].absolute().__str__())
|
||||||
|
|
||||||
converted = convert(args["in_file"])
|
converted = convert(args["in_file"])
|
||||||
|
|
||||||
@@ -22,10 +22,16 @@ def main (args) -> None:
|
|||||||
print("> Output written! Exiting...")
|
print("> Output written! Exiting...")
|
||||||
|
|
||||||
def convert(in_file: Path) -> str:
|
def convert(in_file: Path) -> str:
|
||||||
|
print("> Parsing input...")
|
||||||
|
|
||||||
parsed = Footprint.from_file(in_file.absolute().__str__())
|
parsed = Footprint.from_file(in_file.absolute().__str__())
|
||||||
|
|
||||||
|
print("> Input parsed!")
|
||||||
|
|
||||||
converter = Converter(parsed)
|
converter = Converter(parsed)
|
||||||
|
|
||||||
|
print("> Converting...")
|
||||||
|
|
||||||
return converter.convert()
|
return converter.convert()
|
||||||
|
|
||||||
|
|
||||||
@@ -33,7 +39,7 @@ def write_output (output: str, in_file: Path, out_dir: Path) -> None:
|
|||||||
filename = in_file.name.split('.')[0] + ".js"
|
filename = in_file.name.split('.')[0] + ".js"
|
||||||
|
|
||||||
out_file = out_dir / filename
|
out_file = out_dir / filename
|
||||||
print("> Writing output to " + out_file.__str__())
|
print("> Writing output to " + out_file.absolute().__str__())
|
||||||
|
|
||||||
with open(out_file, 'w') as file:
|
with open(out_file, 'w') as file:
|
||||||
file.writelines(output)
|
file.writelines(output)
|
||||||
|
|||||||
@@ -1,9 +1,3 @@
|
|||||||
// Arduino ProMicro atmega32u4au
|
|
||||||
// Params
|
|
||||||
// orientation: default is down
|
|
||||||
// if down, power led will face the pcb
|
|
||||||
// if up, power led will face away from pcb
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
params: {
|
params: {
|
||||||
designator: 'MCU',
|
designator: 'MCU',
|
||||||
@@ -126,4 +120,4 @@ module.exports = {
|
|||||||
`
|
`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,43 @@
|
|||||||
from ergogen_footprint_converter.converter import Converter
|
from ergogen_footprint_converter.converter import Converter
|
||||||
|
|
||||||
def test_convert():
|
import pytest
|
||||||
input = ""
|
|
||||||
converter = Converter(input)
|
from kiutils.footprint import Footprint
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def footprint():
|
||||||
|
return Footprint.create_new("test", "test")
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def template() -> str:
|
||||||
|
return open("res/template.js").read()
|
||||||
|
|
||||||
|
def test_empty(footprint, template):
|
||||||
|
converter = Converter(footprint)
|
||||||
|
|
||||||
res = converter.convert()
|
res = converter.convert()
|
||||||
|
|
||||||
|
expected = """
|
||||||
|
(module test)
|
||||||
|
"""
|
||||||
|
|
||||||
|
assert res == expected
|
||||||
|
|
||||||
|
def test_replace_template(template: str):
|
||||||
|
replacements = {
|
||||||
|
"{% params %}": "one",
|
||||||
|
"{% main %}": "two",
|
||||||
|
"{% captions %}": "three",
|
||||||
|
"{% pins %}": "four"
|
||||||
|
}
|
||||||
|
|
||||||
|
for key in replacements:
|
||||||
|
template = template.replace(key, replacements[key])
|
||||||
|
|
||||||
|
res = Converter.replace_template("one", "two", "three", "four")
|
||||||
|
|
||||||
|
assert res == template
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user