


'''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   lowercase      (				unittest.TestCase   ):

		"""simple docstring"""

		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]       ,  ):

							'''simple docstring'''


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




		def        lowerCAmelCase__							(						self				):

							'''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   lowercase      (				A__      ,						unittest.TestCase   ):

		"""simple docstring"""

		_a       					=							DonutImageProcessor if is_vision_available() else None




		def        lowerCAmelCase__							(						self				):

							'''simple docstring'''


							UpperCamelCase__  :Union[str, Any]				   =					DonutImageProcessingTester(self				)




		@property
		def        lowerCAmelCase__							(						self				):

							'''simple docstring'''


							return self.image_processor_tester.prepare_image_processor_dict()




		def        lowerCAmelCase__							(						self				):

							'''simple docstring'''


							UpperCamelCase__  :List[Any]				   =					self.image_processing_class(**self.image_processor_dict				)
							self.assertTrue(hasattr(UpperCamelCase_       ,  '''do_resize'''				)				)
							self.assertTrue(hasattr(UpperCamelCase_       ,  '''size'''				)				)
							self.assertTrue(hasattr(UpperCamelCase_       ,  '''do_thumbnail'''				)				)
							self.assertTrue(hasattr(UpperCamelCase_       ,  '''do_align_long_axis'''				)				)
							self.assertTrue(hasattr(UpperCamelCase_       ,  '''do_pad'''				)				)
							self.assertTrue(hasattr(UpperCamelCase_       ,  '''do_normalize'''				)				)
							self.assertTrue(hasattr(UpperCamelCase_       ,  '''image_mean'''				)				)
							self.assertTrue(hasattr(UpperCamelCase_       ,  '''image_std'''				)				)




		def        lowerCAmelCase__							(						self				):

							'''simple docstring'''


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

							UpperCamelCase__  :Dict				   =					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
							UpperCamelCase__  :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        lowerCAmelCase__							(						self				):

							'''simple docstring'''


							pass




		@is_flaky()
		def        lowerCAmelCase__							(						self				):

							'''simple docstring'''


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

							# Test not batched input
							UpperCamelCase__  :Union[str, 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
							UpperCamelCase__  :List[str]				   =					image_processing(UpperCamelCase_       ,  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        lowerCAmelCase__							(						self				):

							'''simple docstring'''


							UpperCamelCase__  :str				   =					self.image_processing_class(**self.image_processor_dict				)
							# create random numpy tensors
							UpperCamelCase__  :int				   =					prepare_image_inputs(self.image_processor_tester       ,  equal_resolution=UpperCamelCase_       ,  numpify=UpperCamelCase_				)
							for image in image_inputs:
												self.assertIsInstance(UpperCamelCase_       ,  np.ndarray				)

							# Test not batched input
							UpperCamelCase__  :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
							UpperCamelCase__  :List[str]				   =					image_processing(UpperCamelCase_       ,  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        lowerCAmelCase__							(						self				):

							'''simple docstring'''


							UpperCamelCase__  :Optional[Any]				   =					self.image_processing_class(**self.image_processor_dict				)
							# create random PyTorch tensors
							UpperCamelCase__  :Optional[int]				   =					prepare_image_inputs(self.image_processor_tester       ,  equal_resolution=UpperCamelCase_       ,  torchify=UpperCamelCase_				)
							for image in image_inputs:
												self.assertIsInstance(UpperCamelCase_       ,  torch.Tensor				)

							# Test not batched input
							UpperCamelCase__  :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
							UpperCamelCase__  :str				   =					image_processing(UpperCamelCase_       ,  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'''],
							    )       ,  )



'''simple docstring'''
from .glue import glue_convert_examples_to_features, glue_output_modes, glue_processors, glue_tasks_num_labels
from .squad import SquadExample, SquadFeatures, SquadVaProcessor, SquadVaProcessor, squad_convert_examples_to_features
from .utils import DataProcessor, InputExample, InputFeatures, SingleSentenceClassificationProcessor
from .xnli import xnli_output_modes, xnli_processors, xnli_tasks_num_labels