Update kwargs validation for preprocess with decorator (#32024)
* BLIP preprocess * BIT preprocess * BRIDGETOWER preprocess * CHAMELEON preprocess * CHINESE_CLIP preprocess * CONVNEXT preprocess * DEIT preprocess * DONUT preprocess * DPT preprocess * FLAVA preprocess * EFFICIENTNET preprocess * FUYU preprocess * GLPN preprocess * IMAGEGPT preprocess * INTRUCTBLIPVIDEO preprocess * VIVIT preprocess * ZOEDEPTH preprocess * VITMATTE preprocess * VIT preprocess * VILT preprocess * VIDEOMAE preprocess * VIDEOLLAVA * TVP processing * TVP fixup * SWIN2SR preprocess * SIGLIP preprocess * SAM preprocess * RT-DETR preprocess * PVT preprocess * POOLFORMER preprocess * PERCEIVER preprocess * OWLVIT preprocess * OWLV2 preprocess * NOUGAT preprocess * MOBILEVIT preprocess * MOBILENETV2 preprocess * MOBILENETV1 preprocess * LEVIT preprocess * LAYOUTLMV2 preprocess * LAYOUTLMV3 preprocess * Add test * Update tests
This commit is contained in:
committed by
GitHub
parent
e85d86398a
commit
fb66ef8147
@@ -19,6 +19,7 @@ import os
|
||||
import pathlib
|
||||
import tempfile
|
||||
import time
|
||||
import warnings
|
||||
|
||||
import numpy as np
|
||||
import requests
|
||||
@@ -425,8 +426,12 @@ class ImageProcessingTestMixin:
|
||||
)
|
||||
|
||||
def test_image_processor_preprocess_arguments(self):
|
||||
is_tested = False
|
||||
|
||||
for image_processing_class in self.image_processor_list:
|
||||
image_processor = image_processing_class(**self.image_processor_dict)
|
||||
|
||||
# validation done by _valid_processor_keys attribute
|
||||
if hasattr(image_processor, "_valid_processor_keys") and hasattr(image_processor, "preprocess"):
|
||||
preprocess_parameter_names = inspect.getfullargspec(image_processor.preprocess).args
|
||||
preprocess_parameter_names.remove("self")
|
||||
@@ -434,6 +439,28 @@ class ImageProcessingTestMixin:
|
||||
valid_processor_keys = image_processor._valid_processor_keys
|
||||
valid_processor_keys.sort()
|
||||
self.assertEqual(preprocess_parameter_names, valid_processor_keys)
|
||||
is_tested = True
|
||||
|
||||
# validation done by @filter_out_non_signature_kwargs decorator
|
||||
if hasattr(image_processor.preprocess, "_filter_out_non_signature_kwargs"):
|
||||
if hasattr(self.image_processor_tester, "prepare_image_inputs"):
|
||||
inputs = self.image_processor_tester.prepare_image_inputs()
|
||||
elif hasattr(self.image_processor_tester, "prepare_video_inputs"):
|
||||
inputs = self.image_processor_tester.prepare_video_inputs()
|
||||
else:
|
||||
self.skipTest(reason="No valid input preparation method found")
|
||||
|
||||
with warnings.catch_warnings(record=True) as raised_warnings:
|
||||
warnings.simplefilter("always")
|
||||
image_processor(inputs, extra_argument=True)
|
||||
|
||||
messages = " ".join([str(w.message) for w in raised_warnings])
|
||||
self.assertGreaterEqual(len(raised_warnings), 1)
|
||||
self.assertIn("extra_argument", messages)
|
||||
is_tested = True
|
||||
|
||||
if not is_tested:
|
||||
self.skipTest(reason="No validation found for `preprocess` method")
|
||||
|
||||
|
||||
class AnnotationFormatTestMixin:
|
||||
|
||||
Reference in New Issue
Block a user