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:
co-authored by
Claude Opus 5
parent
804e5377aa
commit
8c1557a79c
@@ -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):
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user