MCPcopy Index your code
hub / github.com/Breakthrough/PySceneDetect / test_time_invariants

Method test_time_invariants

tests/test_video_stream.py:173–196  ·  view source on GitHub ↗

Validate the `frame_number`, `position`, and `position_ms` properties.

(
        self, vs_type: ty.Callable[..., VideoStream], test_video: VideoParameters
    )

Source from the content-addressed store, hash-verified

171 assert stream.frame_number == 1
172
173 def test_time_invariants(
174 self, vs_type: ty.Callable[..., VideoStream], test_video: VideoParameters
175 ):
176 """Validate the `frame_number`, `position`, and `position_ms` properties."""
177 stream = vs_type(test_video.path)
178 # The video starts "before" the first frame, with everything set to zero.
179 assert stream.frame_number == 0
180 assert stream.position == stream.base_timecode
181 assert stream.position_ms == pytest.approx(0.0, abs=TIME_TOLERANCE_MS)
182 # Read the first frame (frame number 1).
183 assert stream.read() is not False
184 assert stream.frame_number == 1
185 # The `position`/`position_ms` properties represent the presentation time, so they
186 # should still be zero for the first frame.
187 assert stream.position == stream.base_timecode
188 assert stream.position_ms == pytest.approx(0.0, abs=TIME_TOLERANCE_MS)
189 # Test that the invariants hold for the first few frames.
190 for i in range(2, 10):
191 assert stream.read() is not False
192 assert stream.frame_number == i
193 assert stream.position == stream.base_timecode + (i - 1)
194 assert stream.position_ms == pytest.approx(
195 1000.0 * (i - 1) / float(stream.frame_rate), abs=TIME_TOLERANCE_MS
196 )
197
198 def test_reset(self, vs_type: ty.Callable[..., VideoStream], test_video: VideoParameters):
199 """Test `reset()` functions as expected."""

Callers

nothing calls this directly

Calls 1

readMethod · 0.45

Tested by

no test coverage detected