1
0
Files
Rihards Gailums 9156830902 Pārbaudītās sasaistes (sasaistes/<VPK ID>.xml), shēma sasaistes-0.1.xsd un validators
Pilotiestādes: Valsts meža dienests (pakalpojums -> darbs, sistēma, informācijas resurss; sistēma -> resurss) un Latvijas
Nacionālā bibliotēka. Katru saiti pārbaudīja Claude pret nolikuma formulējumu un VIRSIS aprakstu; pierādījuma līmenis
direct vai broad.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016679RwmHsuTFfxt26wP6rk
2026-10-29 18:58:41 +00:00

42 lines
1.6 KiB
Python

"""Negatīvie testi validate_links.py: katrs bojājums jāpamana."""
import re
import shutil
import sys
import tempfile
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parent))
import validate_links as V # noqa: E402
SRC = sorted((V.ROOT / "sasaistes").glob("*.xml"))[0]
TEXT = SRC.read_text(encoding="utf-8")
CASES = [
("saite atkārtojas", lambda s: s.replace("</Links>", re.search(r" <Link [^\n]*\n", s).group(0) + "</Links>")),
("nezināma attiecība", lambda s: re.sub(r'relation="\w+"', 'relation="likes"', s, count=1)),
("attiecība neder galiem", lambda s: re.sub(r'relation="\w+"', 'relation="same_as"', s, count=1)),
("nav avota", lambda s: re.sub(r' source="[^"]*"', "", s, count=1)),
("datnes nosaukums neatbilst iestādei", None),
("darbs no citas iestādes", lambda s: re.sub(r'to="fdk:([FDK])-\d{2}-\d{4}-', r'to="fdk:\1-99-9999-', s, count=1)
if "fdk:" in s else s.replace('institution="', 'institution="9', 0)),
]
fail = 0
errs, _ = V.check(V.ROOT / "sasaistes")
if errs:
print("FAIL pašas datnes nav derīgas:", errs[:3])
fail += 1
for title, mutate in CASES:
d = Path(tempfile.mkdtemp())
if mutate is None:
shutil.copy(SRC, d / "00-0000.xml")
else:
bad = mutate(TEXT)
if bad == TEXT:
print("SKIP " + title)
continue
(d / SRC.name).write_text(bad, encoding="utf-8")
ok = bool(V.check(d)[0])
print(("PASS " if ok else "FAIL ") + title)
fail += not ok
print("Visi testi izdevās" if not fail else "Ir neizdevušies testi")
sys.exit(1 if fail else 0)