55import mimetypes
66import os
77from tempfile import NamedTemporaryFile , TemporaryDirectory
8- from typing import TYPE_CHECKING , NamedTuple
98
109import numpy as np
1110import pytest
1514from vllm .multimodal .inputs import PlaceholderRange
1615from 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)
2218TEST_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