"""Tests for the filename clock in isrweb/audiofile.py. Recordings are named for their *start* time, and that name is the only reliable time anchor the archive has — mtime drifts to the last write. """ from isrweb.audiofile import _cut_filename, _recording_start def test_recording_start_parses_standard_name(): from datetime import datetime assert _recording_start("20260523_220000") == datetime(2026, 5, 23, 22, 0, 0) def test_recording_start_rejects_nonstandard_name(): assert _recording_start("radio1_20260523") is None assert _recording_start("notes") is None def test_cut_filename_uses_wall_clock_span(): # Recording started 22:00:00; cut covers 22:31:30 → 22:32:30. name = _cut_filename("20260523_220000", ".flac", 1890, 1950) assert name == "20260523_22-31-30_22-32-30.flac" def test_cut_filename_rolls_over_the_hour(): name = _cut_filename("20260523_220000", ".wav", 3590, 3661) assert name == "20260523_22-59-50_23-01-01.wav" def test_cut_filename_falls_back_for_nonstandard_name(): name = _cut_filename("mixtape", ".mp3", 740, 750.4) assert name == "mixtape_cut_740s-750s.mp3"