[Bugfix] Fix edge case in UUID data parsing (#34884)
Signed-off-by: DarkLight1337 <tlleungac@connect.ust.hk>
This commit is contained in:
@@ -42,6 +42,16 @@ def test_multi_modal_uuids_length_mismatch_raises():
|
||||
|
||||
mm_data = {"image": [cherry_pil_image, stop_pil_image]}
|
||||
|
||||
# Mismatch: 2 items but only 0 uuids provided
|
||||
mm_uuids = {"image": []} # type: ignore[var-annotated]
|
||||
|
||||
mm_processor = renderer.get_mm_processor()
|
||||
mm_data_items = mm_processor.info.parse_mm_data(mm_data)
|
||||
mm_uuid_items = parse_mm_uuids(mm_uuids)
|
||||
|
||||
with pytest.raises(ValueError, match="must have same length as"):
|
||||
renderer._process_mm_uuids(mm_data, mm_data_items, mm_uuid_items, "req-1a")
|
||||
|
||||
# Mismatch: 2 items but only 1 uuid provided
|
||||
mm_uuids = {"image": ["hash_cherry"]}
|
||||
|
||||
@@ -50,7 +60,7 @@ def test_multi_modal_uuids_length_mismatch_raises():
|
||||
mm_uuid_items = parse_mm_uuids(mm_uuids)
|
||||
|
||||
with pytest.raises(ValueError, match="must have same length as"):
|
||||
renderer._process_mm_uuids(mm_data, mm_data_items, mm_uuid_items, "req-1")
|
||||
renderer._process_mm_uuids(mm_data, mm_data_items, mm_uuid_items, "req-1b")
|
||||
|
||||
|
||||
def test_multi_modal_uuids_missing_modality_raises():
|
||||
@@ -125,8 +135,8 @@ def test_multi_modal_uuids_accepts_empty(
|
||||
|
||||
# While None means cached multi-modal input requiring UUIDs
|
||||
# an empty list means no multi-modal input
|
||||
mm_data = {"image": [], "video": []} # type: ignore[var-annotated]
|
||||
mm_uuids = {"image": [], "video": None} # type: ignore[var-annotated]
|
||||
mm_data = {"image": [], "video": [], "audio": None} # type: ignore[var-annotated]
|
||||
mm_uuids = {"image": [], "video": None, "audio": []} # type: ignore[var-annotated]
|
||||
|
||||
mm_processor = renderer.get_mm_processor()
|
||||
mm_data_items = mm_processor.info.parse_mm_data(mm_data)
|
||||
|
||||
@@ -482,7 +482,7 @@ class BaseRenderer(ABC, Generic[_T]):
|
||||
)
|
||||
|
||||
elif uuid_items is not None:
|
||||
if len(uuid_items) > 0 and len(data_items) != len(uuid_items):
|
||||
if len(data_items) != len(uuid_items):
|
||||
raise ValueError(
|
||||
f"If given, multi_modal_uuids[{modality!r}] must have "
|
||||
f"same length as multi_modal_data[{modality!r}], but "
|
||||
|
||||
Reference in New Issue
Block a user