from ergogen_footprint_converter.converter import Converter import pytest 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 def footprint(): footprint = Footprint.create_new("test", "test") footprint.tedit = "64de79c2" footprint.graphicItems = [] return footprint @pytest.fixture def template() -> str: return open("res/template.js").read() strip = lambda s: ''.join([x.strip() for x in s.split()]) def test_empty_footprint(footprint, template, main_rendered): converter = Converter(footprint) res = strip(converter.convert().strip('\n').strip()) expected = strip(Converter.replace_template(template, "", main_rendered, "", "")) assert res == expected def test_contains_caption(footprint: Footprint, template: str, main_rendered): 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): replacements = { "{% params %}": "one", "{% main %}": "two", "{% captions %}": "three", "{% pins %}": "four" } expected = template for key in replacements: expected = expected.replace(key, replacements[key]) res = Converter.replace_template(template, "one", "two", "three", "four") assert res == expected