

import json
import os
import shutil
import tempfile
import unittest

from transformers.models.wavaveca import WavaVecaCTCTokenizer, WavaVecaFeatureExtractor, WavaVecaProcessor
from transformers.models.wavaveca.tokenization_wavaveca import VOCAB_FILES_NAMES
from transformers.utils import FEATURE_EXTRACTOR_NAME

from .test_feature_extraction_wavaveca import floats_list







class 						__magic_name__      (							unittest.TestCase							):

   '''simple docstring'''




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






     """simple docstring"""






     a__  ='<pad> <s> </s> <unk> | E T A O N I H S R D L U M W C F G Y P B V K \' X J Q Z'.split(''' '''	)
     a__  =dict(zip(_snake_case,   range(len(_snake_case	)	)	)	)

     a__  ={
         'pad_token': '<pad>',
         'unk_token': '<unk>',
         'bos_token': '<s>',
         'eos_token': '</s>',
     }
     a__  ={
         'feature_size': 1,
         'padding_value': 0.0,
         'sampling_rate': 16000,
         'return_attention_mask': False,
         'do_normalize': True,
     }

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

     with open(self.feature_extraction_file,   '''w''',   encoding='''utf-8'''	) as fp:
       fp.write(json.dumps(_snake_case	) + '''\n'''	)



   def 			_UpperCAmelCase			(    self,   **lowercase_	)							->   Union[str, Any]:






     """simple docstring"""






     a__  =self.add_kwargs_tokens_map.copy()
     kwargs.update(_snake_case	)
     return WavaVecaCTCTokenizer.from_pretrained(self.tmpdirname,   **_snake_case	)



   def 			_UpperCAmelCase			(    self,   **lowercase_	)							->   Union[str, Any]:






     """simple docstring"""






     return WavaVecaFeatureExtractor.from_pretrained(self.tmpdirname,   **_snake_case	)



   def 			_UpperCAmelCase			(    self	)							->   str:






     """simple docstring"""






     shutil.rmtree(self.tmpdirname	)



   def 			_UpperCAmelCase			(    self	)							->   Any:






     """simple docstring"""






     a__  =self.get_tokenizer()
     a__  =self.get_feature_extractor()

     a__  =WavaVecaProcessor(tokenizer=_snake_case,   feature_extractor=_snake_case	)

     processor.save_pretrained(self.tmpdirname	)
     a__  =WavaVecaProcessor.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	)							->   Any:






     """simple docstring"""






     a__  =WavaVecaProcessor(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=_snake_case,   padding_value=1.0	)

     a__  =WavaVecaProcessor.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	)							->   Optional[Any]:






     """simple docstring"""






     a__  =self.get_feature_extractor()
     a__  =self.get_tokenizer()

     a__  =WavaVecaProcessor(tokenizer=_snake_case,   feature_extractor=_snake_case	)

     a__  =floats_list((3, 1000)	)

     a__  =feature_extractor(_snake_case,   return_tensors='''np'''	)
     a__  =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	)							->   str:






     """simple docstring"""






     a__  =self.get_feature_extractor()
     a__  =self.get_tokenizer()

     a__  =WavaVecaProcessor(tokenizer=_snake_case,   feature_extractor=_snake_case	)

     a__  ='This is a test string'

     a__  =processor(text=_snake_case	)

     a__  =tokenizer(_snake_case	)

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



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






     """simple docstring"""






     a__  =self.get_feature_extractor()
     a__  =self.get_tokenizer()

     a__  =WavaVecaProcessor(tokenizer=_snake_case,   feature_extractor=_snake_case	)

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

     a__  =processor.batch_decode(_snake_case	)
     a__  =tokenizer.batch_decode(_snake_case	)

     self.assertListEqual(_snake_case,   _snake_case	)



   def 			_UpperCAmelCase			(    self	)							->   Any:






     """simple docstring"""






     a__  =self.get_feature_extractor()
     a__  =self.get_tokenizer()

     a__  =WavaVecaProcessor(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''',   )


import re
import tempfile
import unittest
from pathlib import Path

from datasets.utils.metadata import DatasetMetadata




def       UpperCAmelCase__    (      _A				:			str							):





  '''simple docstring'''







  a__  =min(re.search('''^ +'''     ,				_A							).end() if t.startswith(''' '''							) else 0 for t in string.splitlines()							)
  return "\n".join([line[indent_level:] for line in string.splitlines() if indent_level < len(_A							)]							)


lowerCamelCase									= '''\
---
language:
- zh
- en
task_ids:
- sentiment-classification
---
# Begin of markdown

Some cool dataset card
'''

lowerCamelCase									= '''\
---
---
# Begin of markdown

Some cool dataset card
'''


lowerCamelCase									= '''\
# Begin of markdown

Some cool dataset card
'''







class 						__magic_name__      (							unittest.TestCase							):

   '''simple docstring'''




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






     """simple docstring"""






     with tempfile.TemporaryDirectory() as tmp_dir:
       a__  =Path(lowercase_	) / '''README.md'''
       with open(lowercase_,   '''w+'''	) as readme_file:
         readme_file.write(lowercase_	)
       a__  =DatasetMetadata.from_readme(lowercase_	)
       self.assertDictEqual(lowercase_,   {'''language''': ['''zh''', '''en'''], '''task_ids''': ['''sentiment-classification''']}	)

       with open(lowercase_,   '''w+'''	) as readme_file:
         readme_file.write(lowercase_	)
       a__  =DatasetMetadata.from_readme(lowercase_	)
       self.assertDictEqual(lowercase_,   {}	)

       with open(lowercase_,   '''w+'''	) as readme_file:
         readme_file.write(lowercase_	)
       a__  =DatasetMetadata.from_readme(lowercase_	)
       self.assertEqual(lowercase_,   {}	)



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






     """simple docstring"""






     a__  =_dedent(
         '''\
            annotations_creators:
            - found
            language_creators:
            - found
            language:
            - en
            license:
            - unknown
            multilinguality:
            - monolingual
            pretty_name: Test Dataset
            size_categories:
            - 10K<n<100K
            source_datasets:
            - extended|other-yahoo-webscope-l6
            task_categories:
            - question-answering
            task_ids:
            - open-domain-qa
            '''	)
     assert DatasetMetadata.from_yaml_string(lowercase_	)

     a__  =_dedent(
         '''\
            annotations_creators:
            - found
            language:
            - en
            license:
            - unknown
            multilinguality:
            - monolingual
            pretty_name: Test Dataset
            size_categories:
            - 10K<n<100K
            source_datasets:
            - extended|other-yahoo-webscope-l6
            task_categories:
            - question-answering
            task_ids:
            - open-domain-qa
            task_ids:
            - open-domain-qa
            '''	)
     with self.assertRaises(lowercase_	):
       DatasetMetadata.from_yaml_string(lowercase_	)

     a__  =_dedent(
         '''\
            annotations_creators:
            - found
            language_creators:
            - found
            language:
            - en
            license:
            - unknown
            multilinguality:
            - monolingual
            pretty_name: Test Dataset
            size_categories:
            - 10K<n<100K
            source_datasets:
            - extended|other-yahoo-webscope-l6
            task_categories:
            - text-classification
            task_ids:
            - multi-class-classification
            paperswithcode_id:
            - squad
            configs:
            - en
            train-eval-index:
            - config: en
              task: text-classification
              task_id: multi_class_classification
              splits:
                train_split: train
                eval_split: test
              col_mapping:
                text: text
                label: target
              metrics:
                - type: accuracy
                  name: Accuracy
            extra_gated_prompt: |
              By clicking on “Access repository” below, you also agree to ImageNet Terms of Access:
              [RESEARCHER_FULLNAME] (the "Researcher") has requested permission to use the ImageNet database (the "Database") at Princeton University and Stanford University. In exchange for such permission, Researcher hereby agrees to the following terms and conditions:
              1. Researcher shall use the Database only for non-commercial research and educational purposes.
            extra_gated_fields:
              Company: text
              Country: text
              I agree to use this model for non-commerical use ONLY: checkbox
            '''	)
     assert DatasetMetadata.from_yaml_string(lowercase_	)
