Files
hpr-intro-stripper/tests/test_politeness.py
T
Lee Hanken 2bef06d108 Add politeness delay between requests, fix two more marker gaps found by smoke-testing
- config.py/fetch.py: enforce a minimum gap between any requests to HPR's
  servers (fetch._wait_for_politeness_gap()), regardless of which
  function issues them. Not needed for someone who already understands
  HPR's infrastructure, but a real consideration for a future user who
  doesn't -- a sweep makes several requests per episode across thousands
  of episodes.
- markers.json (version 3): found via the same random-sample-then-
  visualize technique used for the earlier hpr4775 fix. hpr2157's era
  apparently used the bare 'HPR episode' rather than 'Hacker Public Radio
  episode', which fell all the way through to a much weaker sibling-
  correlation fallback (3.25s) instead of a proper marker match (now
  15.1s); Whisper tiny mis-hearing 'Today's' as 'To its' on hpr3356 broke
  the same marker a different way (8.0s -> 26.6s). hpr3356 itself is an
  unusual 282-minute special episode that remains correctly flagged for
  manual review even after the fix.
- docs/DESIGN.md: corrected an overstated claim ('retry with backoff')
  that was never actually implemented; documented the real smoke test
  (SIGINT mid-episode, resumed, interrupted again, resumed to
  completion -- no lost work, no stray subprocesses, no ledger
  corruption) and a real full-corpus timing estimate (32.1s/episode
  average on the hardest episode category, so on the order of 1-2 days
  for the full archive, not weeks).
- New regression tests for the politeness delay and both marker fixes.
2026-11-22 11:07:28 +00:00

29 lines
936 B
Python

import time
import unittest
from unittest import mock
from hpr_stripper import config, fetch
class TestPolitenessGap(unittest.TestCase):
def test_enforces_minimum_gap_between_requests(self):
fetch._last_request_at = 0.0
with mock.patch.object(config, "REQUEST_DELAY_SECONDS", 0.05):
start = time.monotonic()
fetch._wait_for_politeness_gap()
fetch._wait_for_politeness_gap()
elapsed = time.monotonic() - start
self.assertGreaterEqual(elapsed, 0.05)
def test_no_wait_once_the_gap_has_already_elapsed(self):
with mock.patch.object(config, "REQUEST_DELAY_SECONDS", 0.01):
fetch._last_request_at = time.monotonic() - 10
start = time.monotonic()
fetch._wait_for_politeness_gap()
elapsed = time.monotonic() - start
self.assertLess(elapsed, 0.01)
if __name__ == "__main__":
unittest.main()