Add pydocstyle to the ruff rules (#52136)

Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
Signed-off-by: Harry Mellor <hej.mellor@gmail.com>
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Harry Mellor
2026-09-16 16:44:29 +00:00
committed by GitHub
co-authored by Claude Opus 5
parent 804e5377aa
commit 8c1557a79c
2002 changed files with 15024 additions and 14269 deletions
+14 -8
View File
@@ -54,7 +54,8 @@ def test_audio_media_io_load_base64(dummy_audio_bytes):
def test_audio_media_io_load_base64_rejects_malformed(dummy_audio_bytes):
"""Malformed base64 must surface as a ValueError so the server answers 400.
Without strict decoding the bad characters are dropped, the garbage reaches
libsndfile, and the client gets a 500 instead."""
libsndfile, and the client gets a 500 instead.
"""
encoded = base64.b64encode(dummy_audio_bytes).decode("utf-8")
malformed = encoded[:8] + "!!!@@@###" + encoded[8:]
@@ -133,7 +134,8 @@ def test_small_file_passes_memory_guard():
def test_memory_guard_rejects_large_allocation():
"""A file whose frames*channels*4 exceeds the byte limit must be
rejected before allocating the buffer."""
rejected before allocating the buffer.
"""
# 100_000 frames * 8 channels * 4 bytes = 3.2 MB
payload = _make_flac_bytes(frames=100_000, channels=8, samplerate=48000)
# Set limit to 1 MiB — should reject
@@ -148,7 +150,8 @@ def test_memory_guard_rejects_large_allocation():
def test_forged_samplerate_rejected_by_memory_guard():
"""The PoC scenario: high sample rate fools the duration guard but
the memory guard catches the large frame*channel allocation."""
the memory guard catches the large frame*channel allocation.
"""
# Forged high sample rate: 655350 Hz, 8 channels, 1M frames
# Duration guard sees: 1_000_000 / 655_350 = 1.5s → passes
# Memory: 1_000_000 * 8 * 4 = 32 MB
@@ -209,7 +212,8 @@ def test_load_audio_unknown_backend_rejected(dummy_audio_bytes):
def test_load_audio_auto_falls_back_without_torchcodec(dummy_audio_bytes):
"""`auto` must fall back to the soundfile → PyAV chain when torchcodec
is not importable."""
is not importable.
"""
ref_audio, ref_sr = load_audio_soundfile(BytesIO(dummy_audio_bytes), sr=None)
with patch.object(audio_module, "load_audio_torchcodec", side_effect=ImportError):
audio, sr = load_audio(BytesIO(dummy_audio_bytes), sr=None, backend="auto")
@@ -218,8 +222,9 @@ def test_load_audio_auto_falls_back_without_torchcodec(dummy_audio_bytes):
def test_load_audio_auto_falls_back_without_ffmpeg(dummy_audio_bytes):
"""torchcodec installed but system ffmpeg missing (`AudioDecoder is None`)
must surface as ImportError so `auto` falls back to soundfile → PyAV."""
"""Torchcodec installed but system ffmpeg missing (`AudioDecoder is None`)
must surface as ImportError so `auto` falls back to soundfile → PyAV.
"""
ref_audio, ref_sr = load_audio_soundfile(BytesIO(dummy_audio_bytes), sr=None)
with patch.object(audio_module, "AudioDecoder", None):
with pytest.raises(ImportError, match="torchcodec audio backend"):
@@ -232,9 +237,10 @@ def test_load_audio_auto_falls_back_without_ffmpeg(dummy_audio_bytes):
def test_load_audio_auto_falls_back_when_libtorchcodec_unloadable(
dummy_audio_bytes,
):
"""torchcodec loads its ffmpeg-backed core lazily at decoder construction;
"""Torchcodec loads its ffmpeg-backed core lazily at decoder construction;
a "Could not load libtorchcodec" RuntimeError there (no system ffmpeg)
must also surface as ImportError so `auto` falls back."""
must also surface as ImportError so `auto` falls back.
"""
class _UnloadableDecoder:
def __init__(self, *args, **kwargs):
+2 -1
View File
@@ -228,7 +228,8 @@ async def test_fetch_image_local_files_with_space_in_name(image_url: str):
@pytest.mark.asyncio
async def test_fetch_image_data_url_with_params():
"""RFC 2397 allows parameters between the mediatype and the base64
marker; they must not be rejected or leak into the media type."""
marker; they must not be rejected or leak into the media type.
"""
connector = MediaConnector()
image = Image.new("RGB", (4, 4), color=(255, 0, 0))
-1
View File
@@ -105,7 +105,6 @@ def test_image_media_io_no_mode_conversion(tmp_path):
def test_image_media_io_rgba_background_color_validation():
"""Test that invalid rgba_background_color values are properly rejected."""
# Test invalid types
with pytest.raises(
ValueError, match="rgba_background_color must be a list or tuple"
+14 -14
View File
@@ -77,8 +77,7 @@ def test_video_media_io_kwargs(monkeypatch: pytest.MonkeyPatch):
@pytest.mark.parametrize("is_color", [True, False])
@pytest.mark.parametrize("fourcc, ext", [("mp4v", "mp4"), ("XVID", "avi")])
def test_opencv_video_io_colorspace(tmp_path, is_color: bool, fourcc: str, ext: str):
"""
Test all functions that use OpenCV for video I/O return RGB format.
"""Test all functions that use OpenCV for video I/O return RGB format.
Both RGB and grayscale videos are tested.
"""
image_path = get_vllm_public_assets(
@@ -168,8 +167,7 @@ class TestVideoBackendOverride2(VideoLoader):
def test_video_media_io_backend_kwarg_override(monkeypatch: pytest.MonkeyPatch):
"""
Test that video_backend kwarg can override the VLLM_VIDEO_LOADER_BACKEND
"""Test that video_backend kwarg can override the VLLM_VIDEO_LOADER_BACKEND
environment variable.
This allows users to dynamically select a different video backend
@@ -201,8 +199,7 @@ def test_video_media_io_backend_kwarg_override(monkeypatch: pytest.MonkeyPatch):
def test_video_media_io_backend_kwarg_not_passed_to_loader(
monkeypatch: pytest.MonkeyPatch,
):
"""
Test that video_backend kwarg is consumed by VideoMediaIO and NOT passed
"""Test that video_backend kwarg is consumed by VideoMediaIO and NOT passed
through to the underlying video loader's load_bytes method.
This ensures the kwarg is properly popped from kwargs before forwarding.
@@ -245,8 +242,7 @@ def test_video_media_io_backend_kwarg_not_passed_to_loader(
def test_video_media_io_backend_env_var_fallback(monkeypatch: pytest.MonkeyPatch):
"""
Test that when video_backend kwarg is None or not provided,
"""Test that when video_backend kwarg is None or not provided,
VideoMediaIO falls back to VLLM_VIDEO_LOADER_BACKEND env var.
"""
with monkeypatch.context() as m:
@@ -285,7 +281,6 @@ def test_load_base64_jpeg_returns_metadata():
metadata, which broke downstream consumers that rely on fields like
total_num_frames and fps. See PR #37301.
"""
num_test_frames = 3
b64_frames = _make_jpeg_b64_frames(num_test_frames)
@@ -403,7 +398,8 @@ def test_pynvvideocodec_unrelated_error_propagates(
class TestMergeKwargsGpuBackendPolicy:
"""Verify that merge_kwargs blocks request-level GPU backend selection
when the static (engine-level) config did not configure that backend."""
when the static (engine-level) config did not configure that backend.
"""
def test_pynvvideocodec_requires_gpu(self):
assert VIDEO_LOADER_REGISTRY.backend_requires_gpu(PYNVVIDEOCODEC_VIDEO_BACKEND)
@@ -496,7 +492,8 @@ class TestMergeKwargsGpuBackendPolicy:
def test_static_pynv_with_different_runtime_gpu_backend(self):
"""If static sets pynv via video_backend but runtime tries to set it
via the codec-level 'backend' key (without a static match), strip it."""
via the codec-level 'backend' key (without a static match), strip it.
"""
result = VideoMediaIO.merge_kwargs(
default_kwargs={"video_backend": "pynvvideocodec"},
runtime_kwargs={"backend": "pynvvideocodec"},
@@ -535,7 +532,8 @@ class TestMergeKwargsGpuBackendPolicy:
def test_strips_request_level_device(self):
"""The decode device is a startup-only knob: a request must not move
decoding onto the GPU when the startup config did not opt in, nor off
it when it did."""
it when it did.
"""
result = VideoMediaIO.merge_kwargs(
default_kwargs={"backend": "torchcodec"},
runtime_kwargs={"device": "cuda"},
@@ -560,7 +558,8 @@ class TestMergeKwargsGpuBackendPolicy:
def test_switching_backend_drops_stale_codec_options(default_kwargs):
"""Codec-specific options from the static config must not leak into a
different codec backend selected per-request, where they would fail the
new backend's option validation."""
new backend's option validation.
"""
result = VideoMediaIO.merge_kwargs(
default_kwargs={**default_kwargs, "num_frames": 8},
runtime_kwargs={"backend": "opencv"},
@@ -582,7 +581,8 @@ def test_pynvvc_frames_normalized_to_nhwc(layout: str):
"""PyNvVideoCodec frame batches are normalized to NHWC regardless of the
per-frame layout the decoder emits (it has varied across versions), so the
HF video processors (which materialize a PIL image per frame) receive the
same NHWC shape as every other video backend."""
same NHWC shape as every other video backend.
"""
torch = pytest.importorskip("torch")
n, h, w, c = 4, 5, 6, 3
-6
View File
@@ -695,7 +695,6 @@ class TestAudioChunking:
def test_split_audio_short_clip(self):
"""Audio shorter than max_clip_duration_s should not be split."""
# 10 seconds of audio at 16kHz
audio = np.linspace(-1.0, 1.0, 160000, dtype=np.float32)
@@ -712,7 +711,6 @@ class TestAudioChunking:
def test_split_audio_exact_length(self):
"""Audio exactly at max_clip_duration_s should not be split."""
# Exactly 30 seconds at 16kHz
audio = np.linspace(-1.0, 1.0, 480000, dtype=np.float32)
@@ -729,7 +727,6 @@ class TestAudioChunking:
def test_split_audio_long_clip(self):
"""Long audio should be split into multiple chunks."""
# 65 seconds of audio at 16kHz
audio = np.linspace(-1.0, 1.0, 1040000, dtype=np.float32)
@@ -749,7 +746,6 @@ class TestAudioChunking:
def test_split_audio_chunks_have_correct_length(self):
"""Each chunk (except last) should be approximately max_clip_duration_s."""
# 65 seconds of audio at 16kHz
audio = np.linspace(-1.0, 1.0, 1040000, dtype=np.float32)
@@ -841,7 +837,6 @@ class TestAudioChunking:
def test_split_audio_preserves_boundaries(self):
"""Verify first and last samples are preserved when chunking."""
audio = np.arange(1120000, dtype=np.float32) # 70s at 16kHz
chunks = split_audio(
@@ -893,7 +888,6 @@ class TestAudioChunking:
def test_split_audio_with_different_sample_rates(self):
"""Test chunking works with different sample rates."""
# 40 seconds at 8kHz
audio_8k = np.linspace(-1.0, 1.0, 320000, dtype=np.float32)
@@ -1,7 +1,6 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
"""
Embedding shape validation in multimodal APIs.
"""Embedding shape validation in multimodal APIs.
Tests verify that embeddings with correct ndim but incorrect hidden_size
are rejected before they can cause crashes during model inference.
@@ -178,8 +177,7 @@ class TestShapeValidationIntegration:
"""Integration tests verifying attack scenarios are blocked."""
def test_attack_scenario_multimodal_image(self):
"""
Simulate attack through Chat API with image embeddings.
"""Simulate attack through Chat API with image embeddings.
Verifies validation occurs in multimodal parser path.
"""
@@ -193,8 +191,7 @@ class TestShapeValidationIntegration:
parser.parse_mm_data({"image": attack_tensor})
def test_attack_scenario_multimodal_audio(self):
"""
Simulate attack through Chat API with audio embeddings.
"""Simulate attack through Chat API with audio embeddings.
Verifies validation occurs in multimodal parser path.
"""
@@ -208,8 +205,7 @@ class TestShapeValidationIntegration:
parser.parse_mm_data({"audio": attack_tensor})
def test_attack_scenario_multimodal_video(self):
"""
Simulate attack through Chat API with video embeddings.
"""Simulate attack through Chat API with video embeddings.
Verifies validation occurs in multimodal parser path.
"""
@@ -1,7 +1,6 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
"""
Unit tests for embedding shape validation.
"""Unit tests for embedding shape validation.
Simple, fast unit tests that can run without server fixtures.
Run with: pytest tests/multimodal/test_embedding_shape_validation_unit.py -v
@@ -167,16 +166,14 @@ class TestAudioEmbedBasicValidation:
class TestShapeValidationDoSPrevention:
"""
Tests for DoS prevention through shape validation.
"""Tests for DoS prevention through shape validation.
Verifies that embeddings with incorrect shapes are rejected early,
preventing crashes during model inference.
"""
def test_prevent_crash_from_wrong_shape_image_embeds(self):
"""
Prevent crash scenario: wrong hidden size in image embeddings.
"""Prevent crash scenario: wrong hidden size in image embeddings.
Without validation, this would pass initial checks but crash later
during model forward pass when dimensions don't match.
@@ -198,9 +195,7 @@ class TestShapeValidationDoSPrevention:
assert str(wrong_hidden_size) in error_msg # Received
def test_prevent_crash_from_wrong_shape_audio_embeds(self):
"""
Prevent crash scenario: wrong hidden size in audio embeddings.
"""
"""Prevent crash scenario: wrong hidden size in audio embeddings."""
expected_hidden_size = 768
wrong_hidden_size = 4096
+2 -1
View File
@@ -141,7 +141,8 @@ def test_hash_collision_video_num_frames():
def test_hash_video_tensor_frames():
"""Videos holding tensor frames (e.g. NVDEC-decoded) hash like
array-framed ones, from the original bytes without a D2H copy."""
array-framed ones, from the original bytes without a D2H copy.
"""
source = b"x" * 100
def item_for_hash(frames):
+2 -1
View File
@@ -80,7 +80,8 @@ def test_l_mode_no_trns_to_rgb():
def test_exif_transpose_normalizes_orientation():
"""Image with EXIF orientation 3 (180-degree rotation) should be
normalized so pixel data matches visual display."""
normalized so pixel data matches visual display.
"""
# Built synthetically because the existing assets are PNGs which
# don't carry EXIF orientation metadata; we need a JPEG with an
# injected EXIF orientation=3 tag.
+4 -2
View File
@@ -59,7 +59,8 @@ def test_frame_size_hwc_chw(frame):
def test_video_with_metadata_tensor_passthrough():
"""Tensor frames pass through unchanged regardless of device: HF video
processors accept tensors, and device-resident frames (e.g. NVDEC-decoded)
must not be copied back to host."""
must not be copied back to host.
"""
frames = torch.zeros((4, H, W, 3), dtype=torch.uint8)
video, metadata = MultiModalDataParser()._get_video_with_metadata(frames)
@@ -70,7 +71,8 @@ def test_video_with_metadata_tensor_passthrough():
@pytest.mark.skipif(not torch.cuda.is_available(), reason="Requires CUDA")
def test_video_with_metadata_keeps_device_tensor():
"""Device-resident frames (e.g. NVDEC-decoded) pass through as tensors,
so a device-side HF processor can consume them without a D2H copy."""
so a device-side HF processor can consume them without a D2H copy.
"""
frames = torch.zeros((4, H, W, 3), dtype=torch.uint8, device="cuda")
video, metadata = MultiModalDataParser()._get_video_with_metadata(frames)
+7 -14
View File
@@ -968,8 +968,7 @@ def test_hf_processor_call_kwargs(
def test_apply_matches_no_match_exits_quickly():
"""
Test that _apply_matches exits quickly when no matches are found.
"""Test that _apply_matches exits quickly when no matches are found.
Previously, _apply_matches had O(n²) behavior when no match was found
because it would increment start_idx by 1 each iteration while
@@ -1027,8 +1026,7 @@ def test_iter_token_matches_rejects_negative_start_idx():
def test_find_mm_placeholders_avoids_quadratic_false_prefixes():
"""
Test that placeholder scanning stays linear under adversarial candidates.
"""Test that placeholder scanning stays linear under adversarial candidates.
The fast-forward scan must not rescan the prompt tail per position when
one candidate's first token never occurs (forcing a full search) while
@@ -1061,8 +1059,7 @@ def test_find_mm_placeholders_avoids_quadratic_false_prefixes():
],
)
def test_find_mm_placeholders_stops_at_missing_item(prompt):
"""
Test that the scan returns no placeholders once it fails to find
"""Test that the scan returns no placeholders once it fails to find
an item's placeholder, leaving later items unresolved.
"""
result = find_mm_placeholders(
@@ -1079,8 +1076,7 @@ def test_find_mm_placeholders_stops_at_missing_item(prompt):
class _FakeTokenizer:
"""
Character-level tokenizer where "foo" merges into one token differently
"""Character-level tokenizer where "foo" merges into one token differently
depending on whether it is followed by "d", like BPE merging "foo" in
"food" across the search-text boundary.
"""
@@ -1145,8 +1141,7 @@ def _text_fallback_processor() -> BaseMultiModalProcessor:
def test_apply_prompt_updates_falls_back_to_text_matching():
"""
Test that the fallback in `_apply_prompt_updates` finds targets that
"""Test that the fallback in `_apply_prompt_updates` finds targets that
tokenize differently inside the prompt ("foo" in "food").
"""
processor = _text_fallback_processor()
@@ -1166,8 +1161,7 @@ def test_apply_prompt_updates_falls_back_to_text_matching():
def test_apply_prompt_updates_falls_back_with_prefix_target():
"""
Test that `PromptIndexTargets.prefix` targets are resolved against the
"""Test that `PromptIndexTargets.prefix` targets are resolved against the
decoded text in the fallback path of `_apply_prompt_updates`.
"""
processor = _text_fallback_processor()
@@ -1192,8 +1186,7 @@ def test_apply_prompt_updates_falls_back_with_prefix_target():
def test_apply_prompt_updates_falls_back_with_index_targets():
"""
Test that the text resolvers of `PromptIndexTargets.start`/`end`
"""Test that the text resolvers of `PromptIndexTargets.start`/`end`
match against the decoded text when another item forces the
fallback in `_apply_prompt_updates`.
"""
+3 -3
View File
@@ -1,7 +1,6 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
"""
Unit tests for MultiModalRegistry.supports_multimodal_inputs and
"""Unit tests for MultiModalRegistry.supports_multimodal_inputs and
Qwen2.5-VL visual component loading behavior.
"""
@@ -58,7 +57,8 @@ def test_dummy_inputs_scheduler_budget(
@pytest.mark.core_model
def test_supports_multimodal_inputs(model_id, limit_mm_per_prompt, expected):
"""Test supports_multimodal_inputs returns correct boolean for various
configs."""
configs.
"""
ctx = build_model_context(
model_id,
limit_mm_per_prompt=limit_mm_per_prompt,
@@ -1,7 +1,6 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
"""
Unit tests for sparse tensor validation.
"""Unit tests for sparse tensor validation.
Simple, fast unit tests that can run without server fixtures.
Run with: pytest tests/multimodal/test_sparse_tensor_validation_unit.py -v
@@ -56,8 +55,7 @@ class TestSparseTensorValidationContextManager:
tensor.to_dense()
def test_without_context_manager_allows_invalid(self):
"""
WITHOUT validation, invalid tensors may not immediately error.
"""WITHOUT validation, invalid tensors may not immediately error.
This demonstrates the vulnerability: PyTorch 2.8.0+ doesn't validate
by default, which can lead to memory corruption.
+2 -1
View File
@@ -231,7 +231,8 @@ def test_group_and_batch_mm_items_splits_shared_data_by_dtype():
def test_encode_image_url_uncommon_format_has_valid_mimetype():
"""A format missing from mimetypes.types_map must still produce a
well-formed type/subtype media type, not a bare 'image'."""
well-formed type/subtype media type, not a bare 'image'.
"""
# ".tga" is not registered in mimetypes.types_map, so it exercises the
# fallback path; Pillow can still encode it.
url = encode_image_url(Image.new("RGB", (2, 2)), format="TGA")
+25 -20
View File
@@ -842,8 +842,7 @@ def test_video_processor_from_model_repo(
def test_video_backend_handles_broken_frames(monkeypatch: pytest.MonkeyPatch):
"""
Regression test for handling videos with broken frames.
"""Regression test for handling videos with broken frames.
This test uses a pre-corrupted video file (assets/corrupted.mp4) that
contains broken frames to verify the video loader handles
them gracefully without crashing and returns accurate metadata.
@@ -882,8 +881,7 @@ def test_video_backend_handles_broken_frames(monkeypatch: pytest.MonkeyPatch):
def test_video_backend_handles_edit_list_trimmed_video(
monkeypatch: pytest.MonkeyPatch,
):
"""
An mp4 edit list (e.g. from a lossless ``ffmpeg -ss ... -c copy`` cut)
"""An mp4 edit list (e.g. from a lossless ``ffmpeg -ss ... -c copy`` cut)
hides the decode lead-in: the header still counts every physical sample
while sequential decode only yields the visible frames. Sampling over the
header count used to collapse such videos to the few indices below the
@@ -923,8 +921,7 @@ def test_video_backend_handles_edit_list_trimmed_video(
def test_video_recovery_simulated_failures(monkeypatch: pytest.MonkeyPatch):
"""
Test that frame recovery correctly uses the next valid frame when
"""Test that frame recovery correctly uses the next valid frame when
target frames fail to load.
Uses corrupted.mp4 and mocks VideoCapture.grab() to fail on specific
@@ -1019,8 +1016,7 @@ def test_video_recovery_simulated_failures(monkeypatch: pytest.MonkeyPatch):
def test_video_recovery_with_corrupted_file(monkeypatch: pytest.MonkeyPatch):
"""
Test frame recovery with an actual corrupted video file using sparse sampling.
"""Test frame recovery with an actual corrupted video file using sparse sampling.
This test uses corrupted.mp4 which has genuine H.264 codec errors on
frame 17. With num_frames=8, the target frames are [0, 3, 7, 10, 14, 17, 21, 25].
@@ -1088,8 +1084,7 @@ def test_video_recovery_with_corrupted_file(monkeypatch: pytest.MonkeyPatch):
def test_video_recovery_dynamic_backend(monkeypatch: pytest.MonkeyPatch):
"""
Test that frame_recovery works with the dynamic video backend.
"""Test that frame_recovery works with the dynamic video backend.
The dynamic backend samples frames based on fps/duration rather than
loading all frames. This test verifies recovery works in that context.
@@ -1219,7 +1214,8 @@ def test_torchcodec_backend_rejects_frame_recovery(dummy_video_path):
@pytest.mark.skipif(not current_platform.is_cuda(), reason="Requires CUDA")
def test_torchcodec_backend_cuda_decodes_on_gpu(dummy_video_path):
"""With device="cuda", torchcodec decodes via NVDEC and keeps the frames
on the GPU instead of returning a host-side numpy array."""
on the GPU instead of returning a host-side numpy array.
"""
pytest.importorskip("torchcodec")
with open(dummy_video_path, "rb") as f:
@@ -1512,7 +1508,8 @@ def test_glm46v_duration_estimation_from_fps():
class TestGLMGASamplingCaps:
"""Regression tests for GHSA-58v5-2m8f-94pr: request-controlled fps
and max_frames must not create intermediate allocations larger than
the actual frame count."""
the actual frame count.
"""
@staticmethod
def _source(
@@ -1566,7 +1563,8 @@ def test_glm5next_backend_selected_for_processor():
"""Glm5NextVideoProcessor maps to the glm5next loader so only the
sampled frames are decoded instead of the whole container. Both the
borrowed-config spelling and the dedicated Glm5next class name (landing
with the new checkpoint) must resolve."""
with the new checkpoint) must resolve.
"""
for name in ("Glm5NextVideoProcessor", "Glm5nextVideoProcessor"):
assert VIDEO_LOADER_REGISTRY.get_backend_for_video_processor(name) == "glm5next"
@@ -1588,7 +1586,8 @@ def test_glm5next_backend_indices_match_sampler(
total_frames, original_fps, duration, fps, max_frames
):
"""The loader must select exactly the frames the processor's sampler
would, with target.fps mapping onto the raw-fps override."""
would, with target.fps mapping onto the raw-fps override.
"""
from vllm.transformers_utils.processors.glm5next import (
glm_sample_frame_indices,
)
@@ -1616,7 +1615,8 @@ def test_glm5next_backend_indices_match_sampler(
def test_glm5next_backend_metadata_contract():
"""create_hf_metadata reports the subset so the processor skips
re-sampling (do_sample_frames=False) and keeps the original totals."""
re-sampling (do_sample_frames=False) and keeps the original totals.
"""
source = VideoSourceMetadata(total_frames_num=900, original_fps=30.0, duration=30.0)
target = VideoTargetMetadata(num_frames=-1, fps=-1, max_duration=-1)
indices = Glm5NextVideoBackend.compute_frames_index_to_sample(source, target)
@@ -1645,7 +1645,8 @@ def test_glm5next_backend_metadata_contract():
def _write_gray_video(tmp_path, total_frames, fps, size=(32, 32)):
"""Synthetic clip whose frame i is flat gray level i (near-lossless under
mp4v), so a decoded frame's level maps back to its source index."""
mp4v), so a decoded frame's level maps back to its source index.
"""
cv2 = pytest.importorskip("cv2")
path = tmp_path / f"gray_{total_frames}_{fps}.mp4"
@@ -1686,7 +1687,8 @@ class _CountingCap:
def test_glm5next_backend_codec_parity(tmp_path, backend):
"""Every codec samples the same GLM indices and decodes the same
frames; the OpenCV seek reader and torchcodec batched index-exact decode
must agree."""
must agree.
"""
if backend == "torchcodec":
pytest.importorskip("torchcodec")
@@ -1716,7 +1718,8 @@ def test_glm5next_backend_codec_parity(tmp_path, backend):
def test_glm5next_backend_decodes_only_sampled_frames(tmp_path):
"""End to end over a synthetic clip: load_bytes returns exactly the
sampler's frame count, with the right frame content at each index."""
sampler's frame count, with the right frame content at each index.
"""
pytest.importorskip("cv2")
total_frames, fps = 60, 10
@@ -1742,7 +1745,8 @@ def test_glm5next_backend_decodes_only_sampled_frames(tmp_path):
def test_glm5next_read_frames_seeks_past_large_gaps(tmp_path):
"""Sparse targets must not walk the container: the stock reader grabs
every frame up to the last index; the GLM reader seeks instead."""
every frame up to the last index; the GLM reader seeks instead.
"""
cv2 = pytest.importorskip("cv2")
total_frames, fps = 200, 10
@@ -1769,7 +1773,8 @@ def test_glm5next_read_frames_seeks_past_large_gaps(tmp_path):
def test_glm5next_read_frames_dense_walk_matches_stock(tmp_path):
"""Dense targets keep the sequential walk (seeking would be slower) and
return the same frames as the stock reader."""
return the same frames as the stock reader.
"""
cv2 = pytest.importorskip("cv2")
total_frames, fps = 120, 10