





from tempfile import TemporaryDirectory
from unittest import TestCase
from unittest.mock import MagicMock, patch

from transformers import AutoModel, TFAutoModel
from transformers.onnx import FeaturesManager
from transformers.testing_utils import SMALL_MODEL_IDENTIFIER, require_tf, require_torch





@require_torch
@require_tf
class 				a			(      __lowercase			):






				def 			snake_case_    (  self					):

										"""simple docstring"""




										__SCREAMING_SNAKE_CASE:				int           =   SMALL_MODEL_IDENTIFIER
										__SCREAMING_SNAKE_CASE:				Dict           =   '''pt'''
										__SCREAMING_SNAKE_CASE:				Tuple           =   '''tf'''






				def 			snake_case_    (  self			, _lowerCAmelCase					):

										"""simple docstring"""




										__SCREAMING_SNAKE_CASE:				str           =   AutoModel.from_pretrained(self.test_model					)
										model_pt.save_pretrained(_lowercase					)






				def 			snake_case_    (  self			, _lowerCAmelCase					):

										"""simple docstring"""




										__SCREAMING_SNAKE_CASE:				str           =   TFAutoModel.from_pretrained(self.test_model			, from_pt=_lowercase					)
										model_tf.save_pretrained(_lowercase					)






				def 			snake_case_    (  self					):

										"""simple docstring"""




										__SCREAMING_SNAKE_CASE:				Tuple           =   '''mock_framework'''

										# Framework provided - return whatever the user provides
										__SCREAMING_SNAKE_CASE:				List[str]           =   FeaturesManager.determine_framework(self.test_model			, _lowercase					)
										self.assertEqual(_lowercase			, _lowercase					)

										# Local checkpoint and framework provided - return provided framework
										# PyTorch checkpoint
										with TemporaryDirectory() as local_pt_ckpt:
																self._setup_pt_ckpt(_lowercase					)
																__SCREAMING_SNAKE_CASE:				Optional[Any]           =   FeaturesManager.determine_framework(_lowercase			, _lowercase					)
																self.assertEqual(_lowercase			, _lowercase					)

										# TensorFlow checkpoint
										with TemporaryDirectory() as local_tf_ckpt:
																self._setup_tf_ckpt(_lowercase					)
																__SCREAMING_SNAKE_CASE:				Optional[Any]           =   FeaturesManager.determine_framework(_lowercase			, _lowercase					)
																self.assertEqual(_lowercase			, _lowercase					)






				def 			snake_case_    (  self					):

										"""simple docstring"""




										with TemporaryDirectory() as local_pt_ckpt:
																self._setup_pt_ckpt(_lowercase					)
																__SCREAMING_SNAKE_CASE:				Tuple           =   FeaturesManager.determine_framework(_lowercase					)
																self.assertEqual(_lowercase			, self.framework_pt					)

										# TensorFlow checkpoint
										with TemporaryDirectory() as local_tf_ckpt:
																self._setup_tf_ckpt(_lowercase					)
																__SCREAMING_SNAKE_CASE:				Optional[Any]           =   FeaturesManager.determine_framework(_lowercase					)
																self.assertEqual(_lowercase			, self.framework_tf					)

										# Invalid local checkpoint
										with TemporaryDirectory() as local_invalid_ckpt:
																with self.assertRaises(_lowercase					):
																						__SCREAMING_SNAKE_CASE:				str           =   FeaturesManager.determine_framework(_lowercase					)






				def 			snake_case_    (  self					):

										"""simple docstring"""




										__SCREAMING_SNAKE_CASE:				int           =   MagicMock(return_value=_lowercase					)
										with patch('''transformers.onnx.features.is_tf_available'''			, _lowercase					):
																__SCREAMING_SNAKE_CASE:				Optional[Any]           =   FeaturesManager.determine_framework(self.test_model					)
																self.assertEqual(_lowercase			, self.framework_pt					)

										# PyTorch not in environment -> use TensorFlow
										__SCREAMING_SNAKE_CASE:				Tuple           =   MagicMock(return_value=_lowercase					)
										with patch('''transformers.onnx.features.is_torch_available'''			, _lowercase					):
																__SCREAMING_SNAKE_CASE:				Union[str, Any]           =   FeaturesManager.determine_framework(self.test_model					)
																self.assertEqual(_lowercase			, self.framework_tf					)

										# Both in environment -> use PyTorch
										__SCREAMING_SNAKE_CASE:				int           =   MagicMock(return_value=_lowercase					)
										__SCREAMING_SNAKE_CASE:				List[Any]           =   MagicMock(return_value=_lowercase					)
										with patch('''transformers.onnx.features.is_tf_available'''			, _lowercase					), patch(
										    '''transformers.onnx.features.is_torch_available'''			, _lowercase					):
																__SCREAMING_SNAKE_CASE:				Optional[int]           =   FeaturesManager.determine_framework(self.test_model					)
																self.assertEqual(_lowercase			, self.framework_pt					)

										# Both not in environment -> raise error
										__SCREAMING_SNAKE_CASE:				List[str]           =   MagicMock(return_value=_lowercase					)
										__SCREAMING_SNAKE_CASE:				Tuple           =   MagicMock(return_value=_lowercase					)
										with patch('''transformers.onnx.features.is_tf_available'''			, _lowercase					), patch(
										    '''transformers.onnx.features.is_torch_available'''			, _lowercase					):
																with self.assertRaises(_lowercase					):
																						__SCREAMING_SNAKE_CASE:				Dict           =   FeaturesManager.determine_framework(self.test_model					)






import os
import unittest

from transformers import LayoutLMTokenizer, LayoutLMTokenizerFast
from transformers.models.layoutlm.tokenization_layoutlm import VOCAB_FILES_NAMES
from transformers.testing_utils import require_tokenizers

from ...test_tokenization_common import TokenizerTesterMixin






@require_tokenizers
class 						__magic_name__					(							snake_case			,      unittest.TestCase				):
     UpperCamelCase_	:List[Any]										=      LayoutLMTokenizer
     UpperCamelCase_	:Dict										=      LayoutLMTokenizerFast
     UpperCamelCase_	:List[str]										=      True
     UpperCamelCase_	:Dict										=      True






     def 	UpperCAmelCase_				(				self	)->     str:
         super().setUp()

         UpperCamelCase_			  =						[
             "[UNK]",
             "[CLS]",
             "[SEP]",
             "want",
             "##want",
             "##ed",
             "wa",
             "un",
             "runn",
             "##ing",
             ",",
             "low",
             "lowest",
         ]
         UpperCamelCase_			  =						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 	UpperCAmelCase_				(				self		,						**_lowercase	)->     List[str]:
         return LayoutLMTokenizer.from_pretrained(self.tmpdirname		,						**_lowercase	)






     def 	UpperCAmelCase_				(				self		,						_lowercase	)->     Union[str, Any]:
         UpperCamelCase_			  =						"UNwant\u00E9d,running"
         UpperCamelCase_			  =						"unwanted, running"
         return input_text, output_text






     def 	UpperCAmelCase_				(				self	)->     Tuple:
         UpperCamelCase_			  =						self.tokenizer_class(self.vocab_file	)

         UpperCamelCase_			  =						tokenizer.tokenize("UNwant\u00E9d,running"	)
         self.assertListEqual(_lowercase		,						["un", "##want", "##ed", ",", "runn", "##ing"]	)
         self.assertListEqual(tokenizer.convert_tokens_to_ids(_lowercase	)		,						[7, 4, 5, 10, 8, 9]	)






     def 	UpperCAmelCase_				(				self	)->     Dict:
         pass
