#!/usr/bin/env python3 """R-325: hub_copy_gate.check_drift accepts the controller gate IMPORTING the shared stem list. Cases: a matching literal (ok), a diverged literal (drift), the import with no literal (ok — the destination), an import that exists only in a comment (drift — the label without the fact), an import beside a stale literal (drift), and an absent file (inconclusive, never a pass). Run: python3 scripts/test_hub_copy_drift.py """ import os import sys import tempfile sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) import hub_copy_gate as g # noqa: E402 from customer_copy_vocab import RETRIEVAL_STEMS # noqa: E402 lit = "STEMS = [%s]\n" % ", ".join('"%s"' % x for x in RETRIEVAL_STEMS) imp = "sys.path.insert(0, VOCAB_DIR)\nfrom customer_copy_vocab import RETRIEVAL_STEMS as STEMS # noqa\n" CASES = [ ("matching-literal", "import re\n" + lit, "ok"), ("diverged-literal", "import re\nSTEMS = [\"visszaallithat\"]\n", "drift"), ("imports-shared", "import re\n" + imp, "ok"), ("import-in-comment-only", "import re\n# from customer_copy_vocab import RETRIEVAL_STEMS\n", "drift"), ("import-beside-stale-literal", imp + "STEMS = [\"x\"]\n", "drift"), ] fails = 0 tmp = tempfile.mkdtemp(prefix="r325-") for name, body, want in CASES: p = os.path.join(tmp, name + ".py") with open(p, "w", encoding="utf-8") as f: f.write(body) got, msg = g.check_drift(p) ok = got == want fails += not ok print(" %s %-28s want %-12s got %s" % ("ok " if ok else "FAIL", name, want, got)) got, _ = g.check_drift(os.path.join(tmp, "absent.py")) if got != "inconclusive": fails += 1 print(" FAIL absent file -> %s, want inconclusive" % got) else: print(" ok absent file want inconclusive got inconclusive") print("test_hub_copy_drift: %s" % ("FAILED" if fails else "OK")) sys.exit(1 if fails else 0)