




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 						SCREAMING_SNAKE_CASE__		(unittest.TestCase ):
     def 					A__			(	self  :		Optional[Any]	):



       """simple docstring"""
       lowerCAmelCase__								=			'''<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(''' '''	)
       lowerCAmelCase__								=			dict(zip(__lowerCamelCase					,	range(len(__lowerCamelCase	)	)	)	)

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

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

       with open(self.feature_extraction_file					,	'''w'''					,	encoding='''utf-8'''	) as fp:
         fp.write(json.dumps(__lowerCamelCase	) + '''\n'''	)
     def 					A__			(	self  :		Tuple					,	**__lowerCamelCase  :		str	):



       """simple docstring"""
       lowerCAmelCase__								=			self.add_kwargs_tokens_map.copy()
       kwargs.update(__lowerCamelCase	)
       return WavaVecaCTCTokenizer.from_pretrained(self.tmpdirname					,	**__lowerCamelCase	)
     def 					A__			(	self  :		int					,	**__lowerCamelCase  :		List[Any]	):



       """simple docstring"""
       return WavaVecaFeatureExtractor.from_pretrained(self.tmpdirname					,	**__lowerCamelCase	)
     def 					A__			(	self  :		List[Any]	):



       """simple docstring"""
       shutil.rmtree(self.tmpdirname	)
     def 					A__			(	self  :		Optional[int]	):



       """simple docstring"""
       lowerCAmelCase__								=			self.get_tokenizer()
       lowerCAmelCase__								=			self.get_feature_extractor()

       lowerCAmelCase__								=			WavaVecaProcessor(tokenizer=__lowerCamelCase					,	feature_extractor=__lowerCamelCase	)

       processor.save_pretrained(self.tmpdirname	)
       lowerCAmelCase__								=			WavaVecaProcessor.from_pretrained(self.tmpdirname	)

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

       self.assertEqual(processor.feature_extractor.to_json_string()					,	feature_extractor.to_json_string()	)
       self.assertIsInstance(processor.feature_extractor					,	__lowerCamelCase	)
     def 					A__			(	self  :		Dict	):



       """simple docstring"""
       lowerCAmelCase__								=			WavaVecaProcessor(tokenizer=self.get_tokenizer()					,	feature_extractor=self.get_feature_extractor()	)
       processor.save_pretrained(self.tmpdirname	)

       lowerCAmelCase__								=			self.get_tokenizer(bos_token='''(BOS)'''					,	eos_token='''(EOS)'''	)
       lowerCAmelCase__								=			self.get_feature_extractor(do_normalize=__lowerCamelCase					,	padding_value=1.0	)

       lowerCAmelCase__								=			WavaVecaProcessor.from_pretrained(
           self.tmpdirname					,	bos_token='''(BOS)'''					,	eos_token='''(EOS)'''					,	do_normalize=__lowerCamelCase					,	padding_value=1.0	)

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

       self.assertEqual(processor.feature_extractor.to_json_string()					,	feature_extractor_add_kwargs.to_json_string()	)
       self.assertIsInstance(processor.feature_extractor					,	__lowerCamelCase	)
     def 					A__			(	self  :		Dict	):



       """simple docstring"""
       lowerCAmelCase__								=			self.get_feature_extractor()
       lowerCAmelCase__								=			self.get_tokenizer()

       lowerCAmelCase__								=			WavaVecaProcessor(tokenizer=__lowerCamelCase					,	feature_extractor=__lowerCamelCase	)

       lowerCAmelCase__								=			floats_list((3, 10_00)	)

       lowerCAmelCase__								=			feature_extractor(__lowerCamelCase					,	return_tensors='''np'''	)
       lowerCAmelCase__								=			processor(__lowerCamelCase					,	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 					A__			(	self  :		Optional[Any]	):



       """simple docstring"""
       lowerCAmelCase__								=			self.get_feature_extractor()
       lowerCAmelCase__								=			self.get_tokenizer()

       lowerCAmelCase__								=			WavaVecaProcessor(tokenizer=__lowerCamelCase					,	feature_extractor=__lowerCamelCase	)

       lowerCAmelCase__								=			'''This is a test string'''

       lowerCAmelCase__								=			processor(text=__lowerCamelCase	)

       lowerCAmelCase__								=			tokenizer(__lowerCamelCase	)

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



       """simple docstring"""
       lowerCAmelCase__								=			self.get_feature_extractor()
       lowerCAmelCase__								=			self.get_tokenizer()

       lowerCAmelCase__								=			WavaVecaProcessor(tokenizer=__lowerCamelCase					,	feature_extractor=__lowerCamelCase	)

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

       lowerCAmelCase__								=			processor.batch_decode(__lowerCamelCase	)
       lowerCAmelCase__								=			tokenizer.batch_decode(__lowerCamelCase	)

       self.assertListEqual(__lowerCamelCase					,	__lowerCamelCase	)



     def 					A__			(	self  :		Dict	):



       """simple docstring"""
       lowerCAmelCase__								=			self.get_feature_extractor()
       lowerCAmelCase__								=			self.get_tokenizer()

       lowerCAmelCase__								=			WavaVecaProcessor(tokenizer=__lowerCamelCase					,	feature_extractor=__lowerCamelCase	)

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







import json

import requests

from .fetch_github_info import AUTHENTICATED_USER_ENDPOINT, fetch_github_info
def 		a_       (   __lowerCAmelCase							):





  class 						SCREAMING_SNAKE_CASE__		:
       def __init__(	self  :		List[str]					,	__lowerCamelCase  :		Any	):



         """simple docstring"""
         assert isinstance(__lowerCamelCase					,	(bytes, str)	)
         lowerCAmelCase__								=			content



       def 					A__			(	self  :		int	):



         """simple docstring"""
         return json.loads(self.content	)

  def mock_response(*__lowerCAmelCase      ,   **__lowerCAmelCase							):
    assert args[0] == AUTHENTICATED_USER_ENDPOINT
    assert "Authorization" in kwargs["headers"]
    assert kwargs["headers"]["Authorization"].startswith('''token '''							)
    assert "Accept" in kwargs["headers"]
    return FakeResponse(B'''{"login":"test","id":1}'''							)

  monkeypatch.setattr(__lowerCAmelCase      ,   '''get'''      ,   __lowerCAmelCase							)
  lowerCAmelCase__								=			fetch_github_info('''token'''							)
  assert result["login"] == "test"
  assert result["id"] == 1

