Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
Download tests/test_rate_limit.py from CohereLabs/cohere-parse: direct link, hf CLI and curl.
- Browser
- Download file 714 Bytes
-
https://huggingface.co/spaces/CohereLabs/cohere-parse/resolve/main/tests/test_rate_limit.py
- Command line
-
hf download hf://spaces/CohereLabs/cohere-parse/tests/test_rate_limit.py
-
curl -L -o test_rate_limit.py https://huggingface.co/spaces/CohereLabs/cohere-parse/resolve/main/tests/test_rate_limit.py
714 Bytes
| from __future__ import annotations | |
| from rate_limit import RateLimiter | |
| def test_limits_each_key_within_window() -> None: | |
| limiter = RateLimiter(limit=2, window_seconds=10) | |
| assert limiter.take("client", now=0) == (True, 0) | |
| assert limiter.take("client", now=1) == (True, 0) | |
| allowed, retry_after = limiter.take("client", now=2) | |
| assert not allowed | |
| assert retry_after == 8 | |
| assert limiter.take("other-client", now=2) == (True, 0) | |
| def test_resets_after_window() -> None: | |
| limiter = RateLimiter(limit=1, window_seconds=10) | |
| assert limiter.take("client", now=0) == (True, 0) | |
| assert limiter.take("client", now=5)[0] is False | |
| assert limiter.take("client", now=10) == (True, 0) | |