


'''simple docstring'''
import unittest

import numpy as np

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

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 DPTImageProcessor

class 						_lowerCamelCase					(    unittest.TestCase				):




 '''simple docstring'''


 def __init__(      self      ,      __lowercase      ,      __lowercase=7      ,      __lowercase=3      ,      __lowercase=18      ,      __lowercase=30      ,      __lowercase=400      ,      __lowercase=True      ,      __lowercase=None      ,      __lowercase=True      ,      __lowercase=[0.5, 0.5, 0.5]      ,      __lowercase=[0.5, 0.5, 0.5]      ,      ):

  """simple docstring"""







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







 def  snake_case__   (      self						):

  """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 						_lowerCamelCase					(    snake_case_    ,		unittest.TestCase				):




 '''simple docstring'''
 __lowercase				:		Optional[Any]    							=						DPTImageProcessor if is_vision_available() else None


 def  snake_case__   (      self						):

  """simple docstring"""







  __A  :		int       =			DPTImageProcessingTester(self						)


 @property
 def  snake_case__   (      self						):

  """simple docstring"""







  return self.image_processor_tester.prepare_image_processor_dict()


 def  snake_case__   (      self						):

  """simple docstring"""







  __A  :		Optional[int]       =			self.image_processing_class(**self.image_processor_dict						)
  self.assertTrue(hasattr(__lowercase      ,      'image_mean'						)						)
  self.assertTrue(hasattr(__lowercase      ,      'image_std'						)						)
  self.assertTrue(hasattr(__lowercase      ,      'do_normalize'						)						)
  self.assertTrue(hasattr(__lowercase      ,      'do_resize'						)						)
  self.assertTrue(hasattr(__lowercase      ,      'size'						)						)


 def  snake_case__   (      self						):

  """simple docstring"""







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

  __A  :		Any       =			self.image_processing_class.from_dict(self.image_processor_dict      ,      size=42						)
  self.assertEqual(image_processor.size      ,      {'height': 42, 'width': 42}						)


 def  snake_case__   (      self						):

  """simple docstring"""







  __A  :		List[str]       =			self.image_processing_class(**self.image_processor_dict						)
  # create random PIL images
  __A  :		List[str]       =			prepare_image_inputs(self.image_processor_tester      ,      equal_resolution=__lowercase						)
  for image in image_inputs:
   self.assertIsInstance(__lowercase      ,      Image.Image						)

  # Test not batched input
  __A  :		List[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
  __A  :		Any       =			image_processing(__lowercase      ,      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'],
      )      ,      )


 def  snake_case__   (      self						):

  """simple docstring"""







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

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







 def  snake_case__   (      self						):

  """simple docstring"""







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

  # Test not batched input
  __A  :		List[str]       =			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
  __A  :		List[str]       =			image_processing(__lowercase      ,      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'''
import unittest

from transformers import DonutProcessor


UpperCAmelCase_ :     str								=      'naver-clova-ix/donut-base'

class 						_lowerCamelCase					(    unittest.TestCase				):




 '''simple docstring'''


 def  snake_case__   (      self						):

  """simple docstring"""







  __A  :		List[str]       =			DonutProcessor.from_pretrained(__lowercase						)







 def  snake_case__   (      self						):

  """simple docstring"""







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

  __A  :		Optional[Any]       =			(
      '<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  :		List[Any]       =			self.processor.tokenajson(__lowercase						)

  self.assertDictEqual(__lowercase      ,      __lowercase						)






