mirror of
https://github.com/kuhyx/testsAndMisc-archive.git
synced 2026-07-04 14:23:04 +02:00
- Rename PYTHON/ to python_pkg/ (fix N999 uppercase folder) - Rename camelCase folders to snake_case: - randomJPG -> random_jpg - tagDivider -> tag_divider - downloadCats -> download_cats - keyboardCoop -> keyboard_coop - extractLinks -> extract_links - scapeWebsite -> scrape_website - Rename camelCase files: - generateJpeg.py -> generate_jpeg.py - tagDivider.py -> tag_divider.py - Rename poker-modifier-app to poker_modifier_app (fix INP001) - Add __init__.py to poker_modifier_app - Replace random module with secrets.SystemRandom (fix S311) - Fix S110 try-except-pass with contextlib.suppress - Update all imports and config references
27 lines
746 B
Python
27 lines
746 B
Python
"""Tests for utility functions."""
|
|
|
|
import pytest
|
|
|
|
from python_pkg.lichess_bot.utils import backoff_sleep
|
|
|
|
|
|
def test_backoff_sleep_increments_and_caps(monkeypatch: pytest.MonkeyPatch) -> None:
|
|
"""Test that backoff sleep increments and respects the cap."""
|
|
slept: list[float] = []
|
|
|
|
def fake_sleep(sec: float) -> None:
|
|
slept.append(sec)
|
|
|
|
monkeypatch.setattr("time.sleep", fake_sleep)
|
|
|
|
b = 0
|
|
b = backoff_sleep(b, base=0.1, cap=0.3)
|
|
b = backoff_sleep(b, base=0.1, cap=0.3)
|
|
b = backoff_sleep(b, base=0.1, cap=0.3)
|
|
assert b >= 1
|
|
assert len(slept) == 3
|
|
# Expected sleep values: first=0.1, second=0.2, third=0.3 (capped)
|
|
assert slept[0] == 0.1
|
|
assert slept[1] == 0.2
|
|
assert slept[2] == 0.3
|