diff --git a/src/wabot/pacing.py b/src/wabot/pacing.py index c32c16b..852ef0d 100644 --- a/src/wabot/pacing.py +++ b/src/wabot/pacing.py @@ -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``.""" diff --git a/tests/unit/test_pacing.py b/tests/unit/test_pacing.py index 5800f62..a4981fe 100644 --- a/tests/unit/test_pacing.py +++ b/tests/unit/test_pacing.py @@ -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()