






import unittest

import numpy as np

from transformers.testing_utils import require_torch, require_vision
from transformers.utils import is_torch_available, is_vision_available

from ...test_image_processing_common import ImageProcessingSavingTestMixin, prepare_image_inputs


if is_torch_available():
 import torch

if is_vision_available():
 from PIL import Image

 from transformers import ViTImageProcessor



class 				_UpperCamelCase      (unittest.TestCase      ):


      def __init__(						self       ,    __UpperCamelCase       ,    __UpperCamelCase=1_3       ,    __UpperCamelCase=3       ,    __UpperCamelCase=2_2_4       ,    __UpperCamelCase=3_0       ,    __UpperCamelCase=4_0_0       ,    __UpperCamelCase=True       ,    __UpperCamelCase=None       ,    __UpperCamelCase=True       ,    __UpperCamelCase=[0.5, 0.5, 0.5]       ,    __UpperCamelCase=[0.5, 0.5, 0.5]       ,    )->						str:
           __lowerCAmelCase             =       size if size is not None else {"height": 1_8, "width": 1_8}
           __lowerCAmelCase             =       parent
           __lowerCAmelCase             =       batch_size
           __lowerCAmelCase             =       num_channels
           __lowerCAmelCase             =       image_size
           __lowerCAmelCase             =       min_resolution
           __lowerCAmelCase             =       max_resolution
           __lowerCAmelCase             =       do_resize
           __lowerCAmelCase             =       size
           __lowerCAmelCase             =       do_normalize
           __lowerCAmelCase             =       image_mean
           __lowerCAmelCase             =       image_std


      def 			__UpperCAmelCase		(						self						)->						List[Any]:
           return {
               "image_mean": self.image_mean,
               "image_std": self.image_std,
               "do_normalize": self.do_normalize,
               "do_resize": self.do_resize,
               "size": self.size,
           }



@require_torch
@require_vision
class 				_UpperCamelCase      (a_				,		unittest.TestCase      ):
      snake_case_	=				ViTImageProcessor if is_vision_available() else None


      def 			__UpperCAmelCase		(						self						)->						Dict:
           __lowerCAmelCase             =       EfficientFormerImageProcessorTester(self						)


      @property
      def 			__UpperCAmelCase		(						self						)->						Optional[int]:
           return self.image_proc_tester.prepare_image_processor_dict()


      def 			__UpperCAmelCase		(						self						)->						int:
           __lowerCAmelCase             =       self.image_processing_class(**self.image_processor_dict						)
           self.assertTrue(hasattr(__UpperCamelCase       ,    "image_mean"						)						)
           self.assertTrue(hasattr(__UpperCamelCase       ,    "image_std"						)						)
           self.assertTrue(hasattr(__UpperCamelCase       ,    "do_normalize"						)						)
           self.assertTrue(hasattr(__UpperCamelCase       ,    "do_resize"						)						)
           self.assertTrue(hasattr(__UpperCamelCase       ,    "size"						)						)


      def 			__UpperCAmelCase		(						self						)->						Union[str, Any]:
           pass


      def 			__UpperCAmelCase		(						self						)->						Optional[int]:
           # Initialize image_processor
           __lowerCAmelCase             =       self.image_processing_class(**self.image_processor_dict						)
           # create random PIL images
           __lowerCAmelCase             =       prepare_image_inputs(self.image_proc_tester       ,    equal_resolution=__UpperCamelCase						)
           for image in image_inputs:
                self.assertIsInstance(__UpperCamelCase       ,    Image.Image						)

           # Test not batched input
           __lowerCAmelCase             =       image_processor(image_inputs[0]       ,    return_tensors="pt"						).pixel_values
           self.assertEqual(
               encoded_images.shape       ,    (
                   1,
                   self.image_proc_tester.num_channels,
                   self.image_proc_tester.size["height"],
                   self.image_proc_tester.size["width"],
               )       ,    )

           # Test batched
           __lowerCAmelCase             =       image_processor(__UpperCamelCase       ,    return_tensors="pt"						).pixel_values
           self.assertEqual(
               encoded_images.shape       ,    (
                   self.image_proc_tester.batch_size,
                   self.image_proc_tester.num_channels,
                   self.image_proc_tester.size["height"],
                   self.image_proc_tester.size["width"],
               )       ,    )


      def 			__UpperCAmelCase		(						self						)->						str:
           # Initialize image_processor
           __lowerCAmelCase             =       self.image_processing_class(**self.image_processor_dict						)
           # create random numpy tensors
           __lowerCAmelCase             =       prepare_image_inputs(self.image_proc_tester       ,    equal_resolution=__UpperCamelCase       ,    numpify=__UpperCamelCase						)
           for image in image_inputs:
                self.assertIsInstance(__UpperCamelCase       ,    np.ndarray						)

           # Test not batched input
           __lowerCAmelCase             =       image_processor(image_inputs[0]       ,    return_tensors="pt"						).pixel_values
           self.assertEqual(
               encoded_images.shape       ,    (
                   1,
                   self.image_proc_tester.num_channels,
                   self.image_proc_tester.size["height"],
                   self.image_proc_tester.size["width"],
               )       ,    )

           # Test batched
           __lowerCAmelCase             =       image_processor(__UpperCamelCase       ,    return_tensors="pt"						).pixel_values
           self.assertEqual(
               encoded_images.shape       ,    (
                   self.image_proc_tester.batch_size,
                   self.image_proc_tester.num_channels,
                   self.image_proc_tester.size["height"],
                   self.image_proc_tester.size["width"],
               )       ,    )


      def 			__UpperCAmelCase		(						self						)->						Union[str, Any]:
           # Initialize image_processor
           __lowerCAmelCase             =       self.image_processing_class(**self.image_processor_dict						)
           # create random PyTorch tensors
           __lowerCAmelCase             =       prepare_image_inputs(self.image_proc_tester       ,    equal_resolution=__UpperCamelCase       ,    torchify=__UpperCamelCase						)
           for image in image_inputs:
                self.assertIsInstance(__UpperCamelCase       ,    torch.Tensor						)

           # Test not batched input
           __lowerCAmelCase             =       image_processor(image_inputs[0]       ,    return_tensors="pt"						).pixel_values
           self.assertEqual(
               encoded_images.shape       ,    (
                   1,
                   self.image_proc_tester.num_channels,
                   self.image_proc_tester.size["height"],
                   self.image_proc_tester.size["width"],
               )       ,    )

           # Test batched
           __lowerCAmelCase             =       image_processor(__UpperCamelCase       ,    return_tensors="pt"						).pixel_values
           self.assertEqual(
               encoded_images.shape       ,    (
                   self.image_proc_tester.batch_size,
                   self.image_proc_tester.num_channels,
                   self.image_proc_tester.size["height"],
                   self.image_proc_tester.size["width"],
               )       ,    )














# tests directory-specific settings - this file is run automatically
# by pytest before any tests are run

import sys
import warnings
from os.path import abspath, dirname, join


# allow having multiple repository checkouts and not needing to remember to rerun
# 'pip install -e .[dev]' when switching between checkouts and running tests.
lowerCamelCase      :       Dict    =						abspath(join(dirname(dirname(__file__)), '''src'''))
sys.path.insert(1, git_repo_path)

# silence FutureWarning warnings in tests since often we can't act on them until
# they become normal warnings - i.e. the tests still need to test the current functionality
warnings.simplefilter(action='''ignore''', category=FutureWarning)





def    __lowerCAmelCase   (    __snake_case							):
     from diffusers.utils.testing_utils import pytest_addoption_shared

     pytest_addoption_shared(__snake_case							)





def    __lowerCAmelCase   (    __snake_case							):
     from diffusers.utils.testing_utils import pytest_terminal_summary_main

     __lowerCAmelCase             =       terminalreporter.config.getoption("--make-reports"							)
     if make_reports:
          pytest_terminal_summary_main(__snake_case       ,			id=__snake_case							)






