"""The accounting corpus's SECOND document per format: the elements the witness could not see until 2026-09-18. An independent review of the gate found that the witness -- and therefore the whole accounting, because rows 2 and 3 require the build's inventory to EQUAL it -- counted no header, no comment, no speaker note, no hidden sheet, no formula, no citation and no figure caption. What nothing counts, nothing can lose visibly. It also found that 20 of 63 element types had a count of ZERO in their only fixture, so six of seven witness mutants survived. These documents are written BY HAND, part by part, for the reason the XML fixtures state: a library that writes and then reads its own format proves only that it agrees with itself. Every count they carry is written down in `tests/fixtures/README.md` by a person reading these strings, not by running the witness over them. python3 tests/fixtures/accounting/make_accounting_fixtures.py """ from __future__ import annotations import io import zipfile from pathlib import Path HERE = Path(__file__).resolve().parent CORPUS = HERE / "corpus" _ZIP_DATE = (2020, 1, 1, 0, 0, 0) _XML = '' _W = 'xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"' _A = 'xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"' _P = 'xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main"' _S = 'xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"' def build_zip(parts: dict[str, str | bytes]) -> bytes: """Zip the parts with a fixed timestamp, so a regeneration that changes nothing leaves the bytes alone and `git diff --quiet` stays a real check.""" out = io.BytesIO() with zipfile.ZipFile(out, "w", compression=zipfile.ZIP_DEFLATED) as archive: for name, payload in parts.items(): info = zipfile.ZipInfo(name, date_time=_ZIP_DATE) info.compress_type = zipfile.ZIP_DEFLATED archive.writestr(info, payload) return out.getvalue() # --- docx: a header, a footer, a comment, an endnote and a text box ---------- _DOCX_BODY = ( '' "Krav til gangbruer" "Gangbruer skal ha rekkverk paa begge sider." "" "Bredde" "3,0 m" "" "" "Merk: kravet gjelder ikke midlertidige bruer." "" ) _DOCX_PARTS: dict[str, str | bytes] = { "[Content_Types].xml": _XML + '' + '' + '' + '' + '' + "", "_rels/.rels": _XML + '' + '', "word/_rels/document.xml.rels": _XML + '' + '', "word/styles.xml": _XML + f"" + '' + "", "word/document.xml": _XML + f"{_DOCX_BODY}", "word/header1.xml": _XML + f"Utkast - gjelder ikke etter 2026-01-01" + "", "word/footer1.xml": _XML + f"Statens vegvesen, side 1", "word/comments.xml": _XML + f"" + 'Unntak: gjelder IKKE gangbruer i tunnel.' + "", "word/footnotes.xml": _XML + f"" + 'separator' + 'Se haandbok N400 kapittel 5.' + "", "word/endnotes.xml": _XML + f"" + 'separator' + 'Kravet ble skjerpet i 2024.' + "", } # --- pptx: a speaker note and a hidden slide -------------------------------- def _slide(title: str, body: str, *, hidden: bool = False) -> str: show = ' show="0"' if hidden else "" return ( _XML + f"" + '' + f"{title}" + "" + f"{body}" + "' + "" + "Post" + "84.1" + "" + "" ) _PPTX_PARTS: dict[str, str | bytes] = { "[Content_Types].xml": _XML + '' + '' + '' + '' + "".join( f'' for n in (1, 2) ) + '' + "", "_rels/.rels": _XML + '' + '', "ppt/_rels/presentation.xml.rels": _XML + '' + '' + '', "ppt/slides/_rels/slide1.xml.rels": _XML + '' + '', "ppt/presentation.xml": _XML + f"" + '' + "", "ppt/slides/slide1.xml": _slide("Prosess 84 Konstruksjoner", "Toleranser er gitt i tabell."), "ppt/slides/slide2.xml": _slide("Utgaatt lysbilde", "Ikke vis dette.", hidden=True), "ppt/notesSlides/notesSlide1.xml": _XML + f"" + "Husk aa nevne at toleranseklassen er skjerpet." + "", } # --- xlsx: a hidden sheet and a formula -------------------------------------- _XLSX_STRINGS = ["Post", "Enhet", "Mengde", "Sum", "Internt", "Kladd"] _XLSX_PARTS: dict[str, str | bytes] = { "[Content_Types].xml": _XML + '' + '' + '' + '' # Declaring the parts is not decoration. Without the sharedStrings # override every `t="s"` cell converts to an EMPTY cell -- the fixture # would have reported four cells lost that the build never lost. + '' + '' + '' + "", "_rels/.rels": _XML + '' + '', "xl/workbook.xml": _XML + f'' + '' + '' + "", "xl/_rels/workbook.xml.rels": _XML + '' + '' + '' # The shared string table is reached through the WORKBOOK's relationship, # not by its path: without this line every `t="s"` cell converts empty and # the fixture reports four cells lost that the build never lost. + '', "xl/sharedStrings.xml": _XML + f'' + "".join(f"{value}" for value in _XLSX_STRINGS) + "", "xl/worksheets/sheet1.xml": _XML + f'' + '01' + '2' + '312' + 'B2*224' + '', "xl/drawings/drawing1.xml": _XML + '' + "" + '' + "", "xl/worksheets/_rels/sheet1.xml.rels": _XML + '' + '', "xl/worksheets/sheet2.xml": _XML + f'' + '5' + "", } # --- odt: a header, a list, an annotation and a picture ---------------------- _ODT_NS = ( 'xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" ' 'xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" ' 'xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" ' 'xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" ' 'xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" ' 'xmlns:xlink="http://www.w3.org/1999/xlink"' ) _ODT_PARTS: dict[str, str | bytes] = { "mimetype": "application/vnd.oasis.opendocument.text", "META-INF/manifest.xml": _XML + '' + '' + '' + "", "content.xml": _XML + f'' + "" + 'Drift av gangbruer' + "Gangbruer inspiseres hvert aar." + "Rekkverk" + "Dekke" + "Se figuren under." + '' + "Sjekk denne mot N400 foer utsendelse." + "" + "" + "Type" + "Gangbru" + "" + "", "styles.xml": _XML + f'' + "" + '' + "Intern arbeidsversjon" + "Vegdirektoratet" + "", } # --- rtf: a picture ---------------------------------------------------------- _RTF = ( r"{\rtf1\ansi\deff0{\fonttbl{\f0 Times New Roman;}}" r"\pard Figur 84-1 viser prinsippet.\par" r"\pard{\pict\pngblip\picw16\pich16 89504e470d0a1a0a}\par" "}" ) # --- html: a picture and a caption ------------------------------------------- _HTML = """ Figur 84-1

Figur 84-1

Prinsippet for toleranseklasser.

Prinsippskisse
KlasseAvvik
A5 mm
""" # --- sts: a citation, a formula, a figure with a caption, a table, a footnote - _STS = """ R7622025 Vegdekker

Dekket skal ha jevnhet etter NS-EN 13036-1:2010.

Kravet regnes som IRI<2.

Maalepunkter langs vegbanen.

KlasseIRI
11,5

Maales hvert 20. meter.

Gjelder ikke gang- og sykkelveger.

""" def main() -> int: written = { "topptekst-og-kommentar.docx": build_zip(_DOCX_PARTS), "notater-og-skjult.pptx": build_zip(_PPTX_PARTS), "skjult-ark-og-formel.xlsx": build_zip(_XLSX_PARTS), "liste-og-bilde.odt": build_zip(_ODT_PARTS), "bilde.rtf": _RTF.encode("latin-1"), "figur.html": _HTML.encode("utf-8"), "sts-rikt.xml": _STS.encode("utf-8"), } for name, payload in written.items(): (CORPUS / name).write_bytes(payload) print(f"wrote {name}") return 0 if __name__ == "__main__": raise SystemExit(main())