Files
VoiceStudio/tests/test_longform_progress_weights.py
debpalash fc47cb40c2 fix: review findings on the #4372–#4389 batch
- insertionSlot: falls back when the next segment has no finite start, and
  rounds a custom threshold to milliseconds before comparing (#4389).
- New test modules resolve app code at test time (#4380, #4382, #4383).
2026-11-23 13:05:01 +05:30

30 lines
934 B
Python

"""Long-book progress must remain cheap after many chapters finish."""
import pytest
def test_progress_does_not_rescan_completed_chapters(monkeypatch):
import importlib
RenderProgress = importlib.import_module("services.longform_progress").RenderProgress # resolved at test time
progress = RenderProgress([10] * 500)
for index in range(400):
progress.finish_chapter(index)
# Finishing twice and delayed chunk notifications must leave the total alone.
progress.finish_chapter(0)
progress.chunk(0, 1, 1)
progress.chunk(400, 1, 2, cached=True)
original = progress._weights_at
reads = []
def counted(index):
reads.append(index)
return original(index)
monkeypatch.setattr(progress, "_weights_at", counted)
assert progress.fraction() == pytest.approx(400.5 / 500)
assert progress.remaining_units() == pytest.approx(995)
assert reads == [400, 400]