test: assert pacing actually varies; document NoPacing as policy base

This commit is contained in:
Mathew Sir Guest the best 2026-07-07 21:37:33 -06:00
parent 25aaa5d4da
commit f5e358393d
2 changed files with 12 additions and 1 deletions

@ -11,7 +11,12 @@ import random
class NoPacing:
"""Instant actions, exact clicks."""
"""Instant actions, exact clicks.
Also the base class for custom pacing policies; do not use
``isinstance(x, NoPacing)`` to test whether pacing is disabled
HumanPacing subclasses this.
"""
def delay(self, action: str) -> float:
"""Seconds to sleep before performing ``action``."""

@ -24,15 +24,21 @@ class TestHumanPacing:
def test_unknown_action_has_no_delay(self):
assert HumanPacing().delay("unknown-action") == 0.0
def test_delays_actually_vary(self):
assert len({HumanPacing().delay("text") for _ in range(50)}) > 1
def test_click_offset_stays_inside_element(self):
p = HumanPacing()
offsets = []
for _ in range(200):
offset = p.click_offset(100, 40)
assert offset is not None
offsets.append(offset)
x, y = offset
# offsets are measured from the element CENTER (selenium 4)
assert -49 <= x <= 49
assert -19 <= y <= 19
assert any(o != (0, 0) for o in offsets)
def test_tiny_elements_get_plain_click(self):
p = HumanPacing()