P-0000: FORMAT.md v1, Prüfskript check_format.py, Viewer-Kopie mit Hinweis bei neuerer Formatversion, Tests format2lint
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
105
skill/tests/format2lint.py
Normal file
105
skill/tests/format2lint.py
Normal file
@ -0,0 +1,105 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Automatische Tests format2lint.1 und .2 (und Zusatzfälle) für skill/scripts/check_format.py.
|
||||
|
||||
Aufruf: python3 skill/tests/format2lint.py (aus dem Projektordner)
|
||||
Die Fehlerfälle entstehen als Kopien der echten ROADMAP.md in einem Temp-Ordner, mit genau einer Änderung.
|
||||
Gibt je Test eine Zeile `- id: ✓|✗ Notiz` aus und endet mit Exit-Code 1, wenn einer ✗ ist.
|
||||
"""
|
||||
import os
|
||||
import re
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
|
||||
ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", ".."))
|
||||
LINT = os.path.join(ROOT, "skill", "scripts", "check_format.py")
|
||||
ergebnisse = []
|
||||
|
||||
|
||||
def lint(ordner):
|
||||
p = subprocess.run([sys.executable, "-I", LINT, os.path.join(ordner, "ROADMAP.md")], capture_output=True, text=True)
|
||||
return p.returncode, p.stdout
|
||||
|
||||
|
||||
def kopie():
|
||||
d = tempfile.mkdtemp(prefix="format2lint-")
|
||||
shutil.copy(os.path.join(ROOT, "ROADMAP.md"), d)
|
||||
shutil.copy(os.path.join(ROOT, "KLICKTESTS.md"), d)
|
||||
shutil.copytree(os.path.join(ROOT, "testberichte"), os.path.join(d, "testberichte"))
|
||||
return d
|
||||
|
||||
|
||||
def ersetze(d, datei, alt, neu, anzahl=1):
|
||||
p = os.path.join(d, datei)
|
||||
s = open(p, encoding="utf-8").read()
|
||||
assert s.count(alt) >= 1, f"Testaufbau: '{alt[:40]}' nicht gefunden"
|
||||
open(p, "w", encoding="utf-8").write(s.replace(alt, neu, anzahl))
|
||||
|
||||
|
||||
def zeile_von(d, datei, teil):
|
||||
for i, l in enumerate(open(os.path.join(d, datei), encoding="utf-8").read().split("\n"), 1):
|
||||
if teil in l:
|
||||
return i
|
||||
raise AssertionError(f"Testaufbau: Zeile mit '{teil}' fehlt")
|
||||
|
||||
|
||||
def melde(tid, ok, notiz):
|
||||
ergebnisse.append(ok)
|
||||
print(f"- {tid}: {'✓' if ok else '✗'} {notiz}")
|
||||
|
||||
|
||||
def fehlerfall(tid, beschreibung, aender, datei, suchteil, grund):
|
||||
d = kopie()
|
||||
try:
|
||||
aender(d)
|
||||
z = zeile_von(d, datei, suchteil)
|
||||
code, out = lint(d)
|
||||
erwartet = f"{datei}:{z}: FEHLER"
|
||||
ok = code == 1 and erwartet in out and grund in out
|
||||
melde(tid, ok, f"{beschreibung}: Exit {code}, {'Zeile ' + str(z) + ' und Grund gemeldet' if ok else 'Meldung weicht ab: ' + repr(out[-300:])}")
|
||||
finally:
|
||||
shutil.rmtree(d, ignore_errors=True)
|
||||
|
||||
|
||||
def main():
|
||||
# .1 echte Datei
|
||||
d = kopie()
|
||||
code, out = lint(d)
|
||||
melde("format2lint.1", code == 0 and "OK" in out and "Format: 1" in out and "Projekt-ID: P-0000" in out,
|
||||
f"echte ROADMAP.md: Exit {code}, Formatversion und Projekt-ID erkannt" if code == 0 else out[-300:])
|
||||
shutil.rmtree(d, ignore_errors=True)
|
||||
|
||||
# .2 Fehlerfälle
|
||||
fehlerfall("format2lint.2a", "doppelte ID", lambda d: ersetze(d, "ROADMAP.md", "| #1002 |", "| #1001 |"),
|
||||
"ROADMAP.md", "| #1001 | Plugin-Paket", "doppelte ID #1001")
|
||||
fehlerfall("format2lint.2b", "Verweis ins Leere", lambda d: ersetze(d, "ROADMAP.md", "Tests `projekt2sync.1–.3`. → #1015", "Tests `projekt2sync.1–.3`. → #1999"),
|
||||
"ROADMAP.md", "→ #1999", "#1999 ist nirgends definiert")
|
||||
fehlerfall("format2lint.2c", "fehlende Projekt-ID", lambda d: ersetze(d, "ROADMAP.md", "Projekt-ID: P-0000 · ", ""),
|
||||
"ROADMAP.md", "Stand: 2026-11-03", "Projekt-ID fehlt")
|
||||
fehlerfall("format2lint.2d", "kaputte Stand-Zeile", lambda d: ersetze(d, "ROADMAP.md", "| Bestand | ✓ | In echter Installation geprüft (bestand2plugin.1)", "| Bestand | fertig | In echter Installation geprüft (bestand2plugin.1)"),
|
||||
"ROADMAP.md", "| fertig |", "beginnt nicht mit ✓")
|
||||
fehlerfall("format2lint.2e", "falsches Datum im Erledigt-Block", lambda d: ersetze(d, "ROADMAP.md", "**Erledigt am 03.11.2026:**", "**Erledigt am 2026-11-03:**"),
|
||||
"ROADMAP.md", "**Erledigt am 2026-11-03:**", "Datum muss TT.MM.JJJJ sein")
|
||||
fehlerfall("format2lint.2f", "Zelle mit senkrechtem Strich", lambda d: ersetze(d, "ROADMAP.md", "Plugin-Paket (Marketplace,", "Plugin-Paket | (Marketplace,"),
|
||||
"ROADMAP.md", "Plugin-Paket | (Marketplace,", "Zellen")
|
||||
fehlerfall("format2lint.2g", "Klicktest-Zeile mit falscher Art", lambda d: ersetze(d, "KLICKTESTS.md", "| format2lint.1 | Prüfskript auf die `ROADMAP.md` dieses Projekts anwenden | Ausgabe OK, Formatversion und Projekt-ID werden erkannt | auto |", "| format2lint.1 | Prüfskript auf die `ROADMAP.md` dieses Projekts anwenden | Ausgabe OK, Formatversion und Projekt-ID werden erkannt | robot |"),
|
||||
"KLICKTESTS.md", "| robot |", "weder manuell noch auto")
|
||||
|
||||
# Zusatz: Format 0 und zu neue Version
|
||||
d = kopie()
|
||||
ersetze(d, "ROADMAP.md", " · Format: 1", "")
|
||||
code, out = lint(d)
|
||||
melde("format2lint.2h", code == 0 and "Altformat (Format 0)" in out, f"ohne Format-Zeile: Exit {code}, Hinweis auf Format 0")
|
||||
shutil.rmtree(d, ignore_errors=True)
|
||||
d = kopie()
|
||||
ersetze(d, "ROADMAP.md", "Format: 1", "Format: 2")
|
||||
code, out = lint(d)
|
||||
melde("format2lint.2i", code == 2 and "neuer als ich verstehe" in out, f"Format 2: Exit {code}, Hinweis 'neuer als ich verstehe'")
|
||||
shutil.rmtree(d, ignore_errors=True)
|
||||
|
||||
sys.exit(0 if all(ergebnisse) else 1)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user