Files
SuperminarenandClaude Sonnet 5.5 874838f525 Swedish adaptation: Instegscertifikat and HAREC
- Editions replaced by INSTEG, HAREC and UPPGRADERING (Instegscertifikat -> HAREC)
- Question pool optional; simulator, homework tool and solutions switch off without one
- All UI strings, templates, renderers and project JS localised to sv-SE
  (decimal comma, Swedish non-breaking-space rules, Å/Ä/Ö in Morse table)
- DARC branding, membership CTA and German links removed; attribution footer added
- Page names centralised in src/pages.py
- README and docs rewritten in Swedish

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2026-10-10 15:03:02 +02:00

92 lines
2.9 KiB
Python

import json
import pytest
from jinja2 import Environment, FileSystemLoader
import src.config as config
from renderer.document import Document
from renderer.fifty_ohm_html_renderer import FiftyOhmHtmlRenderer
conf = config.Config()
def parse_question_pool():
with open(conf.p_data_question_pool) as question_pool_file:
question_pool = json.load(question_pool_file)
questions = {}
for exampart in question_pool["sections"]:
for chapter in exampart["sections"]:
if "questions" in chapter:
for question in chapter["questions"]:
questions[question["number"]] = question
if "sections" in chapter:
for section in chapter["sections"]:
for question in section["questions"]:
questions[question["number"]] = question
return questions
env = Environment(loader=FileSystemLoader("templates/html"))
question_template = env.get_template("question.html")
def question_stub(number):
questions = parse_question_pool()
"""Combines the question pool with our internal metadata"""
with open(conf.p_data_metadata) as metadata_file:
metadata = json.load(metadata_file)
question = questions[number]
metadata = metadata[f"{number}"]
if "answer_a" in question:
answers = [question["answer_a"], question["answer_b"], question["answer_c"], question["answer_d"]]
else:
answers = []
if metadata["picture_a"] != "":
answer_pictures = [
metadata["picture_a"],
metadata["picture_b"],
metadata["picture_c"],
metadata["picture_d"],
]
else:
answer_pictures = []
if "picture_question" in question:
picture_question = metadata["picture_question"]
else:
picture_question = ""
return question_template.render(
question=question["question"],
number=number,
layout=metadata["layout"],
picture_question=picture_question,
answers=answers,
answer_pictures=answer_pictures,
)
def include_stub(include):
with open(conf.p_data_html / f"{include}.html") as file:
return file.read()
@pytest.mark.skip("Requires special files")
@pytest.mark.html
def test_html(capsys):
with capsys.disabled():
with open("test/acceptanceTest.md") as file:
content = file.read()
with FiftyOhmHtmlRenderer(
question_renderer=question_stub,
include_handler=include_stub,
) as renderer:
output = renderer.render(Document(content))
with open("test/acceptanceTest.html", "w") as output_file:
output_file.write(output)