



from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_sentencepiece_available, is_tokenizers_available


A__						:						int          =      {}

try:
						if not is_sentencepiece_available():
												raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
						pass
else:
						A__						:						int          =      ['''MBart50Tokenizer''']

try:
						if not is_tokenizers_available():
												raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
						pass
else:
						A__						:						Optional[Any]          =      ['''MBart50TokenizerFast''']


if TYPE_CHECKING:
						try:
												if not is_sentencepiece_available():
																		raise OptionalDependencyNotAvailable()
						except OptionalDependencyNotAvailable:
												pass
						else:
												from .tokenization_mbartaa import MBartaaTokenizer

						try:
												if not is_tokenizers_available():
																		raise OptionalDependencyNotAvailable()
						except OptionalDependencyNotAvailable:
												pass
						else:
												from .tokenization_mbartaa_fast import MBartaaTokenizerFast

else:
						import sys

						A__						:						Dict          =      _LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)










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 DeiTImageProcessor



class        __snake_case		(  unittest.TestCase		):




							def __init__( self  : Union[str, Any]       ,       A_  : Optional[Any]       ,       A_  : Optional[Any]=7       ,       A_  : str=3       ,       A_  : Optional[Any]=1_8       ,       A_  : Union[str, Any]=3_0       ,       A_  : str=4_0_0       ,       A_  : List[str]=True       ,       A_  : str=None       ,       A_  : str=True       ,       A_  : List[Any]=None       ,       A_  : List[Any]=True       ,       A_  : Optional[Any]=[0.5, 0.5, 0.5]       ,       A_  : Optional[int]=[0.5, 0.5, 0.5]       ,       ):
									lowerCAmelCase_    :  List[str]             =				size if size is not None else {'''height''': 2_0, '''width''': 2_0}
									lowerCAmelCase_    :  List[Any]             =				crop_size if crop_size is not None else {'''height''': 1_8, '''width''': 1_8}

									lowerCAmelCase_    :  str             =				parent
									lowerCAmelCase_    :  Union[str, Any]             =				batch_size
									lowerCAmelCase_    :  Optional[Any]             =				num_channels
									lowerCAmelCase_    :  List[str]             =				image_size
									lowerCAmelCase_    :  List[str]             =				min_resolution
									lowerCAmelCase_    :  Union[str, Any]             =				max_resolution
									lowerCAmelCase_    :  Optional[int]             =				do_resize
									lowerCAmelCase_    :  Dict             =				size
									lowerCAmelCase_    :  Dict             =				do_center_crop
									lowerCAmelCase_    :  str             =				crop_size
									lowerCAmelCase_    :  List[Any]             =				do_normalize
									lowerCAmelCase_    :  str             =				image_mean
									lowerCAmelCase_    :  Dict             =				image_std







							def      UpperCAmelCase__    ( self  : int):
									return {
									    "do_resize": self.do_resize,
									    "size": self.size,
									    "do_center_crop": self.do_center_crop,
									    "crop_size": self.crop_size,
									    "do_normalize": self.do_normalize,
									    "image_mean": self.image_mean,
									    "image_std": self.image_std,
									}





@require_torch
@require_vision
class        __snake_case		(  UpperCamelCase_		,unittest.TestCase		):
							_a       =				DeiTImageProcessor if is_vision_available() else None
							_a       =				True




							def      UpperCAmelCase__    ( self  : Tuple):
									lowerCAmelCase_    :  int             =				DeiTImageProcessingTester(self)




							@property
							def      UpperCAmelCase__    ( self  : Optional[Any]):
									return self.image_processor_tester.prepare_image_processor_dict()




							def      UpperCAmelCase__    ( self  : str):
									lowerCAmelCase_    :  List[Any]             =				self.image_processing_class(**self.image_processor_dict)
									self.assertTrue(hasattr(A_       ,       '''do_resize'''))
									self.assertTrue(hasattr(A_       ,       '''size'''))
									self.assertTrue(hasattr(A_       ,       '''do_center_crop'''))
									self.assertTrue(hasattr(A_       ,       '''center_crop'''))
									self.assertTrue(hasattr(A_       ,       '''do_normalize'''))
									self.assertTrue(hasattr(A_       ,       '''image_mean'''))
									self.assertTrue(hasattr(A_       ,       '''image_std'''))




							def      UpperCAmelCase__    ( self  : Union[str, Any]):
									lowerCAmelCase_    :  Tuple             =				self.image_processing_class.from_dict(self.image_processor_dict)
									self.assertEqual(image_processor.size       ,       {'''height''': 2_0, '''width''': 2_0})
									self.assertEqual(image_processor.crop_size       ,       {'''height''': 1_8, '''width''': 1_8})

									lowerCAmelCase_    :  Any             =				self.image_processing_class.from_dict(self.image_processor_dict       ,       size=4_2       ,       crop_size=8_4)
									self.assertEqual(image_processor.size       ,       {'''height''': 4_2, '''width''': 4_2})
									self.assertEqual(image_processor.crop_size       ,       {'''height''': 8_4, '''width''': 8_4})




							def      UpperCAmelCase__    ( self  : Union[str, Any]):
									pass




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

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

									# Test batched
									lowerCAmelCase_    :  Dict             =				image_processing(A_       ,       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.crop_size['''height'''],
									        self.image_processor_tester.crop_size['''width'''],
									    )       ,       )




							def      UpperCAmelCase__    ( self  : List[str]):
									# Initialize image_processing
									lowerCAmelCase_    :  Union[str, Any]             =				self.image_processing_class(**self.image_processor_dict)
									# create random numpy tensors
									lowerCAmelCase_    :  Union[str, Any]             =				prepare_image_inputs(self.image_processor_tester       ,       equal_resolution=A_       ,       numpify=A_)
									for image in image_inputs:
											self.assertIsInstance(A_       ,       np.ndarray)

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

									# Test batched
									lowerCAmelCase_    :  str             =				image_processing(A_       ,       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.crop_size['''height'''],
									        self.image_processor_tester.crop_size['''width'''],
									    )       ,       )







							def      UpperCAmelCase__    ( self  : Any):
									# Initialize image_processing
									lowerCAmelCase_    :  str             =				self.image_processing_class(**self.image_processor_dict)
									# create random PyTorch tensors
									lowerCAmelCase_    :  Union[str, Any]             =				prepare_image_inputs(self.image_processor_tester       ,       equal_resolution=A_       ,       torchify=A_)
									for image in image_inputs:
											self.assertIsInstance(A_       ,       torch.Tensor)

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

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





