



'''simple docstring'''


import inspect
import json
import os
import tempfile
import unittest

from transformers.models.speech_to_text_a import SpeechaTextaTokenizer
from transformers.models.speech_to_text_a.tokenization_speech_to_text_a import VOCAB_FILES_NAMES

from ...test_tokenization_common import TokenizerTesterMixin







class 						UpperCAmelCase						(		__a       ,						unittest.TestCase):


 '''simple docstring'''




 __magic_name__       :			Optional[Any]	=   SpeechaTextaTokenizer
 __magic_name__       :			str	=   False




 def    lowercase_	( self)			->   List[str]:



      """simple docstring"""







      super().setUp()

      a_									="<s> <pad> </s> <unk> here@@ a couple of@@ words for the he@@ re@@ vocab".split(" ")
      a_									=["he re</w> 123", "here a 1456"]
      a_									=dict(zip(lowerCAmelCase_				,	range(len(lowerCAmelCase_))))

      a_									={"pad_token": "<pad>", "unk_token": "<unk>", "bos_token": "<s>", "eos_token": "</s>"}

      a_									=tempfile.mkdtemp()
      a_									=os.path.join(self.tmpdirname				,	VOCAB_FILES_NAMES["vocab_file"])
      a_									=os.path.join(self.tmpdirname				,	VOCAB_FILES_NAMES["merges_file"])

      with open(self.vocab_file				,	"w"				,	encoding="utf-8") as fp:
           fp.write(json.dumps(lowerCAmelCase_) + "\n")

      with open(self.merges_file				,	"w") as fp:
           fp.write("\n".join(lowerCAmelCase_))




 def    lowercase_	( self)			->   Optional[Any]:



      """simple docstring"""







      a_									=list(self.get_tokenizer().get_vocab().keys())

      self.assertEqual(vocab_keys[0]				,	"<s>")
      self.assertEqual(vocab_keys[1]				,	"<pad>")
      self.assertEqual(vocab_keys[-1]				,	"vocab")
      self.assertEqual(len(lowerCAmelCase_)				,	1_4)




 def    lowercase_	( self)			->   List[Any]:



      """simple docstring"""







      self.assertEqual(self.get_tokenizer().vocab_size				,	1_4)




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



      """simple docstring"""







      a_									=SpeechaTextaTokenizer.from_pretrained(self.tmpdirname)

      # make sure @@ is correctly concatenated
      a_									=[4, 6, 8, 7, 1_0]  # ["here@@", "couple", "words", "of@@", "the"]
      a_									=tokenizer.decode(lowerCAmelCase_)

      self.assertTrue(output_string == "herecouple words ofthe")




 def    lowercase_	( self)			->   Any:



      """simple docstring"""







      a_									=SpeechaTextaTokenizer.from_pretrained(self.tmpdirname)

      with tempfile.TemporaryDirectory() as tmp_dirname:
           tokenizer.save_pretrained(lowerCAmelCase_)
           os.remove(os.path.join(lowerCAmelCase_				,	"merges.txt"))

           # load tokenizer without merges file should not throw an error
           a_									=SpeechaTextaTokenizer.from_pretrained(lowerCAmelCase_)

      with tempfile.TemporaryDirectory() as tmp_dirname:
           # save tokenizer and load again
           tokenizer.save_pretrained(lowerCAmelCase_)
           a_									=SpeechaTextaTokenizer.from_pretrained(lowerCAmelCase_)

      self.assertIsNotNone(lowerCAmelCase_)




 def    lowercase_	( self)			->   Tuple:



      """simple docstring"""







      if not self.test_slow_tokenizer:
           return

      a_									=inspect.signature(self.tokenizer_class.__init__)
      a_									=self.get_tokenizer()

      for parameter_name, parameter in signature.parameters.items():
           if parameter.default != inspect.Parameter.empty and parameter_name != "merges_file":
                self.assertIn(lowerCAmelCase_				,	tokenizer.init_kwargs)







'''simple docstring'''


lowercase											=      (1, 153, 370, 371, 1_634, 24_678_051, 115_132_219_018_763_992_565_095_597_973_971_522_401)
lowercase											=      (-153, -1, 0, 1.2, 200, "A", [], {}, None)






def 			UpperCAmelCase_							(		lowercase__							):


     '''simple docstring'''







     if not isinstance(lowercase__							,						lowercase__							) or n < 1:
          return False

     # Initialization of sum and number of digits.
     a_									=0
     a_									=0
     a_									=n
     # Calculation of digits of the number
     while temp > 0:
          number_of_digits += 1
          temp //= 1_0
     # Dividing number into separate digits and find Armstrong number
     a_									=n
     while temp > 0:
          a_									=temp % 1_0
          total += rem**number_of_digits
          temp //= 1_0
     return n == total






def 			UpperCAmelCase_							(		lowercase__							):


     '''simple docstring'''







     if not isinstance(lowercase__							,						lowercase__							) or n < 1:
          return False

     # Init a "histogram" of the digits
     a_									=[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
     a_									=0
     a_									=0
     a_									=n
     while temp > 0:
          a_		,    a_									=divmod(lowercase__							,						1_0							)
          digit_histogram[rem] += 1
          digit_total += 1

     for cnt, i in zip(lowercase__							,						range(len(lowercase__							)							)							):
          total += cnt * i**digit_total

     return n == total






def 			UpperCAmelCase_							(		lowercase__							):


     '''simple docstring'''







     if not isinstance(lowercase__							,						lowercase__							) or n < 1:
          return False
     a_									=len(str(lowercase__							)							)  # the power that all digits will be raised to
     # check if sum of each digit multiplied expo times is equal to number
     return n == sum(int(lowercase__							) ** expo for i in str(lowercase__							)							)






def 			UpperCAmelCase_							(		):


     '''simple docstring'''







     a_									=int(input("Enter an integer to see if it is an Armstrong number: "							).strip()							)
     print(F"""{num} is {'' if armstrong_number(lowercase__							) else 'not '}an Armstrong number."""							)
     print(F"""{num} is {'' if narcissistic_number(lowercase__							) else 'not '}an Armstrong number."""							)
     print(F"""{num} is {'' if pluperfect_number(lowercase__							) else 'not '}an Armstrong number."""							)


if __name__ == "__main__":
  import doctest

  doctest.testmod()
  main()


