




'''simple docstring'''





import shutil
import tempfile
import unittest

import numpy as np
import pytest

from transformers import is_speech_available, is_vision_available
from transformers.testing_utils import require_torch


if is_vision_available():
		from transformers import TvltImageProcessor

if is_speech_available():
		from transformers import TvltFeatureExtractor

from transformers import TvltProcessor




@require_torch
class  _snake_case		(	unittest.TestCase							):




			def    lowerCAmelCase__				(					self							)				->				Optional[int]:

										'''simple docstring'''




										snake_case_						=      "ZinengTang/tvlt-base"
										snake_case_						=      tempfile.mkdtemp()




			def    lowerCAmelCase__				(					self				,							**a__							)				->				Any:

										'''simple docstring'''




										return TvltImageProcessor.from_pretrained(self.checkpoint				,							**a__							)




			def    lowerCAmelCase__				(					self				,							**a__							)				->				Union[str, Any]:

										'''simple docstring'''




										return TvltFeatureExtractor.from_pretrained(self.checkpoint				,							**a__							)




			def    lowerCAmelCase__				(					self							)				->				Any:

										'''simple docstring'''




										shutil.rmtree(self.tmpdirname							)




			def    lowerCAmelCase__				(					self							)				->				Union[str, Any]:

										'''simple docstring'''




										snake_case_						=      self.get_image_processor()
										snake_case_						=      self.get_feature_extractor()

										snake_case_						=      TvltProcessor(image_processor=a__				,							feature_extractor=a__							)
										processor.save_pretrained(self.tmpdirname							)
										snake_case_						=      TvltProcessor.from_pretrained(self.tmpdirname							)

										self.assertIsInstance(processor.feature_extractor				,							a__							)
										self.assertIsInstance(processor.image_processor				,							a__							)




			def    lowerCAmelCase__				(					self							)				->				Union[str, Any]:

										'''simple docstring'''




										snake_case_						=      self.get_image_processor()
										snake_case_						=      self.get_feature_extractor()

										snake_case_						=      TvltProcessor(image_processor=a__				,							feature_extractor=a__							)

										snake_case_						=      np.ones([12_000]							)

										snake_case_						=      feature_extractor(a__				,							return_tensors="np"							)
										snake_case_						=      processor(audio=a__				,							return_tensors="np"							)

										for key in audio_dict.keys():
																	self.assertAlmostEqual(audio_dict[key].sum()				,							input_processor[key].sum()				,							delta=1e-2							)




			def    lowerCAmelCase__				(					self							)				->				Optional[int]:

										'''simple docstring'''




										snake_case_						=      self.get_image_processor()
										snake_case_						=      self.get_feature_extractor()

										snake_case_						=      TvltProcessor(image_processor=a__				,							feature_extractor=a__							)

										snake_case_						=      np.ones([3, 224, 224]							)

										snake_case_						=      image_processor(a__				,							return_tensors="np"							)
										snake_case_						=      processor(images=a__				,							return_tensors="np"							)

										for key in image_dict.keys():
																	self.assertAlmostEqual(image_dict[key].sum()				,							input_processor[key].sum()				,							delta=1e-2							)




			def    lowerCAmelCase__				(					self							)				->				Any:

										'''simple docstring'''




										snake_case_						=      self.get_image_processor()
										snake_case_						=      self.get_feature_extractor()

										snake_case_						=      TvltProcessor(image_processor=a__				,							feature_extractor=a__							)

										snake_case_						=      np.ones([12_000]							)
										snake_case_						=      np.ones([3, 224, 224]							)

										snake_case_						=      processor(audio=a__				,							images=a__							)

										self.assertListEqual(list(inputs.keys()							)				,							["audio_values", "audio_mask", "pixel_values", "pixel_mask"]							)

										# test if it raises when no input is passed
										with pytest.raises(a__							):
																	processor()




			def    lowerCAmelCase__				(					self							)				->				Union[str, Any]:

										'''simple docstring'''




										snake_case_						=      self.get_image_processor()
										snake_case_						=      self.get_feature_extractor()

										snake_case_						=      TvltProcessor(image_processor=a__				,							feature_extractor=a__							)

										self.assertListEqual(
										    processor.model_input_names				,							image_processor.model_input_names + feature_extractor.model_input_names				,							msg="`processor` and `image_processor`+`feature_extractor` model input names do not match"				,							)









'''simple docstring'''

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__						(    _UpperCamelCase			,						unittest.TestCase   ):
							lowerCAmelCase       :    str   				=					LayoutLMTokenizer
							lowerCAmelCase       :    Tuple   				=					LayoutLMTokenizerFast
							lowerCAmelCase       :    List[Any]   				=					True
							lowerCAmelCase       :    int   				=					True







							def 							__lowercase			(							self					:       Dict		):
									super().setUp()

									_a     :      int        =							[
									    '[UNK]',
									    '[CLS]',
									    '[SEP]',
									    'want',
									    '##want',
									    '##ed',
									    'wa',
									    'un',
									    'runn',
									    '##ing',
									    ',',
									    'low',
									    'lowest',
									]
									_a     :      List[str]        =							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 							__lowercase			(							self					:       Dict	,**_UpperCAmelCase					:       List[str]		):
									return LayoutLMTokenizer.from_pretrained(self.tmpdirname	,**_UpperCAmelCase		)







							def 							__lowercase			(							self					:       Optional[Any]	,_UpperCAmelCase					:       Tuple		):
									_a     :      Optional[int]        =							'UNwant\u00E9d,running'
									_a     :      List[Any]        =							'unwanted, running'
									return input_text, output_text







							def 							__lowercase			(							self					:       Optional[int]		):
									_a     :      Optional[Any]        =							self.tokenizer_class(self.vocab_file		)

									_a     :      Optional[Any]        =							tokenizer.tokenize('UNwant\u00E9d,running'		)
									self.assertListEqual(_UpperCAmelCase	,['un', '##want', '##ed', ',', 'runn', '##ing']		)
									self.assertListEqual(tokenizer.convert_tokens_to_ids(_UpperCAmelCase		)	,[7, 4, 5, 10, 8, 9]		)







							def 							__lowercase			(							self					:       Optional[int]		):
									pass




