Files
50ohm/test/test_question_pool.py
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

101 lines
3.4 KiB
Python

import json
from src.build import Build
from src.config import Config
from src.edition import Edition
def write_pool(path, number):
path.write_text(
json.dumps(
{
"sections": [
{
"title": f"Pool {number}",
"questions": [
{
"number": number,
"question": f"Fråga {number}",
"answer_a": "A",
"answer_b": "B",
"answer_c": "C",
"answer_d": "D",
}
],
}
]
}
),
encoding="utf-8",
)
def write_toc(tmp_path, edition, section_content):
(tmp_path / "toc").mkdir(exist_ok=True)
(tmp_path / "contents" / "sections").mkdir(parents=True, exist_ok=True)
(tmp_path / "contents" / "sections" / "intro.md").write_text(section_content, encoding="utf-8")
(tmp_path / "toc" / f"{edition}.json").write_text(
json.dumps(
{
"title": "Instegskurs",
"edition": str(edition),
"chapters": [
{
"title": "Inledning",
"ident": "inledning",
"sections": [{"title": "Välkommen", "ident": "intro"}],
}
],
}
),
encoding="utf-8",
)
def test_editions():
assert [str(edition) for edition in Edition] == ["INSTEG", "HAREC", "UPPGRADERING"]
def test_build_without_question_pool(tmp_path):
write_toc(tmp_path, Edition.instegs, "Hej [question:SE101]")
build = Build(Config(content_path=tmp_path, build_path=tmp_path / "build"))
assert not build.has_question_pool
build.build_website()
build.build_edition(Edition.instegs)
build.build_solutions()
build.build_question_index()
out = tmp_path / "build"
assert (out / "index.html").exists()
assert (out / "INSTEG_course_index.html").exists()
assert (out / "INSTEG_intro.html").exists()
assert not (out / "simulering.html").exists()
assert not (out / "ovning.html").exists()
assert not (tmp_path / "build" / "assets" / "question_index.json").exists()
assert 'lang="sv"' in (out / "index.html").read_text(encoding="utf-8")
assert "simulering.html" not in (out / "index.html").read_text(encoding="utf-8")
def test_build_with_question_pool_and_default_metadata(tmp_path):
questions = tmp_path / "contents" / "questions"
questions.mkdir(parents=True)
write_pool(questions / "question_pool.json", "SE101")
write_toc(tmp_path, Edition.instegs, "[question:SE101]")
build = Build(Config(content_path=tmp_path, build_path=tmp_path / "build"))
assert build.has_question_pool
assert set(build.questions) == {"SE101"}
build.build_website()
build.build_edition(Edition.instegs)
build.build_question_index()
out = tmp_path / "build"
assert (out / "simulering.html").exists()
assert (out / "ovning.html").exists()
assert "Fråga SE101" in (out / "INSTEG_intro.html").read_text(encoding="utf-8")
assert json.loads((out / "assets" / "question_index.json").read_text(encoding="utf-8"))["SE101"]["editions"] == [
"INSTEG"
]