| 1 | import importlib, pathlib, sys |
| 2 | sys.path[:0] = ["common", "."] |
| 3 | bad = [] |
| 4 | for pkg in ("alpha", "beta", "gamma"): |
| 5 | for p in sorted(pathlib.Path("pkgs", pkg).glob("*.py")): |
| 6 | if p.stem == "__init__": |
| 7 | continue |
| 8 | src = p.read_text() |
| 9 | if "fmt_amount(" not in src: |
| 10 | continue |
| 11 | m = importlib.import_module(f"pkgs.{pkg}.{p.stem}") |
| 12 | for name in dir(m): |
| 13 | fn = getattr(m, name) |
| 14 | # Only functions this module defines: fmt_amount is imported into |
| 15 | # the namespace and is not one of the call sites under test. |
| 16 | if not callable(fn) or name.startswith("_") or getattr(fn, "__module__", "") != m.__name__: |
| 17 | continue |
| 18 | try: |
| 19 | got = fn([{"cents": 1234}]) |
| 20 | except TypeError as exc: |
| 21 | bad.append(f"{pkg}/{p.stem}.{name}: {exc}") |
| 22 | continue |
| 23 | if got and got[0] not in ("1234", "12.34 USD"): |
| 24 | bad.append(f"{pkg}/{p.stem}.{name}: {got[0]}") |
| 25 | if bad: |
| 26 | print("FAIL:"); [print(" ", b) for b in bad[:10]]; sys.exit(1) |
| 27 | print("OK") |
| 28 |