






"""simple docstring"""
import unittest
from dataclasses import dataclass
from typing import Optional

from transformers.utils import ModelOutput



@dataclass
class 		a_      (	snake_case_ ):







      '''simple docstring'''

      lowerCamelCase__       :				float
      lowerCamelCase__       :				Optional[float] =	None
      lowerCamelCase__       :				Optional[float] =	None



class 		a_      (	unittest.TestCase ):







      '''simple docstring'''

      def 			a__							(self					):

       '''simple docstring'''



       lowerCamelCase__     :			str     				=						ModelOutputTest(a=3_0					)
       self.assertEqual(x.a,     3_0					)
       self.assertIsNone(x.b					)
       self.assertIsNone(x.c					)
       with self.assertRaises(lowerCamelCase_					):
        lowerCamelCase__     :			Union[str, Any]     				=						x.d




      def 			a__							(self					):

       '''simple docstring'''



       lowerCamelCase__     :			int     				=						ModelOutputTest(a=3_0,     b=1_0					)
       self.assertEqual(x[0],     3_0					)
       self.assertEqual(x[1],     1_0					)
       self.assertEqual(x[:2],     (3_0, 1_0)					)
       self.assertEqual(x[:],     (3_0, 1_0)					)

       lowerCamelCase__     :			Optional[int]     				=						ModelOutputTest(a=3_0,     c=1_0					)
       self.assertEqual(x[0],     3_0					)
       self.assertEqual(x[1],     1_0					)
       self.assertEqual(x[:2],     (3_0, 1_0)					)
       self.assertEqual(x[:],     (3_0, 1_0)					)




      def 			a__							(self					):

       '''simple docstring'''



       lowerCamelCase__     :			Any     				=						ModelOutputTest(a=3_0,     b=1_0					)
       self.assertEqual(x['a'],     3_0					)
       self.assertEqual(x['b'],     1_0					)
       with self.assertRaises(lowerCamelCase_					):
        lowerCamelCase__     :			int     				=						x['c']

       lowerCamelCase__     :			List[Any]     				=						ModelOutputTest(a=3_0,     c=1_0					)
       self.assertEqual(x['a'],     3_0					)
       self.assertEqual(x['c'],     1_0					)
       with self.assertRaises(lowerCamelCase_					):
        lowerCamelCase__     :			Dict     				=						x['b']




      def 			a__							(self					):

       '''simple docstring'''



       lowerCamelCase__     :			str     				=						ModelOutputTest(a=3_0					)
       self.assertEqual(list(x.keys()					),     ['a']					)
       self.assertEqual(list(x.values()					),     [3_0]					)
       self.assertEqual(list(x.items()					),     [('a', 3_0)]					)
       self.assertEqual(list(lowerCamelCase_					),     ['a']					)

       lowerCamelCase__     :			Union[str, Any]     				=						ModelOutputTest(a=3_0,     b=1_0					)
       self.assertEqual(list(x.keys()					),     ['a', 'b']					)
       self.assertEqual(list(x.values()					),     [3_0, 1_0]					)
       self.assertEqual(list(x.items()					),     [('a', 3_0), ('b', 1_0)]					)
       self.assertEqual(list(lowerCamelCase_					),     ['a', 'b']					)

       lowerCamelCase__     :			List[str]     				=						ModelOutputTest(a=3_0,     c=1_0					)
       self.assertEqual(list(x.keys()					),     ['a', 'c']					)
       self.assertEqual(list(x.values()					),     [3_0, 1_0]					)
       self.assertEqual(list(x.items()					),     [('a', 3_0), ('c', 1_0)]					)
       self.assertEqual(list(lowerCamelCase_					),     ['a', 'c']					)

       with self.assertRaises(lowerCamelCase_					):
        lowerCamelCase__     :			Dict     				=						x.update({'d': 2_0}					)
       with self.assertRaises(lowerCamelCase_					):
        del x["a"]
       with self.assertRaises(lowerCamelCase_					):
        lowerCamelCase__     :			str     				=						x.pop('a'					)
       with self.assertRaises(lowerCamelCase_					):
        lowerCamelCase__     :			int     				=						x.setdefault('d',     3_2					)




      def 			a__							(self					):

       '''simple docstring'''



       lowerCamelCase__     :			List[str]     				=						ModelOutputTest(a=3_0					)
       lowerCamelCase__     :			Optional[int]     				=						1_0
       self.assertEqual(x.a,     1_0					)
       self.assertEqual(x['a'],     1_0					)




      def 			a__							(self					):

       '''simple docstring'''



       lowerCamelCase__     :			List[str]     				=						ModelOutputTest(a=3_0					)
       lowerCamelCase__     :			List[Any]     				=						1_0
       self.assertEqual(x.a,     1_0					)
       self.assertEqual(x['a'],     1_0					)




      def 			a__							(self					):

       '''simple docstring'''



       lowerCamelCase__     :			str     				=						ModelOutputTest({'a': 3_0, 'b': 1_0}					)
       self.assertEqual(list(x.keys()					),     ['a', 'b']					)
       self.assertEqual(x.a,     3_0					)
       self.assertEqual(x.b,     1_0					)





      def 			a__							(self					):

       '''simple docstring'''



       lowerCamelCase__     :			List[Any]     				=						ModelOutputTest([('a', 3_0), ('b', 1_0)]					)
       self.assertEqual(list(x.keys()					),     ['a', 'b']					)
       self.assertEqual(x.a,     3_0					)
       self.assertEqual(x.b,     1_0					)

       with self.assertRaises(lowerCamelCase_					):
        lowerCamelCase__     :			Union[str, Any]     				=						ModelOutputTest([('a', 3_0), (1_0, 1_0)]					)

       lowerCamelCase__     :			Optional[Any]     				=						ModelOutputTest(a=(3_0, 3_0)					)
       self.assertEqual(list(x.keys()					),     ['a']					)
       self.assertEqual(x.a,     (3_0, 3_0)					)



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






			'''simple docstring'''

			def __init__(				self       :				Optional[int]  ,		snake_case_       :				Optional[Any]  ,		snake_case_       :				List[Any]=7  ,		snake_case_       :				int=3  ,		snake_case_       :				Tuple=18  ,		snake_case_       :				List[Any]=30  ,		snake_case_       :				Tuple=400  ,		snake_case_       :				Dict=True  ,		snake_case_       :				List[str]=None  ,		snake_case_       :				Any=True  ,		snake_case_       :				str=[0.5, 0.5, 0.5]  ,		snake_case_       :				Optional[Any]=[0.5, 0.5, 0.5]  ,		):
							UpperCamelCase_:							int		=  size if size is not None else {"""height""": 18, """width""": 18}
							UpperCamelCase_:							Any		=  parent
							UpperCamelCase_:							List[str]		=  batch_size
							UpperCamelCase_:							Union[str, Any]		=  num_channels
							UpperCamelCase_:							str		=  image_size
							UpperCamelCase_:							Optional[int]		=  min_resolution
							UpperCamelCase_:							Optional[Any]		=  max_resolution
							UpperCamelCase_:							Dict		=  do_resize
							UpperCamelCase_:							Union[str, Any]		=  size
							UpperCamelCase_:							Optional[Any]		=  do_normalize
							UpperCamelCase_:							str		=  image_mean
							UpperCamelCase_:							int		=  image_std




			def 					lowerCAmelCase__		(				self       :				Tuple					):
							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 				_UpperCamelCase (    _A   ,				unittest.TestCase     ):






			'''simple docstring'''

			__UpperCamelCase					:  str    					=       ViTImageProcessor if is_vision_available() else None

			def 					lowerCAmelCase__		(				self       :				Any					):
							UpperCamelCase_:							Tuple		=  ViTImageProcessingTester(self					)

			@property
			def 					lowerCAmelCase__		(				self       :				Union[str, Any]					):
							return self.image_processor_tester.prepare_image_processor_dict()

			def 					lowerCAmelCase__		(				self       :				int					):
							UpperCamelCase_:							Union[str, Any]		=  self.image_processing_class(**self.image_processor_dict					)
							self.assertTrue(hasattr(snake_case_  ,		"""image_mean"""					)					)
							self.assertTrue(hasattr(snake_case_  ,		"""image_std"""					)					)
							self.assertTrue(hasattr(snake_case_  ,		"""do_normalize"""					)					)
							self.assertTrue(hasattr(snake_case_  ,		"""do_resize"""					)					)
							self.assertTrue(hasattr(snake_case_  ,		"""size"""					)					)

			def 					lowerCAmelCase__		(				self       :				Optional[Any]					):
							UpperCamelCase_:							Optional[Any]		=  self.image_processing_class.from_dict(self.image_processor_dict					)
							self.assertEqual(image_processor.size  ,		{"""height""": 18, """width""": 18}					)

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

			def 					lowerCAmelCase__		(				self       :				int					):
							pass

			def 					lowerCAmelCase__		(				self       :				int					):
							# Initialize image_processing
							UpperCamelCase_:							List[str]		=  self.image_processing_class(**self.image_processor_dict					)
							# create random PIL images
							UpperCamelCase_:							List[Any]		=  prepare_image_inputs(self.image_processor_tester  ,		equal_resolution=snake_case_					)
							for image in image_inputs:
											self.assertIsInstance(snake_case_  ,		Image.Image					)

							# 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(snake_case_  ,		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 					lowerCAmelCase__		(				self       :				str					):
							# Initialize image_processing
							UpperCamelCase_:							List[str]		=  self.image_processing_class(**self.image_processor_dict					)
							# create random numpy tensors
							UpperCamelCase_:							Tuple		=  prepare_image_inputs(self.image_processor_tester  ,		equal_resolution=snake_case_  ,		numpify=snake_case_					)
							for image in image_inputs:
											self.assertIsInstance(snake_case_  ,		np.ndarray					)

							# Test not batched input
							UpperCamelCase_:							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_:							Dict		=  image_processing(snake_case_  ,		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 					lowerCAmelCase__		(				self       :				Any					):
							# Initialize image_processing
							UpperCamelCase_:							int		=  self.image_processing_class(**self.image_processor_dict					)
							# create random PyTorch tensors
							UpperCamelCase_:							Dict		=  prepare_image_inputs(self.image_processor_tester  ,		equal_resolution=snake_case_  ,		torchify=snake_case_					)
							for image in image_inputs:
											self.assertIsInstance(snake_case_  ,		torch.Tensor					)

							# Test not batched input
							UpperCamelCase_:							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
							UpperCamelCase_:							Any		=  image_processing(snake_case_  ,		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"""],
							    )  ,		)






