Download tests/test_ab_test.py from PYTHAI/mindXtrain: direct link, hf CLI and curl.
- Browser
- Download file 845 Bytes
-
https://huggingface.co/PYTHAI/mindXtrain/resolve/main/tests/test_ab_test.py
- Command line
-
hf download hf://PYTHAI/mindXtrain/tests/test_ab_test.py
-
curl -L -o test_ab_test.py https://huggingface.co/PYTHAI/mindXtrain/resolve/main/tests/test_ab_test.py
845 Bytes
| """A/B traffic Splitter.""" | |
| from __future__ import annotations | |
| from mindxtrain.deploy.ab_test import AbConfig, Splitter | |
| def test_zero_canary_pct_always_live(): | |
| s = Splitter(AbConfig(canary_pct=0.0)) | |
| for i in range(100): | |
| assert s.pick(f"r-{i}") == "live" | |
| def test_full_canary_pct_always_canary(): | |
| s = Splitter(AbConfig(canary_pct=1.0)) | |
| for i in range(100): | |
| assert s.pick(f"r-{i}") == "canary" | |
| def test_deterministic_per_request_id(): | |
| s = Splitter(AbConfig(canary_pct=0.5)) | |
| a = s.pick("request-42") | |
| b = s.pick("request-42") | |
| assert a == b | |
| def test_split_distribution_roughly_canary_pct(): | |
| s = Splitter(AbConfig(canary_pct=0.2)) | |
| n = 2000 | |
| canary = sum(1 for i in range(n) if s.pick(f"req-{i}") == "canary") | |
| # 20% +/- a generous band. | |
| assert 0.10 * n <= canary <= 0.30 * n | |