restructure and test, pure python and rust transport both _work_
This commit is contained in:
@@ -10,17 +10,19 @@ from cht.stream.tracker import RecordingTracker
|
||||
|
||||
|
||||
class TestRecordingTracker:
|
||||
def test_initial_duration_is_zero(self, tmp_path):
|
||||
tracker = RecordingTracker(tmp_path / "rec.ts")
|
||||
def test_initial_duration_is_zero(self):
|
||||
tracker = RecordingTracker(get_segments=lambda: [])
|
||||
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)
|
||||
seg = tmp_path / "rec.mp4"
|
||||
seg.write_bytes(b"\x00" * 100_000)
|
||||
|
||||
cb = MagicMock()
|
||||
tracker = RecordingTracker(rec, on_duration_update=cb)
|
||||
|
||||
tracker = RecordingTracker(
|
||||
get_segments=lambda: [seg],
|
||||
on_duration_update=cb,
|
||||
)
|
||||
with patch.object(tracker, "_probe_duration", return_value=10.0):
|
||||
tracker.start()
|
||||
time.sleep(3)
|
||||
@@ -29,10 +31,44 @@ class TestRecordingTracker:
|
||||
cb.assert_called()
|
||||
assert cb.call_args[0][0] > 0
|
||||
|
||||
def test_no_callback_if_file_missing(self, tmp_path):
|
||||
def test_no_callback_if_no_segments(self):
|
||||
cb = MagicMock()
|
||||
tracker = RecordingTracker(tmp_path / "nonexistent.ts", on_duration_update=cb)
|
||||
tracker = RecordingTracker(get_segments=lambda: [], on_duration_update=cb)
|
||||
tracker.start()
|
||||
time.sleep(3)
|
||||
tracker.stop()
|
||||
cb.assert_not_called()
|
||||
|
||||
def test_no_callback_if_file_missing(self, tmp_path):
|
||||
cb = MagicMock()
|
||||
tracker = RecordingTracker(
|
||||
get_segments=lambda: [tmp_path / "nonexistent.mp4"],
|
||||
on_duration_update=cb,
|
||||
)
|
||||
tracker.start()
|
||||
time.sleep(3)
|
||||
tracker.stop()
|
||||
cb.assert_not_called()
|
||||
|
||||
def test_duration_only_increases(self, tmp_path):
|
||||
seg = tmp_path / "rec.mp4"
|
||||
seg.write_bytes(b"\x00" * 100_000)
|
||||
durations = []
|
||||
|
||||
def on_update(d):
|
||||
durations.append(d)
|
||||
|
||||
probe_values = iter([5.0, 3.0, 7.0]) # 3.0 is a regression — should be ignored
|
||||
|
||||
tracker = RecordingTracker(
|
||||
get_segments=lambda: [seg],
|
||||
on_duration_update=on_update,
|
||||
)
|
||||
with patch.object(tracker, "_probe_duration", side_effect=probe_values):
|
||||
tracker.start()
|
||||
time.sleep(7)
|
||||
tracker.stop()
|
||||
|
||||
# Duration should never go backwards
|
||||
for i in range(1, len(durations)):
|
||||
assert durations[i] >= durations[i - 1], "Duration regressed"
|
||||
|
||||
Reference in New Issue
Block a user