
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


UpperCamelCase_  =	5_03_58
UpperCamelCase_  =	5_03_62

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





				def        _UpperCAmelCase						(		self :		Dict							):


								"""simple docstring"""

								A     :  Optional[int]   =				'''openai/whisper-small.en'''
								A     :  List[str]   =				tempfile.mkdtemp()





				def        _UpperCAmelCase						(		self :		int					,      **snake_case_ :		int							):


								"""simple docstring"""

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





				def        _UpperCAmelCase						(		self :		Tuple					,      **snake_case_ :		Tuple							):


								"""simple docstring"""

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





				def        _UpperCAmelCase						(		self :		str							):


								"""simple docstring"""

								shutil.rmtree(self.tmpdirname							)





				def        _UpperCAmelCase						(		self :		List[Any]							):


								"""simple docstring"""

								A     :  List[str]   =				self.get_tokenizer()
								A     :  Optional[int]   =				self.get_feature_extractor()

								A     :  Dict   =				WhisperProcessor(tokenizer=snake_case_					,      feature_extractor=snake_case_							)

								processor.save_pretrained(self.tmpdirname							)
								A     :  List[Any]   =				WhisperProcessor.from_pretrained(self.tmpdirname							)

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

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





				def        _UpperCAmelCase						(		self :		Dict							):


								"""simple docstring"""

								A     :  Any   =				WhisperProcessor(tokenizer=self.get_tokenizer()					,      feature_extractor=self.get_feature_extractor()							)
								processor.save_pretrained(self.tmpdirname							)

								A     :  int   =				self.get_tokenizer(bos_token='''(BOS)'''					,      eos_token='''(EOS)'''							)
								A     :  int   =				self.get_feature_extractor(do_normalize=snake_case_					,      padding_value=1.0							)

								A     :  Dict   =				WhisperProcessor.from_pretrained(
								    self.tmpdirname					,      bos_token='''(BOS)'''					,      eos_token='''(EOS)'''					,      do_normalize=snake_case_					,      padding_value=1.0							)

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

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





				def        _UpperCAmelCase						(		self :		List[Any]							):


								"""simple docstring"""

								A     :  Union[str, Any]   =				self.get_feature_extractor()
								A     :  Tuple   =				self.get_tokenizer()

								A     :  Dict   =				WhisperProcessor(tokenizer=snake_case_					,      feature_extractor=snake_case_							)

								A     :  int   =				floats_list((3, 1000)							)

								A     :  Optional[int]   =				feature_extractor(snake_case_					,      return_tensors='''np'''							)
								A     :  Optional[Any]   =				processor(snake_case_					,      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        _UpperCAmelCase						(		self :		int							):


								"""simple docstring"""

								A     :  str   =				self.get_feature_extractor()
								A     :  int   =				self.get_tokenizer()

								A     :  List[str]   =				WhisperProcessor(tokenizer=snake_case_					,      feature_extractor=snake_case_							)

								A     :  Tuple   =				'''This is a test string'''

								A     :  Tuple   =				processor(text=snake_case_							)

								A     :  List[str]   =				tokenizer(snake_case_							)

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





				def        _UpperCAmelCase						(		self :		Union[str, Any]							):


								"""simple docstring"""

								A     :  Any   =				self.get_feature_extractor()
								A     :  List[str]   =				self.get_tokenizer()

								A     :  Tuple   =				WhisperProcessor(tokenizer=snake_case_					,      feature_extractor=snake_case_							)

								A     :  int   =				[[1, 4, 5, 8, 1, 0, 8], [3, 4, 3, 1, 1, 8, 9]]

								A     :  str   =				processor.batch_decode(snake_case_							)
								A     :  Optional[int]   =				tokenizer.batch_decode(snake_case_							)

								self.assertListEqual(snake_case_					,      snake_case_							)





				def        _UpperCAmelCase						(		self :		List[str]							):


								"""simple docstring"""

								A     :  Any   =				self.get_feature_extractor()
								A     :  Any   =				self.get_tokenizer()

								A     :  Union[str, Any]   =				WhisperProcessor(tokenizer=snake_case_					,      feature_extractor=snake_case_							)

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





				def        _UpperCAmelCase						(		self :		List[Any]							):


								"""simple docstring"""

								A     :  List[str]   =				self.get_feature_extractor()
								A     :  Tuple   =				self.get_tokenizer()

								A     :  Union[str, Any]   =				WhisperProcessor(tokenizer=snake_case_					,      feature_extractor=snake_case_							)
								A     :  Dict   =				processor.get_decoder_prompt_ids(task='''transcribe'''					,      no_timestamps=snake_case_							)

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

								A     :  Any   =				[TRANSCRIBE, NOTIMESTAMPS]
								self.assertListEqual([ids[-1] for ids in forced_decoder_ids]					,      snake_case_							)





				def        _UpperCAmelCase						(		self :		List[Any]							):


								"""simple docstring"""

								A     :  Optional[Any]   =				WhisperProcessor(tokenizer=self.get_tokenizer()					,      feature_extractor=self.get_feature_extractor()							)
								A     :  Any   =				processor.get_prompt_ids('''Mr. Quilter'''							)
								A     :  Union[str, Any]   =				processor.tokenizer.decode(snake_case_							)

								self.assertListEqual(prompt_ids.tolist()					,      [5_0360, 1770, 13, 2264, 346, 353]							)
								self.assertEqual(snake_case_					,      '''<|startofprev|> Mr. Quilter'''							)





				def        _UpperCAmelCase						(		self :		Optional[Any]							):


								"""simple docstring"""

								A     :  List[str]   =				WhisperProcessor(tokenizer=self.get_tokenizer()					,      feature_extractor=self.get_feature_extractor()							)
								A     :  Any   =				processor.get_prompt_ids(''''''							)
								A     :  Optional[int]   =				processor.tokenizer.decode(snake_case_							)

								self.assertListEqual(prompt_ids.tolist()					,      [5_0360, 220]							)
								self.assertEqual(snake_case_					,      '''<|startofprev|> '''							)






				def        _UpperCAmelCase						(		self :		Optional[Any]							):


								"""simple docstring"""

								A     :  int   =				WhisperProcessor(tokenizer=self.get_tokenizer()					,      feature_extractor=self.get_feature_extractor()							)

								def _test_prompt_error_raised_helper(snake_case_ :		Tuple					,      snake_case_ :		int							):
												with pytest.raises(snake_case_							) as excinfo:
																processor.get_prompt_ids(snake_case_							)
												A     :  Dict   =				f"""Encountered text in the prompt corresponding to disallowed special token: {special_token}."""
												self.assertEqual(snake_case_					,      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|>'''							)

UpperCamelCase_  =	{
    "0": 1,
    "1": 1,
    "2": 2,
    "3": 6,
    "4": 24,
    "5": 1_20,
    "6": 7_20,
    "7": 50_40,
    "8": 4_03_20,
    "9": 36_28_80,
}

UpperCamelCase_  =	{1_45: 1_45}

UpperCamelCase_  =	{
    1_45: 0,
    1_69: 3,
    3_63_01: 3,
    14_54: 3,
    8_71: 2,
    4_53_61: 2,
    8_72: 2,
}





def 							_lowerCamelCase			(					lowerCamelCase_:  int		):



				'''simple docstring'''







				if n in CACHE_SUM_DIGIT_FACTORIALS:
								return CACHE_SUM_DIGIT_FACTORIALS[n]
				A     :  Tuple   =				sum(DIGIT_FACTORIALS[let] for let in str(lowerCamelCase_		)		)
				A     :  Dict   =				ret
				return ret





def 							_lowerCamelCase			(					lowerCamelCase_:  int				,	lowerCamelCase_:  set | None = None		):



				'''simple docstring'''







				A     :  Optional[int]   =				previous or set()
				if n in CHAIN_LENGTH_CACHE:
								return CHAIN_LENGTH_CACHE[n]
				A     :  Dict   =				sum_digit_factorials(lowerCamelCase_		)
				if next_number in previous:
								A     :  Optional[int]   =				0
								return 0
				else:
								previous.add(lowerCamelCase_		)
								A     :  str   =				1 + chain_length(lowerCamelCase_				,	lowerCamelCase_		)
								A     :  Any   =				ret
								return ret





def 							_lowerCamelCase			(					lowerCamelCase_:  int = 60				,	lowerCamelCase_:  int = 100_0000		):



				'''simple docstring'''







				return sum(1 for i in range(1				,	lowerCamelCase_		) if chain_length(lowerCamelCase_		) == num_terms		)


if __name__ == "__main__":
					print(F'''{solution() = }''')