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












import os
import tempfile
import unittest
from typing import List

from transformers.models.esm.tokenization_esm import VOCAB_FILES_NAMES, EsmTokenizer
from transformers.testing_utils import require_tokenizers
from transformers.tokenization_utils import PreTrainedTokenizer
from transformers.tokenization_utils_base import PreTrainedTokenizerBase





@require_tokenizers
class  __lowerCamelCase       (    unittest.TestCase    ):




    """simple docstring"""

    snake_case__					=      EsmTokenizer


    def    a      (       self     :     str   )      ->       Tuple:
         super().setUp()
         lowerCAmelCase__		= tempfile.mkdtemp()
         # fmt: off
         lowerCAmelCase__		= ["<cls>", "<pad>", "<eos>", "<unk>", "L", "A", "G", "V", "S", "E", "R", "T", "I", "D", "P", "K", "Q", "N", "F", "Y", "M", "H", "W", "C", "X", "B", "U", "Z", "O", ".", "-", "<null_1>", "<mask>"]  # noqa: E501
         # fmt: on
         lowerCAmelCase__		= os.path.join(self.tmpdirname   ,	VOCAB_FILES_NAMES["vocab_file"]   )
         with open(self.vocab_file   ,	"w"   ,	encoding="utf-8"   ) as vocab_writer:
              vocab_writer.write("".join([x + "\n" for x in vocab_tokens]   )   )


    def    a      (       self     :     Dict   ,	**SCREAMING_SNAKE_CASE__     :     Optional[Any]   )      ->       List[PreTrainedTokenizerBase]:
         return [self.get_tokenizer(**SCREAMING_SNAKE_CASE__   )]


    def    a      (       self     :     List[str]   ,	**SCREAMING_SNAKE_CASE__     :     str   )      ->       PreTrainedTokenizer:
         return self.tokenizer_class.from_pretrained(self.tmpdirname   ,	**SCREAMING_SNAKE_CASE__   )


    def    a      (       self     :     str   )      ->       Tuple:
         lowerCAmelCase__		= self.tokenizer_class(self.vocab_file   )

         lowerCAmelCase__		= tokenizer.tokenize("LAGVS"   )
         self.assertListEqual(SCREAMING_SNAKE_CASE__   ,	["L", "A", "G", "V", "S"]   )
         self.assertListEqual(tokenizer.convert_tokens_to_ids(SCREAMING_SNAKE_CASE__   )   ,	[4, 5, 6, 7, 8]   )


    def    a      (       self     :     int   )      ->       Union[str, Any]:
         lowerCAmelCase__		= self.tokenizer_class(self.vocab_file   )

         lowerCAmelCase__		= "LAGVS"
         self.assertListEqual(tokenizer.encode(SCREAMING_SNAKE_CASE__   )   ,	[0, 4, 5, 6, 7, 8, 2]   )


    def    a      (       self     :     Union[str, Any]   )      ->       str:
         lowerCAmelCase__		= self.tokenizer_class(self.vocab_file   )

         lowerCAmelCase__		= ["LAGVS", "WCB"]
         lowerCAmelCase__		= tokenizer(SCREAMING_SNAKE_CASE__   ,	padding=SCREAMING_SNAKE_CASE__   )["input_ids"]

         self.assertListEqual(SCREAMING_SNAKE_CASE__   ,	[[0, 4, 5, 6, 7, 8, 2], [0, 22, 23, 25, 2]]   )


    def    a      (       self     :     Any   )      ->       Union[str, Any]:
         lowerCAmelCase__		= self.tokenizer_class(self.vocab_file   )

         lowerCAmelCase__		= ["LAGVS", "WCB"]
         lowerCAmelCase__		= tokenizer(SCREAMING_SNAKE_CASE__   ,	padding=SCREAMING_SNAKE_CASE__   )["input_ids"]

         self.assertListEqual(SCREAMING_SNAKE_CASE__   ,	[[0, 4, 5, 6, 7, 8, 2], [0, 22, 23, 25, 2, 1, 1]]   )


    def    a      (       self     :     str   )      ->       Optional[Any]:
         lowerCAmelCase__		= self.get_tokenizers(fast=SCREAMING_SNAKE_CASE__   )
         for tokenizer in tokenizers:
              with self.subTest(f'{tokenizer.__class__.__name__}'   ):
                   lowerCAmelCase__		= "<unk>"
                   lowerCAmelCase__		= "<mask>"

                   lowerCAmelCase__		= tokenizer.tokenize(SCREAMING_SNAKE_CASE__   )
                   lowerCAmelCase__		= tokenizer.tokenize(SCREAMING_SNAKE_CASE__   )

                   self.assertEqual(len(SCREAMING_SNAKE_CASE__   )   ,	1   )
                   self.assertEqual(len(SCREAMING_SNAKE_CASE__   )   ,	1   )
                   self.assertEqual(token_a[0]   ,	SCREAMING_SNAKE_CASE__   )
                   self.assertEqual(token_a[0]   ,	SCREAMING_SNAKE_CASE__   )
