Repository: huggingface/transformers
File: tests/models/glm4v/test_image_processing_glm4v.py (Python)

Code before:
                return_tensors="pt",
                input_data_format="channels_last",
                image_mean=(0.0, 0.0, 0.0, 0.0),
                image_std=(1.0, 1.0, 1.0, 1.0),
            ).pixel_values
            expected_output_image_shape = self.image_processor_tester.expected_output_image_shape([image_inputs[0]])
            self.assertEqual(tuple(encoded_images.shape), expected_output_image_shape)

            # Test batched
            encoded_images = image_processor(
                image_inputs,
                return_tensors="pt",
                input_data_format="channels_last",
                image_mean=(0.0, 0.0, 0.0, 0.0),
                image_std=(1.0, 1.0, 1.0, 1.0),
            ).pixel_values
            expected_output_image_shape = self.image_processor_tester.expected_output_image_shape(image_inputs)
            self.assertEqual(tuple(encoded_images.shape), expected_output_image_shape)

    def test_get_number_of_image_patches_matches_slow_processor(self):
        if not is_torchvision_available():
            self.skipTest("Glm4vImageProcessorFast requires torchvision")

        slow_processor = Glm4vImageProcessor()
        fast_processor = Glm4vImageProcessorFast()

        test_cases = [
            (100, 100, {}),
            (200, 50, {}),
            (100, 100, {"patch_size": 28}),
        ]

        for height, width, images_kwargs in test_cases:
            with self.subTest(height=height, width=width, images_kwargs=images_kwargs):
                expected = slow_processor.get_number_of_image_patches(
                    height=height, width=width, images_kwargs=images_kwargs
                )
                self.assertEqual(
                    fast_processor.get_number_of_image_patches(
                        height=height, width=width, images_kwargs=images_kwargs
                    ),
                    expected,
                )


Review comment (suggestion):
let's follow the pattern in other tests such as

```
for image_processing_class in self.image_processor_list:
    image_processor = image_processing_class(**self.image_processor_dict)
```

Code after:
                return_tensors="pt",
                input_data_format="channels_last",
                image_mean=(0.0, 0.0, 0.0, 0.0),
                image_std=(1.0, 1.0, 1.0, 1.0),
            ).pixel_values
            expected_output_image_shape = self.image_processor_tester.expected_output_image_shape([image_inputs[0]])
            self.assertEqual(tuple(encoded_images.shape), expected_output_image_shape)

            # Test batched
            encoded_images = image_processor(
                image_inputs,
                return_tensors="pt",
                input_data_format="channels_last",
                image_mean=(0.0, 0.0, 0.0, 0.0),
                image_std=(1.0, 1.0, 1.0, 1.0),
            ).pixel_values
            expected_output_image_shape = self.image_processor_tester.expected_output_image_shape(image_inputs)
            self.assertEqual(tuple(encoded_images.shape), expected_output_image_shape)

    def test_get_number_of_image_patches_matches_slow_processor(self):
        test_cases = [
            (100, 100, {}, 64),
            (200, 50, {}, 56),
            (100, 100, {"patch_size": 28}, 16),
        ]

        for image_processing_class in self.image_processor_list:
            image_processor = image_processing_class(**self.image_processor_dict)
            for height, width, images_kwargs, expected in test_cases:
                with self.subTest(
                    image_processing_class=image_processing_class.__name__,
                    height=height,
                    width=width,
                    images_kwargs=images_kwargs,
                ):
                    self.assertEqual(
                        image_processor.get_number_of_image_patches(
                            height=height, width=width, images_kwargs=images_kwargs
                        ),
                        expected,
                    )