Skip to content

Commit b0e9f04

Browse files
DarkLight1337yewentao256
authored andcommitted
[Misc] Simplify test_argsort_mm_positions (#25690)
Signed-off-by: DarkLight1337 <tlleungac@connect.ust.hk> Signed-off-by: yewentao256 <zhyanwentao@126.com>
1 parent 8038595 commit b0e9f04

File tree

1 file changed

+21
-26
lines changed

1 file changed

+21
-26
lines changed

tests/multimodal/test_utils.py

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import mimetypes
66
import os
77
from tempfile import NamedTemporaryFile, TemporaryDirectory
8-
from typing import TYPE_CHECKING, NamedTuple
98

109
import numpy as np
1110
import pytest
@@ -15,9 +14,6 @@
1514
from vllm.multimodal.inputs import PlaceholderRange
1615
from vllm.multimodal.utils import MediaConnector, argsort_mm_positions
1716

18-
if TYPE_CHECKING:
19-
from vllm.multimodal.inputs import MultiModalPlaceholderDict
20-
2117
# Test different image extensions (JPG/PNG) and formats (gray/RGB/RGBA)
2218
TEST_IMAGE_ASSETS = [
2319
"2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg", # "https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg/2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg"
@@ -218,18 +214,13 @@ async def test_fetch_video_http_with_dynamic_loader(
218214
assert metadata_sync["video_backend"] == "opencv_dynamic"
219215

220216

221-
# Used for `test_argsort_mm_positions`.
222-
class TestCase(NamedTuple):
223-
mm_positions: "MultiModalPlaceholderDict"
224-
expected_modality_idxs: list[tuple[str, int]]
225-
226-
227-
def test_argsort_mm_positions():
228-
229-
test_cases = [
217+
# yapf: disable
218+
@pytest.mark.parametrize(
219+
"case",
220+
[
230221
# Single modality
231222
## Internally sorted
232-
TestCase(
223+
dict(
233224
mm_positions={
234225
"image": [
235226
PlaceholderRange(offset=0, length=2),
@@ -242,7 +233,7 @@ def test_argsort_mm_positions():
242233
],
243234
),
244235
## Internally unsorted
245-
TestCase(
236+
dict(
246237
mm_positions={
247238
"image": [
248239
PlaceholderRange(offset=3, length=2),
@@ -257,7 +248,7 @@ def test_argsort_mm_positions():
257248
258249
# Two modalities
259250
## Internally sorted
260-
TestCase(
251+
dict(
261252
mm_positions={
262253
"image": [
263254
PlaceholderRange(offset=7, length=4),
@@ -276,7 +267,7 @@ def test_argsort_mm_positions():
276267
],
277268
),
278269
## Interleaved, internally sorted
279-
TestCase(
270+
dict(
280271
mm_positions={
281272
"image": [
282273
PlaceholderRange(offset=0, length=4),
@@ -295,7 +286,7 @@ def test_argsort_mm_positions():
295286
],
296287
),
297288
## Interleaved, internally unsorted
298-
TestCase(
289+
dict(
299290
mm_positions={
300291
"image": [
301292
PlaceholderRange(offset=8, length=2),
@@ -316,7 +307,7 @@ def test_argsort_mm_positions():
316307
317308
# Three modalities
318309
## Internally sorted
319-
TestCase(
310+
dict(
320311
mm_positions={
321312
"image": [
322313
PlaceholderRange(offset=15, length=7),
@@ -341,7 +332,7 @@ def test_argsort_mm_positions():
341332
],
342333
),
343334
## Interleaved, internally sorted
344-
TestCase(
335+
dict(
345336
mm_positions={
346337
"image": [
347338
PlaceholderRange(offset=0, length=2),
@@ -363,8 +354,8 @@ def test_argsort_mm_positions():
363354
("image", 2),
364355
],
365356
),
366-
## Interleaved, internally sunorted
367-
TestCase(
357+
## Interleaved, internally unsorted
358+
dict(
368359
mm_positions={
369360
"image": [
370361
PlaceholderRange(offset=0, length=2),
@@ -386,9 +377,13 @@ def test_argsort_mm_positions():
386377
("image", 1),
387378
],
388379
),
389-
]
380+
],
381+
)
382+
# yapf: enable
383+
def test_argsort_mm_positions(case):
384+
mm_positions = case["mm_positions"]
385+
expected_modality_idxs = case["expected_modality_idxs"]
390386

391-
for mm_positions, expected_modality_idxs in test_cases:
392-
modality_idxs = argsort_mm_positions(mm_positions)
387+
modality_idxs = argsort_mm_positions(mm_positions)
393388

394-
assert modality_idxs == expected_modality_idxs
389+
assert modality_idxs == expected_modality_idxs

0 commit comments

Comments
 (0)