





"""simple docstring"""
import json
import os
import unittest

from transformers import MgpstrTokenizer
from transformers.models.mgp_str.tokenization_mgp_str import VOCAB_FILES_NAMES
from transformers.testing_utils import require_tokenizers

from ...test_tokenization_common import TokenizerTesterMixin






@require_tokenizers
class  _SCREAMING_SNAKE_CASE(       A   ,     unittest.TestCase  ):
       SCREAMING_SNAKE_CASE_       :				str     						=  MgpstrTokenizer
       SCREAMING_SNAKE_CASE_       :				List[str]     						=  False
       SCREAMING_SNAKE_CASE_       :				Any     						=  {}
       SCREAMING_SNAKE_CASE_       :				Dict     						=  False




       def    _UpperCamelCase					(						self							)      ->				Tuple:





             """simple docstring"""






             super().setUp()

             # fmt: off
             __SCREAMING_SNAKE_CASE       :List[Any]		    =  ['''[GO]''', '''[s]''', '''0''', '''1''', '''2''', '''3''', '''4''', '''5''', '''6''', '''7''', '''8''', '''9''', '''a''', '''b''', '''c''', '''d''', '''e''', '''f''', '''g''', '''h''', '''i''', '''j''', '''k''', '''l''', '''m''', '''n''', '''o''', '''p''', '''q''', '''r''', '''s''', '''t''', '''u''', '''v''', '''w''', '''x''', '''y''', '''z''']
             # fmt: on
             __SCREAMING_SNAKE_CASE       :Any		    =  dict(zip(SCREAMING_SNAKE_CASE__		,range(len(SCREAMING_SNAKE_CASE__							)							)							)							)

             __SCREAMING_SNAKE_CASE       :str		    =  os.path.join(self.tmpdirname		,VOCAB_FILES_NAMES['''vocab_file''']							)
             with open(self.vocab_file		,'''w'''		,encoding='''utf-8'''							) as fp:
                   fp.write(json.dumps(SCREAMING_SNAKE_CASE__							) + '''\n'''							)




       def    _UpperCamelCase					(						self		,**SCREAMING_SNAKE_CASE__							)      ->				Union[str, Any]:





             """simple docstring"""






             return MgpstrTokenizer.from_pretrained(self.tmpdirname		,**SCREAMING_SNAKE_CASE__							)




       def    _UpperCamelCase					(						self		,SCREAMING_SNAKE_CASE__							)      ->				List[Any]:





             """simple docstring"""






             __SCREAMING_SNAKE_CASE       :List[Any]		    =  '''tester'''
             __SCREAMING_SNAKE_CASE       :Union[str, Any]		    =  '''tester'''
             return input_text, output_text




       @unittest.skip('''MGP-STR always lower cases letters.'''							)
       def    _UpperCamelCase					(						self							)      ->				Union[str, Any]:





             """simple docstring"""






             pass




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





             """simple docstring"""






             __SCREAMING_SNAKE_CASE       :Optional[Any]		    =  self.get_tokenizers(do_lower_case=SCREAMING_SNAKE_CASE__							)
             for tokenizer in tokenizers:
                   with self.subTest(f'''{tokenizer.__class__.__name__}'''							):
                         __SCREAMING_SNAKE_CASE       :List[Any]		    =  '''[SPECIAL_TOKEN]'''

                         tokenizer.add_special_tokens({'''cls_token''': special_token}							)
                         __SCREAMING_SNAKE_CASE       :Optional[int]		    =  tokenizer.encode([special_token]		,add_special_tokens=SCREAMING_SNAKE_CASE__							)
                         self.assertEqual(len(SCREAMING_SNAKE_CASE__							)		,1							)

                         __SCREAMING_SNAKE_CASE       :Optional[Any]		    =  tokenizer.decode(SCREAMING_SNAKE_CASE__		,skip_special_tokens=SCREAMING_SNAKE_CASE__							)
                         self.assertTrue(special_token not in decoded							)




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





             """simple docstring"""






             __SCREAMING_SNAKE_CASE       :List[str]		    =  self.get_tokenizers()
             for tokenizer in tokenizers:
                   with self.subTest(f'''{tokenizer.__class__.__name__}'''							):
                         __SCREAMING_SNAKE_CASE    ,__SCREAMING_SNAKE_CASE       :Tuple		    =  self.get_input_output_texts(SCREAMING_SNAKE_CASE__							)

                         __SCREAMING_SNAKE_CASE       :int		    =  tokenizer.tokenize(SCREAMING_SNAKE_CASE__							)
                         __SCREAMING_SNAKE_CASE       :Optional[Any]		    =  tokenizer.convert_tokens_to_ids(SCREAMING_SNAKE_CASE__							)
                         __SCREAMING_SNAKE_CASE       :Union[str, Any]		    =  tokenizer.encode(SCREAMING_SNAKE_CASE__		,add_special_tokens=SCREAMING_SNAKE_CASE__							)
                         self.assertListEqual(SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__							)

                         __SCREAMING_SNAKE_CASE       :Dict		    =  tokenizer.convert_ids_to_tokens(SCREAMING_SNAKE_CASE__							)
                         self.assertNotEqual(len(SCREAMING_SNAKE_CASE__							)		,0							)
                         __SCREAMING_SNAKE_CASE       :List[str]		    =  tokenizer.decode(SCREAMING_SNAKE_CASE__							)
                         self.assertIsInstance(SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__							)

                         self.assertEqual(text_a.replace(''' '''		,''''''							)		,SCREAMING_SNAKE_CASE__							)




       @unittest.skip('''MGP-STR tokenizer only handles one sequence.'''							)
       def    _UpperCamelCase					(						self							)      ->				str:





             """simple docstring"""






             pass




       @unittest.skip('''inputs cannot be pretokenized in MgpstrTokenizer'''							)
       def    _UpperCamelCase					(						self							)      ->				Tuple:





             """simple docstring"""






             pass






"""simple docstring"""
import unittest

from datasets import load_dataset

from transformers.pipelines import pipeline
from transformers.testing_utils import is_pipeline_test, nested_simplify, require_torch, slow






@is_pipeline_test
@require_torch
class  _SCREAMING_SNAKE_CASE(       unittest.TestCase  ):




       @require_torch
       def    _UpperCamelCase					(						self							)      ->				str:





             """simple docstring"""






             __SCREAMING_SNAKE_CASE       :Dict		    =  pipeline(
                 task='''zero-shot-audio-classification'''		,model='''hf-internal-testing/tiny-clap-htsat-unfused'''							)
             __SCREAMING_SNAKE_CASE       :Any		    =  load_dataset('''ashraq/esc50'''							)
             __SCREAMING_SNAKE_CASE       :int		    =  dataset['''train''']['''audio'''][-1]['''array''']
             __SCREAMING_SNAKE_CASE       :Dict		    =  audio_classifier(SCREAMING_SNAKE_CASE__		,candidate_labels=['''Sound of a dog''', '''Sound of vaccum cleaner''']							)
             self.assertEqual(
                 nested_simplify(SCREAMING_SNAKE_CASE__							)		,[{'''score''': 0.5_0_1, '''label''': '''Sound of a dog'''}, {'''score''': 0.4_9_9, '''label''': '''Sound of vaccum cleaner'''}]		,)




       @unittest.skip('''No models are available in TF'''							)
       def    _UpperCamelCase					(						self							)      ->				Optional[int]:





             """simple docstring"""






             pass




       @slow
       @require_torch
       def    _UpperCamelCase					(						self							)      ->				Tuple:





             """simple docstring"""






             __SCREAMING_SNAKE_CASE       :Optional[int]		    =  pipeline(
                 task='''zero-shot-audio-classification'''		,model='''laion/clap-htsat-unfused'''		,)
             # This is an audio of a dog
             __SCREAMING_SNAKE_CASE       :List[Any]		    =  load_dataset('''ashraq/esc50'''							)
             __SCREAMING_SNAKE_CASE       :Tuple		    =  dataset['''train''']['''audio'''][-1]['''array''']
             __SCREAMING_SNAKE_CASE       :str		    =  audio_classifier(SCREAMING_SNAKE_CASE__		,candidate_labels=['''Sound of a dog''', '''Sound of vaccum cleaner''']							)

             self.assertEqual(
                 nested_simplify(SCREAMING_SNAKE_CASE__							)		,[
                     {'''score''': 0.9_9_9, '''label''': '''Sound of a dog'''},
                     {'''score''': 0.0_0_1, '''label''': '''Sound of vaccum cleaner'''},
                 ]		,)

             __SCREAMING_SNAKE_CASE       :Dict		    =  audio_classifier([audio] * 5		,candidate_labels=['''Sound of a dog''', '''Sound of vaccum cleaner''']							)
             self.assertEqual(
                 nested_simplify(SCREAMING_SNAKE_CASE__							)		,[
                     [
                         {'''score''': 0.9_9_9, '''label''': '''Sound of a dog'''},
                         {'''score''': 0.0_0_1, '''label''': '''Sound of vaccum cleaner'''},
                     ],
                 ]
                 * 5		,)
             __SCREAMING_SNAKE_CASE       :Union[str, Any]		    =  audio_classifier(
                 [audio] * 5		,candidate_labels=['''Sound of a dog''', '''Sound of vaccum cleaner''']		,batch_size=5							)
             self.assertEqual(
                 nested_simplify(SCREAMING_SNAKE_CASE__							)		,[
                     [
                         {'''score''': 0.9_9_9, '''label''': '''Sound of a dog'''},
                         {'''score''': 0.0_0_1, '''label''': '''Sound of vaccum cleaner'''},
                     ],
                 ]
                 * 5		,)




       @unittest.skip('''No models are available in TF'''							)
       def    _UpperCamelCase					(						self							)      ->				List[str]:





             """simple docstring"""






             pass