



"""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 ViTImageProcessor

class    _A	(     unittest.TestCase   ):



       def __init__(		self							:					Optional[int]					,		__SCREAMING_SNAKE_CASE							:					List[Any]					,		__SCREAMING_SNAKE_CASE							:					List[Any]=13					,		__SCREAMING_SNAKE_CASE							:					str=3					,		__SCREAMING_SNAKE_CASE							:					int=224					,		__SCREAMING_SNAKE_CASE							:					Dict=30					,		__SCREAMING_SNAKE_CASE							:					int=400					,		__SCREAMING_SNAKE_CASE							:					str=True					,		__SCREAMING_SNAKE_CASE							:					List[str]=None					,		__SCREAMING_SNAKE_CASE							:					Any=True					,		__SCREAMING_SNAKE_CASE							:					str=[0.5, 0.5, 0.5]					,		__SCREAMING_SNAKE_CASE							:					int=[0.5, 0.5, 0.5]					,		):


           '''simple docstring'''

           __a							=    size if size is not None else {'''height''': 18, '''width''': 18}
           __a							=    parent
           __a							=    batch_size
           __a							=    num_channels
           __a							=    image_size
           __a							=    min_resolution
           __a							=    max_resolution
           __a							=    do_resize
           __a							=    size
           __a							=    do_normalize
           __a							=    image_mean
           __a							=    image_std





       def 		_lowerCamelCase      (		self							:					List[Any]):


           '''simple docstring'''

           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    _A	(     UpperCamelCase__				,unittest.TestCase   ):
       UpperCamelCase__  :   int						 =						ViTImageProcessor if is_vision_available() else None



       def 		_lowerCamelCase      (		self							:					List[str]):


           '''simple docstring'''

           __a							=    EfficientFormerImageProcessorTester(self)



       @property
       def 		_lowerCamelCase      (		self							:					Any):


           '''simple docstring'''

           return self.image_proc_tester.prepare_image_processor_dict()



       def 		_lowerCamelCase      (		self							:					Any):


           '''simple docstring'''

           __a							=    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 		_lowerCamelCase      (		self							:					int):


           '''simple docstring'''

           pass



       def 		_lowerCamelCase      (		self							:					Union[str, Any]):


           '''simple docstring'''

           __a							=    self.image_processing_class(**self.image_processor_dict)
           # create random PIL images
           __a							=    prepare_image_inputs(self.image_proc_tester					,		equal_resolution=UpperCamelCase_)
           for image in image_inputs:
               self.assertIsInstance(UpperCamelCase_					,		Image.Image)

           # Test not batched input
           __a							=    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
           __a							=    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 		_lowerCamelCase      (		self							:					Union[str, Any]):


           '''simple docstring'''

           __a							=    self.image_processing_class(**self.image_processor_dict)
           # create random numpy tensors
           __a							=    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
           __a							=    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
           __a							=    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 		_lowerCamelCase      (		self							:					Any):


           '''simple docstring'''

           __a							=    self.image_processing_class(**self.image_processor_dict)
           # create random PyTorch tensors
           __a							=    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
           __a							=    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
           __a							=    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'''],
               )					,		)










import unittest

from transformers import DonutProcessor


__snake_case						:List[str]						=					'''naver-clova-ix/donut-base'''

class    _A	(     unittest.TestCase   ):



       def 		_lowerCamelCase      (		self							:					List[str]):


           '''simple docstring'''

           __a							=    DonutProcessor.from_pretrained(__SCREAMING_SNAKE_CASE)





       def 		_lowerCamelCase      (		self							:					Tuple):


           '''simple docstring'''

           __a							=    {
               '''name''': '''John Doe''',
               '''age''': '''99''',
               '''city''': '''Atlanta''',
               '''state''': '''GA''',
               '''zip''': '''30301''',
               '''phone''': '''123-4567''',
               '''nicknames''': [{'''nickname''': '''Johnny'''}, {'''nickname''': '''JD'''}],
           }

           __a							=    (
               '''<s_name>John Doe</s_name><s_age>99</s_age><s_city>Atlanta</s_city>'''
               '''<s_state>GA</s_state><s_zip>30301</s_zip><s_phone>123-4567</s_phone>'''
               '''<s_nicknames><s_nickname>Johnny</s_nickname>'''
               '''<sep/><s_nickname>JD</s_nickname></s_nicknames>'''
           )
           __a							=    self.processor.tokenajson(__SCREAMING_SNAKE_CASE)

           self.assertDictEqual(__SCREAMING_SNAKE_CASE					,		__SCREAMING_SNAKE_CASE)





