"""simple docstring"""







import unittest

import numpy as np

from transformers.testing_utils import is_flaky, 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 DonutImageProcessor







class        UpperCamelCase		(			unittest.TestCase  ):
   def __init__(			self     ,__UpperCamelCase     ,__UpperCamelCase=7     ,__UpperCamelCase=3     ,__UpperCamelCase=18     ,__UpperCamelCase=30     ,__UpperCamelCase=400     ,__UpperCamelCase=True     ,__UpperCamelCase=None     ,__UpperCamelCase=True     ,__UpperCamelCase=False     ,__UpperCamelCase=True     ,__UpperCamelCase=True     ,__UpperCamelCase=[0.5, 0.5, 0.5]     ,__UpperCamelCase=[0.5, 0.5, 0.5]     ,)	->      Dict:


        '''simple docstring'''


        lowercase_	:				Union[str, Any]													=	parent
        lowercase_	:				List[Any]													=	batch_size
        lowercase_	:				Any													=	num_channels
        lowercase_	:				Optional[int]													=	image_size
        lowercase_	:				Union[str, Any]													=	min_resolution
        lowercase_	:				Optional[Any]													=	max_resolution
        lowercase_	:				Tuple													=	do_resize
        lowercase_	:				int													=	size if size is not None else {'''height''': 18, '''width''': 20}
        lowercase_	:				str													=	do_thumbnail
        lowercase_	:				List[Any]													=	do_align_axis
        lowercase_	:				Tuple													=	do_pad
        lowercase_	:				str													=	do_normalize
        lowercase_	:				Dict													=	image_mean
        lowercase_	:				Any													=	image_std







   def 			_UpperCAmelCase   (			self			)	->      int:


        '''simple docstring'''


        return {
            "do_resize": self.do_resize,
            "size": self.size,
            "do_thumbnail": self.do_thumbnail,
            "do_align_long_axis": self.do_align_axis,
            "do_pad": self.do_pad,
            "do_normalize": self.do_normalize,
            "image_mean": self.image_mean,
            "image_std": self.image_std,
        }







@require_torch
@require_vision
class        UpperCamelCase		(			_snake_case						,      unittest.TestCase  ):
   lowercase							=  DonutImageProcessor if is_vision_available() else None
   def 			_UpperCAmelCase   (			self			)	->      List[str]:


        '''simple docstring'''


        lowercase_	:				str													=	DonutImageProcessingTester(self			)
   @property
   def 			_UpperCAmelCase   (			self			)	->      str:


        '''simple docstring'''


        return self.image_processor_tester.prepare_image_processor_dict()
   def 			_UpperCAmelCase   (			self			)	->      Union[str, Any]:


        '''simple docstring'''


        lowercase_	:				Tuple													=	self.image_processing_class(**self.image_processor_dict			)
        self.assertTrue(hasattr(_lowerCamelCase     ,'do_resize'			)			)
        self.assertTrue(hasattr(_lowerCamelCase     ,'size'			)			)
        self.assertTrue(hasattr(_lowerCamelCase     ,'do_thumbnail'			)			)
        self.assertTrue(hasattr(_lowerCamelCase     ,'do_align_long_axis'			)			)
        self.assertTrue(hasattr(_lowerCamelCase     ,'do_pad'			)			)
        self.assertTrue(hasattr(_lowerCamelCase     ,'do_normalize'			)			)
        self.assertTrue(hasattr(_lowerCamelCase     ,'image_mean'			)			)
        self.assertTrue(hasattr(_lowerCamelCase     ,'image_std'			)			)
   def 			_UpperCAmelCase   (			self			)	->      Dict:


        '''simple docstring'''


        lowercase_	:				Dict													=	self.image_processing_class.from_dict(self.image_processor_dict			)
        self.assertEqual(image_processor.size     ,{'height': 18, 'width': 20}			)

        lowercase_	:				Union[str, Any]													=	self.image_processing_class.from_dict(self.image_processor_dict     ,size=42			)
        self.assertEqual(image_processor.size     ,{'height': 42, 'width': 42}			)

        # Previous config had dimensions in (width, height) order
        lowercase_	:				List[Any]													=	self.image_processing_class.from_dict(self.image_processor_dict     ,size=(42, 84)			)
        self.assertEqual(image_processor.size     ,{'height': 84, 'width': 42}			)
   def 			_UpperCAmelCase   (			self			)	->      List[Any]:


        '''simple docstring'''


        pass
   @is_flaky()
   def 			_UpperCAmelCase   (			self			)	->      Optional[int]:


        '''simple docstring'''


        lowercase_	:				Dict													=	self.image_processing_class(**self.image_processor_dict			)
        # create random PIL images
        lowercase_	:				Optional[Any]													=	prepare_image_inputs(self.image_processor_tester     ,equal_resolution=_lowerCamelCase			)
        for image in image_inputs:
             self.assertIsInstance(_lowerCamelCase     ,Image.Image			)

        # Test not batched input
        lowercase_	:				Any													=	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.size['height'],
                self.image_processor_tester.size['width'],
            )     ,)

        # Test batched
        lowercase_	:				Union[str, Any]													=	image_processing(_lowerCamelCase     ,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.size['height'],
                self.image_processor_tester.size['width'],
            )     ,)
   @is_flaky()
   def 			_UpperCAmelCase   (			self			)	->      Optional[Any]:


        '''simple docstring'''


        lowercase_	:				Any													=	self.image_processing_class(**self.image_processor_dict			)
        # create random numpy tensors
        lowercase_	:				Optional[int]													=	prepare_image_inputs(self.image_processor_tester     ,equal_resolution=_lowerCamelCase     ,numpify=_lowerCamelCase			)
        for image in image_inputs:
             self.assertIsInstance(_lowerCamelCase     ,np.ndarray			)

        # Test not batched input
        lowercase_	:				Optional[Any]													=	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.size['height'],
                self.image_processor_tester.size['width'],
            )     ,)

        # Test batched
        lowercase_	:				int													=	image_processing(_lowerCamelCase     ,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.size['height'],
                self.image_processor_tester.size['width'],
            )     ,)







   @is_flaky()
   def 			_UpperCAmelCase   (			self			)	->      Dict:


        '''simple docstring'''


        lowercase_	:				Any													=	self.image_processing_class(**self.image_processor_dict			)
        # create random PyTorch tensors
        lowercase_	:				Any													=	prepare_image_inputs(self.image_processor_tester     ,equal_resolution=_lowerCamelCase     ,torchify=_lowerCamelCase			)
        for image in image_inputs:
             self.assertIsInstance(_lowerCamelCase     ,torch.Tensor			)

        # Test not batched input
        lowercase_	:				Tuple													=	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.size['height'],
                self.image_processor_tester.size['width'],
            )     ,)

        # Test batched
        lowercase_	:				Tuple													=	image_processing(_lowerCamelCase     ,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.size['height'],
                self.image_processor_tester.size['width'],
            )     ,)





import sys

from .dependency_versions_table import deps
from .utils.versions import require_version, require_version_core


# define which module versions we always want to check at run time
# (usually the ones defined in `install_requires` in setup.py)
#
# order specific notes:
# - tqdm must be checked before tokenizers

snake_case				:    Union[str, Any]       				=     '''python tqdm regex requests packaging filelock numpy tokenizers'''.split()
if sys.version_info < (3, 7):
     pkgs_to_check_at_runtime.append('''dataclasses''')
if sys.version_info < (3, 8):
     pkgs_to_check_at_runtime.append('''importlib_metadata''')

for pkg in pkgs_to_check_at_runtime:
     if pkg in deps:
          if pkg == "tokenizers":
               # must be loaded here, or else tqdm check may fail
               from .utils import is_tokenizers_available

               if not is_tokenizers_available():
                    continue  # not required, check version only if installed

          require_version_core(deps[pkg])
     else:
          raise ValueError(F"""can't find {pkg} in {deps.keys()}, check dependency_versions_table.py""")
def 				__lowerCamelCase						( UpperCAmelCase_						:		Any ,  UpperCAmelCase_						:		Optional[int]=None						):




      """simple docstring"""





      require_version(deps[pkg] ,  UpperCAmelCase_						)





