

"""simple docstring"""

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 DeiTImageProcessor


class 			_snake_case     (						unittest.TestCase       ):







      def __init__(self     ,							UpperCAmelCase_     ,							UpperCAmelCase_=7     ,							UpperCAmelCase_=3     ,							UpperCAmelCase_=1_8     ,							UpperCAmelCase_=3_0     ,							UpperCAmelCase_=4_0_0     ,							UpperCAmelCase_=True     ,							UpperCAmelCase_=None     ,							UpperCAmelCase_=True     ,							UpperCAmelCase_=None     ,							UpperCAmelCase_=True     ,							UpperCAmelCase_=[0.5, 0.5, 0.5]     ,							UpperCAmelCase_=[0.5, 0.5, 0.5]     ,							)			->						Union[str, Any]:
           __lowercase												=			size if size is not None else {'''height''': 2_0, '''width''': 2_0}
           __lowercase												=			crop_size if crop_size is not None else {'''height''': 1_8, '''width''': 1_8}

           __lowercase												=			parent
           __lowercase												=			batch_size
           __lowercase												=			num_channels
           __lowercase												=			image_size
           __lowercase												=			min_resolution
           __lowercase												=			max_resolution
           __lowercase												=			do_resize
           __lowercase												=			size
           __lowercase												=			do_center_crop
           __lowercase												=			crop_size
           __lowercase												=			do_normalize
           __lowercase												=			image_mean
           __lowercase												=			image_std







      def        _UpperCamelCase    (self							)			->						Dict:
           return {
               "do_resize": self.do_resize,
               "size": self.size,
               "do_center_crop": self.do_center_crop,
               "crop_size": self.crop_size,
               "do_normalize": self.do_normalize,
               "image_mean": self.image_mean,
               "image_std": self.image_std,
           }



@require_torch
@require_vision
class 			_snake_case     (						UpperCamelCase						,			unittest.TestCase       ):
      __snake_case 			=     DeiTImageProcessor if is_vision_available() else None
      __snake_case 			=     True







      def        _UpperCamelCase    (self							)			->						Dict:
           __lowercase												=			DeiTImageProcessingTester(self							)







      @property
      def        _UpperCamelCase    (self							)			->						Tuple:
           return self.image_processor_tester.prepare_image_processor_dict()







      def        _UpperCamelCase    (self							)			->						List[Any]:
           __lowercase												=			self.image_processing_class(**self.image_processor_dict							)
           self.assertTrue(hasattr(a_     ,							'''do_resize'''							)							)
           self.assertTrue(hasattr(a_     ,							'''size'''							)							)
           self.assertTrue(hasattr(a_     ,							'''do_center_crop'''							)							)
           self.assertTrue(hasattr(a_     ,							'''center_crop'''							)							)
           self.assertTrue(hasattr(a_     ,							'''do_normalize'''							)							)
           self.assertTrue(hasattr(a_     ,							'''image_mean'''							)							)
           self.assertTrue(hasattr(a_     ,							'''image_std'''							)							)







      def        _UpperCamelCase    (self							)			->						int:
           __lowercase												=			self.image_processing_class.from_dict(self.image_processor_dict							)
           self.assertEqual(image_processor.size     ,							{'''height''': 2_0, '''width''': 2_0}							)
           self.assertEqual(image_processor.crop_size     ,							{'''height''': 1_8, '''width''': 1_8}							)

           __lowercase												=			self.image_processing_class.from_dict(self.image_processor_dict     ,							size=4_2     ,							crop_size=8_4							)
           self.assertEqual(image_processor.size     ,							{'''height''': 4_2, '''width''': 4_2}							)
           self.assertEqual(image_processor.crop_size     ,							{'''height''': 8_4, '''width''': 8_4}							)







      def        _UpperCamelCase    (self							)			->						Dict:
           pass







      def        _UpperCamelCase    (self							)			->						List[str]:
           # Initialize image_processing
           __lowercase												=			self.image_processing_class(**self.image_processor_dict							)
           # create random PIL images
           __lowercase												=			prepare_image_inputs(self.image_processor_tester     ,							equal_resolution=a_							)
           for image in image_inputs:
                self.assertIsInstance(a_     ,							Image.Image							)

           # Test not batched input
           __lowercase												=			image_processing(image_inputs[0]     ,							return_tensors='''pt'''							).pixel_values
           self.assertEqual(
               encoded_images.shape     ,							(
                   1,
                   self.image_processor_tester.num_channels,
                   self.image_processor_tester.crop_size['''height'''],
                   self.image_processor_tester.crop_size['''width'''],
               )     ,							)

           # Test batched
           __lowercase												=			image_processing(a_     ,							return_tensors='''pt'''							).pixel_values
           self.assertEqual(
               encoded_images.shape     ,							(
                   self.image_processor_tester.batch_size,
                   self.image_processor_tester.num_channels,
                   self.image_processor_tester.crop_size['''height'''],
                   self.image_processor_tester.crop_size['''width'''],
               )     ,							)







      def        _UpperCamelCase    (self							)			->						int:
           # Initialize image_processing
           __lowercase												=			self.image_processing_class(**self.image_processor_dict							)
           # create random numpy tensors
           __lowercase												=			prepare_image_inputs(self.image_processor_tester     ,							equal_resolution=a_     ,							numpify=a_							)
           for image in image_inputs:
                self.assertIsInstance(a_     ,							np.ndarray							)

           # Test not batched input
           __lowercase												=			image_processing(image_inputs[0]     ,							return_tensors='''pt'''							).pixel_values
           self.assertEqual(
               encoded_images.shape     ,							(
                   1,
                   self.image_processor_tester.num_channels,
                   self.image_processor_tester.crop_size['''height'''],
                   self.image_processor_tester.crop_size['''width'''],
               )     ,							)

           # Test batched
           __lowercase												=			image_processing(a_     ,							return_tensors='''pt'''							).pixel_values
           self.assertEqual(
               encoded_images.shape     ,							(
                   self.image_processor_tester.batch_size,
                   self.image_processor_tester.num_channels,
                   self.image_processor_tester.crop_size['''height'''],
                   self.image_processor_tester.crop_size['''width'''],
               )     ,							)







      def        _UpperCamelCase    (self							)			->						Optional[int]:
           # Initialize image_processing
           __lowercase												=			self.image_processing_class(**self.image_processor_dict							)
           # create random PyTorch tensors
           __lowercase												=			prepare_image_inputs(self.image_processor_tester     ,							equal_resolution=a_     ,							torchify=a_							)
           for image in image_inputs:
                self.assertIsInstance(a_     ,							torch.Tensor							)

           # Test not batched input
           __lowercase												=			image_processing(image_inputs[0]     ,							return_tensors='''pt'''							).pixel_values
           self.assertEqual(
               encoded_images.shape     ,							(
                   1,
                   self.image_processor_tester.num_channels,
                   self.image_processor_tester.crop_size['''height'''],
                   self.image_processor_tester.crop_size['''width'''],
               )     ,							)

           # Test batched
           __lowercase												=			image_processing(a_     ,							return_tensors='''pt'''							).pixel_values
           self.assertEqual(
               encoded_images.shape     ,							(
                   self.image_processor_tester.batch_size,
                   self.image_processor_tester.num_channels,
                   self.image_processor_tester.crop_size['''height'''],
                   self.image_processor_tester.crop_size['''width'''],
               )     ,							)





"""simple docstring"""

import unittest
import warnings

from datasets.utils import experimental





@experimental
def 				__UpperCamelCase   (    )				->			Optional[Any]:




					"""simple docstring"""



					return "success"


class 			_snake_case     (						unittest.TestCase       ):







						def        _UpperCamelCase    (self							)			->						Tuple:
											with warnings.catch_warnings(record=UpperCAmelCase_							) as w:
																warnings.simplefilter('''always'''							)
																self.assertEqual(dummy_function()     ,							'''success'''							)
											self.assertEqual(len(UpperCAmelCase_							)     ,							1							)


