import io, os, sys, subprocess, shutil ROOT = "/mnt/5_hdd/felhom.eu/git/app-catalog-felhom.eu" sys.path.insert(0, os.path.join(ROOT, "scripts")) import test_gate_decoys as T CG = os.path.join(ROOT, "scripts", "check-copy-i18n.py") GV = os.path.join(ROOT, "scripts", "check-guide-version.py") P = [ ("R1 guide strings counted as copy", CG, ' g = ai.get("guide") if isinstance(ai.get("guide"), dict) else {}', ' g = {}'), ("R2 overlay accepts guide", CG, '"prerequisites",\n "guide"):', '"prerequisites"):'), ("R3 checked_version refused in overlay", CG, ' if k == "checked_version":', ' if False:'), ("R4 empty steps refused", CG, ' if not isinstance(steps, list) or not steps:', ' if not isinstance(steps, list):'), ("R5 faq answer required", CG, ' if not (isinstance(qa.get(k), str) and qa.get(k).strip()):', ' if not isinstance(qa.get(k), (str, type(None))):'), ("R6 quoted version", CG, ' if cv is not None and not isinstance(cv, str):', ' if False:'), ("R7 section/faq counts", CG, ' if len(lst) != len(hu_lst):', ' if len(lst) < len(hu_lst):'), ("R8 step counts", CG, ' if len(st) != hu_n:', ' if len(st) > hu_n + 99:'), ("R9 inert English guide", CG, ' if not isinstance(hu_g, dict):\n errs.append', ' if False:\n errs.append'), ("R10 source deny-list", CG, ' for name in SOURCE_DENYLIST:', ' for name in []:'), ("R11 WARN on a moved image", GV, ' if cv in cands:', ' if cv:'), ("R12 the app service, not a sidecar", GV, ' cands = [tags[s] for s in main_svcs] or list(tags.values())', ' cands = list(tags.values())'), ] for name, path, old, new in P: src = io.open(path, encoding="utf-8").read() assert src.count(old) == 1, name io.open(path, "w", encoding="utf-8").write(src.replace(old, new)) try: T.fails[:] = [] clone = T.make_clone() import contextlib buf = io.StringIO() with contextlib.redirect_stdout(buf): T.guide_cases(clone) shutil.rmtree(clone, ignore_errors=True) names = [f.split(":")[0] + ":" + f.split(":")[1] for f in T.fails] print("%-42s -> %d case(s) FAIL: %s" % (name, len(T.fails), "; ".join(n.strip() for n in names))) finally: io.open(path, "w", encoding="utf-8").write(src)