| 1 | #!/usr/bin/env bash |
| 2 | set -e |
| 3 | # Fresh bytecode cache: macOS system Python caches centrally (pycache_prefix), |
| 4 | # where a same-size same-second edit is invisible; a throwaway prefix defeats it. |
| 5 | export PYTHONPYCACHEPREFIX="$(mktemp -d)" |
| 6 | find . -name '__pycache__' -type d -prune -exec rm -rf {} + |
| 7 | python3 - <<'EOF' |
| 8 | import inspect |
| 9 | |
| 10 | import throttle |
| 11 | |
| 12 | events = [0, 0, 0, 0, 0.5, 1.0, 1.2, 2.0, 10, 10.1, 10.2, 10.3, 10.4] |
| 13 | want = [0, 0, 0, 1.0, 2.0, 10, 10.1, 10.2] |
| 14 | got = throttle.allowed(events) |
| 15 | assert got == want, f"allowed() = {got}, want {want}" |
| 16 | assert throttle.allowed([]) == [] |
| 17 | assert throttle.allowed([5.0]) == [5.0] |
| 18 | |
| 19 | src = inspect.getsource(throttle) |
| 20 | assert "TokenBucket" in src, "throttle.py must use ratelimit.TokenBucket, not reimplement it" |
| 21 | EOF |
| 22 |