






'''simple docstring'''





import shutil
import tempfile
import unittest

import pytest

from transformers import WhisperTokenizer, is_speech_available
from transformers.testing_utils import require_sentencepiece, require_torch, require_torchaudio

from .test_feature_extraction_whisper import floats_list


if is_speech_available():
							from transformers import WhisperFeatureExtractor, WhisperProcessor


a_      = 50_358
a_      = 50_362





@require_torch
@require_torchaudio
@require_sentencepiece
class 		SCREAMING_SNAKE_CASE__   (     unittest.TestCase    ):



		def _lowerCAmelCase     (    self:    Optional[Any])  ->List[str]:






								'''simple docstring'''


								a_				     =   "openai/whisper-small.en"
								a_				     =   tempfile.mkdtemp()



		def _lowerCAmelCase     (    self:    Any				,   **a:    int)  ->Any:






								'''simple docstring'''


								return WhisperTokenizer.from_pretrained(self.checkpoint				,   **a)



		def _lowerCAmelCase     (    self:    Any				,   **a:    List[str])  ->Any:






								'''simple docstring'''


								return WhisperFeatureExtractor.from_pretrained(self.checkpoint				,   **a)



		def _lowerCAmelCase     (    self:    List[str])  ->Tuple:






								'''simple docstring'''


								shutil.rmtree(self.tmpdirname)



		def _lowerCAmelCase     (    self:    List[str])  ->Dict:






								'''simple docstring'''


								a_				     =   self.get_tokenizer()
								a_				     =   self.get_feature_extractor()

								a_				     =   WhisperProcessor(tokenizer=a				,   feature_extractor=a)

								processor.save_pretrained(self.tmpdirname)
								a_				     =   WhisperProcessor.from_pretrained(self.tmpdirname)

								self.assertEqual(processor.tokenizer.get_vocab()				,   tokenizer.get_vocab())
								self.assertIsInstance(processor.tokenizer				,   a)

								self.assertEqual(processor.feature_extractor.to_json_string()				,   feature_extractor.to_json_string())
								self.assertIsInstance(processor.feature_extractor				,   a)



		def _lowerCAmelCase     (    self:    Dict)  ->List[str]:






								'''simple docstring'''


								a_				     =   WhisperProcessor(tokenizer=self.get_tokenizer()				,   feature_extractor=self.get_feature_extractor())
								processor.save_pretrained(self.tmpdirname)

								a_				     =   self.get_tokenizer(bos_token="(BOS)"				,   eos_token="(EOS)")
								a_				     =   self.get_feature_extractor(do_normalize=a				,   padding_value=1.0)

								a_				     =   WhisperProcessor.from_pretrained(
								    self.tmpdirname				,   bos_token="(BOS)"				,   eos_token="(EOS)"				,   do_normalize=a				,   padding_value=1.0)

								self.assertEqual(processor.tokenizer.get_vocab()				,   tokenizer_add_kwargs.get_vocab())
								self.assertIsInstance(processor.tokenizer				,   a)

								self.assertEqual(processor.feature_extractor.to_json_string()				,   feature_extractor_add_kwargs.to_json_string())
								self.assertIsInstance(processor.feature_extractor				,   a)



		def _lowerCAmelCase     (    self:    Optional[Any])  ->List[str]:






								'''simple docstring'''


								a_				     =   self.get_feature_extractor()
								a_				     =   self.get_tokenizer()

								a_				     =   WhisperProcessor(tokenizer=a				,   feature_extractor=a)

								a_				     =   floats_list((3, 10_00))

								a_				     =   feature_extractor(a				,   return_tensors="np")
								a_				     =   processor(a				,   return_tensors="np")

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



		def _lowerCAmelCase     (    self:    Tuple)  ->int:






								'''simple docstring'''


								a_				     =   self.get_feature_extractor()
								a_				     =   self.get_tokenizer()

								a_				     =   WhisperProcessor(tokenizer=a				,   feature_extractor=a)

								a_				     =   "This is a test string"

								a_				     =   processor(text=a)

								a_				     =   tokenizer(a)

								for key in encoded_tok.keys():
														self.assertListEqual(encoded_tok[key]				,   encoded_processor[key])



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






								'''simple docstring'''


								a_				     =   self.get_feature_extractor()
								a_				     =   self.get_tokenizer()

								a_				     =   WhisperProcessor(tokenizer=a				,   feature_extractor=a)

								a_				     =   [[1, 4, 5, 8, 1, 0, 8], [3, 4, 3, 1, 1, 8, 9]]

								a_				     =   processor.batch_decode(a)
								a_				     =   tokenizer.batch_decode(a)

								self.assertListEqual(a				,   a)



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






								'''simple docstring'''


								a_				     =   self.get_feature_extractor()
								a_				     =   self.get_tokenizer()

								a_				     =   WhisperProcessor(tokenizer=a				,   feature_extractor=a)

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



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






								'''simple docstring'''


								a_				     =   self.get_feature_extractor()
								a_				     =   self.get_tokenizer()

								a_				     =   WhisperProcessor(tokenizer=a				,   feature_extractor=a)
								a_				     =   processor.get_decoder_prompt_ids(task="transcribe"				,   no_timestamps=a)

								self.assertIsInstance(a				,   a)
								for ids in forced_decoder_ids:
														self.assertIsInstance(a				,   (list, tuple))

								a_				     =   [TRANSCRIBE, NOTIMESTAMPS]
								self.assertListEqual([ids[-1] for ids in forced_decoder_ids]				,   a)



		def _lowerCAmelCase     (    self:    List[str])  ->int:






								'''simple docstring'''


								a_				     =   WhisperProcessor(tokenizer=self.get_tokenizer()				,   feature_extractor=self.get_feature_extractor())
								a_				     =   processor.get_prompt_ids("Mr. Quilter")
								a_				     =   processor.tokenizer.decode(a)

								self.assertListEqual(prompt_ids.tolist()				,   [5_03_60, 17_70, 13, 22_64, 3_46, 3_53])
								self.assertEqual(a				,   "<|startofprev|> Mr. Quilter")



		def _lowerCAmelCase     (    self:    str)  ->Optional[Any]:






								'''simple docstring'''


								a_				     =   WhisperProcessor(tokenizer=self.get_tokenizer()				,   feature_extractor=self.get_feature_extractor())
								a_				     =   processor.get_prompt_ids("")
								a_				     =   processor.tokenizer.decode(a)

								self.assertListEqual(prompt_ids.tolist()				,   [5_03_60, 2_20])
								self.assertEqual(a				,   "<|startofprev|> ")




		def _lowerCAmelCase     (    self:    List[str])  ->int:






								'''simple docstring'''


								a_				     =   WhisperProcessor(tokenizer=self.get_tokenizer()				,   feature_extractor=self.get_feature_extractor())

								def _test_prompt_error_raised_helper(a:    List[str]				,   a:    Union[str, Any]):
														with pytest.raises(a) as excinfo:
																				processor.get_prompt_ids(a)
														a_				     =   f"""Encountered text in the prompt corresponding to disallowed special token: {special_token}."""
														self.assertEqual(a				,   str(excinfo.value))

								_test_prompt_error_raised_helper("<|startofprev|> test"				,   "<|startofprev|>")
								_test_prompt_error_raised_helper("test <|notimestamps|>"				,   "<|notimestamps|>")
								_test_prompt_error_raised_helper("test <|zh|> test <|transcribe|>"				,   "<|zh|>")











'''simple docstring'''





from __future__ import annotations





class 		SCREAMING_SNAKE_CASE__   :



		def __init__(    self:    List[str]				,   a:    int = 0)  ->None:






								'''simple docstring'''


								a_				     =   value
								a_				     =   None
								a_				     =   None





def 			__UpperCAmelCase				(lowercase__	,lowercase__				)		->				Node | None:

						'''simple docstring'''


						if treea is None:
												return treea
						if treea is None:
												return treea

						a_				     =   treea.value + treea.value
						a_				     =   merge_two_binary_trees(treea.left	,treea.left				)
						a_				     =   merge_two_binary_trees(treea.right	,treea.right				)
						return treea



def 			__UpperCAmelCase				(lowercase__				)		->				None:

						'''simple docstring'''


						if root:
												print(root.value				)
												print_preorder(root.left				)
												print_preorder(root.right				)


if __name__ == "__main__":
							a_      = Node(1)
							a_      = Node(2)
							a_      = Node(3)
							a_      = Node(4)

							a_      = Node(2)
							a_      = Node(4)
							a_      = Node(6)
							a_      = Node(9)
							a_      = Node(5)

							print('Tree1 is: ')
							print_preorder(treea)
							print('Tree2 is: ')
							print_preorder(treea)
							a_      = merge_two_binary_trees(treea, treea)
							print('Merged Tree is: ')
							print_preorder(merged_tree)



