| 1 | import importlib, pathlib, sys |
| 2 | sys.path.insert(0, ".") |
| 3 | fail = [] |
| 4 | |
| 5 | from svc.query.filters import build_filter |
| 6 | if build_filter("x=1", ["a=2", "b=3"], "any") != "x=1 AND (a=2 OR b=3)": |
| 7 | fail.append("query: OR clauses are not parenthesised") |
| 8 | if build_filter("x=1", ["a=2", "b=3"], "all") != "x=1 AND (a=2 AND b=3)": |
| 9 | fail.append("query: AND clauses are not parenthesised") |
| 10 | if build_filter("x=1", ["a=2"], "any") != "x=1 AND a=2": |
| 11 | fail.append("query: a single clause must not be parenthesised") |
| 12 | |
| 13 | from svc.format.human import humanise |
| 14 | for n, want in ((1250, "1.3k"), (1234, "1.2k"), (3450000, "3.5M"), (999, "999")): |
| 15 | if humanise(n) != want: |
| 16 | fail.append(f"format: humanise({n}) = {humanise(n)!r}, want {want!r}") |
| 17 | |
| 18 | expected = [] |
| 19 | for pkg in ("query", "format"): |
| 20 | for p in sorted(pathlib.Path("svc", pkg).glob("*.py")): |
| 21 | if p.stem == "__init__": |
| 22 | continue |
| 23 | m = importlib.import_module(f"svc.{pkg}.{p.stem}") |
| 24 | for name in sorted(dir(m)): |
| 25 | fn = getattr(m, name) |
| 26 | if callable(fn) and not name.startswith("_") and getattr(fn, "__module__", "") == m.__name__: |
| 27 | expected.append(f"- {pkg}.{name}") |
| 28 | expected = sorted(set(expected)) |
| 29 | got = sorted(l.strip() for l in pathlib.Path("docs/api.md").read_text().splitlines() if l.startswith("- ")) |
| 30 | if got != expected: |
| 31 | missing = [e for e in expected if e not in got] |
| 32 | extra = [g for g in got if g not in expected] |
| 33 | fail.append(f"docs: manifest is stale (missing {len(missing)}, extra {len(extra)})") |
| 34 | |
| 35 | if fail: |
| 36 | print("FAIL:"); [print(" ", f) for f in fail]; sys.exit(1) |
| 37 | print("OK") |
| 38 |