You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1.8 KiB
50 lines
1.8 KiB
from decimal import Decimal |
|
|
|
import pytest |
|
|
|
from voice_transcriptor.services.chunking import ( |
|
calculate_chunk_boundaries, |
|
source_timestamp, |
|
total_chunk_duration, |
|
) |
|
|
|
|
|
@pytest.mark.parametrize( |
|
("total", "chunk", "overlap", "expected"), |
|
[ |
|
("600", "900", "15", [("0", "600")]), |
|
("900", "900", "15", [("0", "900")]), |
|
("1800", "900", "15", [("0", "900"), ("885", "1785"), ("1770", "1800")]), |
|
("901.25", "900", "15", [("0", "900"), ("885", "901.25")]), |
|
("1800", "900", "0", [("0", "900"), ("900", "1800")]), |
|
], |
|
) |
|
def test_chunk_boundaries_keep_context_and_exact_final_end( |
|
total: str, chunk: str, overlap: str, expected: list[tuple[str, str]] |
|
) -> None: |
|
boundaries = calculate_chunk_boundaries(total, chunk, overlap) |
|
assert [(str(item.start_seconds), str(item.end_seconds)) for item in boundaries] == expected |
|
|
|
|
|
def test_overlap_is_included_in_total_generated_audio_duration() -> None: |
|
boundaries = calculate_chunk_boundaries("1800", "900", "15") |
|
assert total_chunk_duration(boundaries) == Decimal("1830") |
|
|
|
|
|
def test_local_timestamp_maps_to_exact_source_offset() -> None: |
|
boundary = calculate_chunk_boundaries("1800", "900", "15")[1] |
|
assert source_timestamp(boundary, "12.5") == Decimal("897.5") |
|
|
|
|
|
def test_many_hour_recording_ends_exactly_at_source_duration() -> None: |
|
boundaries = calculate_chunk_boundaries("28800.125", "900", "15") |
|
assert boundaries[-1].end_seconds == Decimal("28800.125") |
|
|
|
|
|
@pytest.mark.parametrize( |
|
("total", "chunk", "overlap"), |
|
[("0", "900", "15"), ("10", "0", "0"), ("10", "10", "10"), ("10", "10", "-1")], |
|
) |
|
def test_invalid_chunk_configuration_is_rejected(total: str, chunk: str, overlap: str) -> None: |
|
with pytest.raises(ValueError): |
|
calculate_chunk_boundaries(total, chunk, overlap)
|
|
|