39 lines
1.1 KiB
Python
39 lines
1.1 KiB
Python
"""Tests for cht.stream.tracker — RecordingTracker."""
|
|
|
|
import time
|
|
from pathlib import Path
|
|
from unittest.mock import patch, MagicMock
|
|
|
|
import pytest
|
|
|
|
from cht.stream.tracker import RecordingTracker
|
|
|
|
|
|
class TestRecordingTracker:
|
|
def test_initial_duration_is_zero(self, tmp_path):
|
|
tracker = RecordingTracker(tmp_path / "rec.ts")
|
|
assert tracker.duration == 0.0
|
|
|
|
def test_callback_called_on_update(self, tmp_path):
|
|
rec = tmp_path / "rec.ts"
|
|
rec.write_bytes(b"\x00" * 100_000)
|
|
|
|
cb = MagicMock()
|
|
tracker = RecordingTracker(rec, on_duration_update=cb)
|
|
|
|
with patch.object(tracker, "_probe_duration", return_value=10.0):
|
|
tracker.start()
|
|
time.sleep(3)
|
|
tracker.stop()
|
|
|
|
cb.assert_called()
|
|
assert cb.call_args[0][0] > 0
|
|
|
|
def test_no_callback_if_file_missing(self, tmp_path):
|
|
cb = MagicMock()
|
|
tracker = RecordingTracker(tmp_path / "nonexistent.ts", on_duration_update=cb)
|
|
tracker.start()
|
|
time.sleep(3)
|
|
tracker.stop()
|
|
cb.assert_not_called()
|