Repository: huggingface/transformers
File: tests/models/glm46v/test_processor_glm46v.py (Python)

Code before:
if is_torch_available():
    import torch

if is_torch_available() and is_vision_available():
    from transformers import Glm46VImageProcessorFast


@require_vision
@require_torch
class Glm46VImageProcessorFastTest(unittest.TestCase):
    def test_get_number_of_image_patches_matches_slow_processor(self):
        slow_processor = Glm46VImageProcessor()
        fast_processor = Glm46VImageProcessorFast()
        images_kwargs = {
            "patch_size": 14,
            "merge_size": 2,
            "size": {"shortest_edge": 112 * 112, "longest_edge": 28 * 28 * 15000},
        }

        expected_patches = slow_processor.get_number_of_image_patches(
            height=640, width=960, images_kwargs=images_kwargs
        )
        actual_patches = fast_processor.get_number_of_image_patches(height=640, width=960, images_kwargs=images_kwargs)

        self.assertEqual(actual_patches, expected_patches)


@require_vision
@require_torch
class Glm46VProcessorTest(ProcessorTesterMixin, unittest.TestCase):
    processor_class = Glm46VProcessor
    model_id = "THUDM/GLM-4.1V-9B-Thinking"

    @classmethod
    def _setup_test_attributes(cls, processor):
        cls.image_token = processor.image_token

    @classmethod
    def _setup_from_pretrained(cls, model_id, **kwargs):
        return super()._setup_from_pretrained(
            model_id,
            do_sample_frames=False,
            patch_size=4,
            size={"shortest_edge": 12 * 12, "longest_edge": 18 * 18},
            **kwargs,
        )

    @require_torch
    @require_av
    def _test_apply_chat_template(
        self,

Review comment (suggestion):
needs to be in `test_image_processor`, iirc there's already a similar test for all models. I prob forgot to add it for GLM4v, can you make a similar test to 
https://github.com/huggingface/transformers/blob/b2028e775a52bf57ac2b6bd71b49ce61fa3adde6/tests/models/qwen2_vl/test_image_processing_qwen2_vl.py#L348-L360

Code after:
if is_torch_available():
    import torch


@require_vision
@require_torch
class Glm46VProcessorTest(ProcessorTesterMixin, unittest.TestCase):
    processor_class = Glm46VProcessor
    model_id = "THUDM/GLM-4.1V-9B-Thinking"

    @classmethod
    def _setup_test_attributes(cls, processor):
        cls.image_token = processor.image_token

    @classmethod
    def _setup_from_pretrained(cls, model_id, **kwargs):
        return super()._setup_from_pretrained(
            model_id,
            do_sample_frames=False,
            patch_size=4,
            size={"shortest_edge": 12 * 12, "longest_edge": 18 * 18},
            **kwargs,
        )

    @require_torch
    @require_av
    def _test_apply_chat_template(
        self,
        modality: str,
        batch_size: int,
        return_tensors: str,
        input_name: str,
        processor_name: str,
        input_data: list[str],
    ):
        processor = self.get_processor()
        if processor.chat_template is None:
            self.skipTest("Processor has no chat template")

        if processor_name not in self.processor_class.get_attributes():
            self.skipTest(f"{processor_name} attribute not present in {self.processor_class}")

        batch_messages = [
            [
                {
                    "role": "user",
                    "content": [{"type": "text", "text": "Describe this."}],
                },
            ]
        ] * batch_size