





"""simple docstring"""



import json
import os
import tempfile
import unittest
import unittest.mock as mock
from pathlib import Path

from requests.exceptions import HTTPError

from transformers.utils import (
    CONFIG_NAME,
    FLAX_WEIGHTS_NAME,
    TF2_WEIGHTS_NAME,
    TRANSFORMERS_CACHE,
    WEIGHTS_NAME,
    cached_file,
    get_file_from_repo,
    has_file,
)


a_					=     """hf-internal-testing/tiny-random-bert"""
a_					=     os.path.join(TRANSFORMERS_CACHE, """models--hf-internal-testing--tiny-random-bert""")
a_					=     """9b8c223d42b2188cb49d29af482996f9d0f3e5a6"""






class 						__snake_case   (						unittest.TestCase	):





 """simple docstring"""


 def    UpperCamelCase__(       self    ):



     '''simple docstring'''




     __A       :		Any							=	cached_file(__lowerCamelCase   ,		__lowerCamelCase    )
     # Should have downloaded the file in here
     self.assertTrue(os.path.isdir(__lowerCamelCase    )    )
     # Cache should contain at least those three subfolders:
     for subfolder in ["blobs", "refs", "snapshots"]:
         self.assertTrue(os.path.isdir(os.path.join(__lowerCamelCase   ,		__lowerCamelCase    )    )    )
     with open(os.path.join(__lowerCamelCase   ,		'''refs'''   ,		'''main'''    )    ) as f:
         __A       :		int							=	f.read()
     self.assertEqual(__lowerCamelCase   ,		os.path.join(__lowerCamelCase   ,		'''snapshots'''   ,		__lowerCamelCase   ,		__lowerCamelCase    )    )
     self.assertTrue(os.path.isfile(__lowerCamelCase    )    )

     # File is cached at the same place the second time.
     __A       :		Union[str, Any]							=	cached_file(__lowerCamelCase   ,		__lowerCamelCase    )
     self.assertEqual(__lowerCamelCase   ,		__lowerCamelCase    )

     # Using a specific revision to test the full commit hash.
     __A       :		Optional[int]							=	cached_file(__lowerCamelCase   ,		__lowerCamelCase   ,		revision='''9b8c223'''    )
     self.assertEqual(__lowerCamelCase   ,		os.path.join(__lowerCamelCase   ,		'''snapshots'''   ,		__lowerCamelCase   ,		__lowerCamelCase    )    )

 def    UpperCamelCase__(       self    ):



     '''simple docstring'''




     with self.assertRaisesRegex(__lowerCamelCase   ,		'''is not a valid model identifier'''    ):
         __A       :		str							=	cached_file('''tiny-random-bert'''   ,		__lowerCamelCase    )

     with self.assertRaisesRegex(__lowerCamelCase   ,		'''is not a valid git identifier'''    ):
         __A       :		List[Any]							=	cached_file(__lowerCamelCase   ,		__lowerCamelCase   ,		revision='''aaaa'''    )

     with self.assertRaisesRegex(__lowerCamelCase   ,		'''does not appear to have a file named'''    ):
         __A       :		Dict							=	cached_file(__lowerCamelCase   ,		'''conf'''    )

 def    UpperCamelCase__(       self    ):



     '''simple docstring'''




     with self.assertRaisesRegex(__lowerCamelCase   ,		'''does not appear to have a file named'''    ):
         __A       :		List[Any]							=	cached_file(__lowerCamelCase   ,		'''conf'''    )

     with open(os.path.join(__lowerCamelCase   ,		'''refs'''   ,		'''main'''    )    ) as f:
         __A       :		int							=	f.read()
     self.assertTrue(os.path.isfile(os.path.join(__lowerCamelCase   ,		'''.no_exist'''   ,		__lowerCamelCase   ,		'''conf'''    )    )    )

     __A       :		Any							=	cached_file(__lowerCamelCase   ,		'''conf'''   ,		_raise_exceptions_for_missing_entries=__lowerCamelCase    )
     self.assertIsNone(__lowerCamelCase    )

     __A       :		Optional[Any]							=	cached_file(__lowerCamelCase   ,		'''conf'''   ,		local_files_only=__lowerCamelCase   ,		_raise_exceptions_for_missing_entries=__lowerCamelCase    )
     self.assertIsNone(__lowerCamelCase    )

     __A       :		Tuple							=	mock.Mock()
     __A       :		Optional[int]							=	500
     __A       :		str							=	{}
     __A       :		Optional[Any]							=	HTTPError
     __A       :		Tuple							=	{}

     # Under the mock environment we get a 500 error when trying to reach the tokenizer.
     with mock.patch('''requests.Session.request'''   ,		return_value=__lowerCamelCase    ) as mock_head:
         __A       :		Optional[Any]							=	cached_file(__lowerCamelCase   ,		'''conf'''   ,		_raise_exceptions_for_connection_errors=__lowerCamelCase    )
         self.assertIsNone(__lowerCamelCase    )
         # This check we did call the fake head request
         mock_head.assert_called()

 def    UpperCamelCase__(       self    ):



     '''simple docstring'''




     self.assertTrue(has_file('''hf-internal-testing/tiny-bert-pt-only'''   ,		__lowerCamelCase    )    )
     self.assertFalse(has_file('''hf-internal-testing/tiny-bert-pt-only'''   ,		__lowerCamelCase    )    )
     self.assertFalse(has_file('''hf-internal-testing/tiny-bert-pt-only'''   ,		__lowerCamelCase    )    )

 def    UpperCamelCase__(       self    ):



     '''simple docstring'''




     self.assertIsNone(get_file_from_repo('''bert-base-cased'''   ,		'''ahah.txt'''    )    )

     # The function raises if the repository does not exist.
     with self.assertRaisesRegex(__lowerCamelCase   ,		'''is not a valid model identifier'''    ):
         get_file_from_repo('''bert-base-case'''   ,		__lowerCamelCase    )

     # The function raises if the revision does not exist.
     with self.assertRaisesRegex(__lowerCamelCase   ,		'''is not a valid git identifier'''    ):
         get_file_from_repo('''bert-base-cased'''   ,		__lowerCamelCase   ,		revision='''ahaha'''    )

     __A       :		Optional[int]							=	get_file_from_repo('''bert-base-cased'''   ,		__lowerCamelCase    )
     # The name is the cached name which is not very easy to test, so instead we load the content.
     __A       :		str							=	json.loads(open(__lowerCamelCase   ,		'''r'''    ).read()    )
     self.assertEqual(config['''hidden_size''']   ,		768    )







 def    UpperCamelCase__(       self    ):



     '''simple docstring'''




     with tempfile.TemporaryDirectory() as tmp_dir:
         __A       :		List[Any]							=	Path(__lowerCamelCase    ) / '''a.txt'''
         filename.touch()
         self.assertEqual(get_file_from_repo(__lowerCamelCase   ,		'''a.txt'''    )   ,		str(__lowerCamelCase    )    )

         self.assertIsNone(get_file_from_repo(__lowerCamelCase   ,		'''b.txt'''    )    )











"""simple docstring"""



import warnings

from ...utils import logging
from .image_processing_poolformer import PoolFormerImageProcessor


a_					=     logging.get_logger(__name__)






class 						__snake_case   (						SCREAMING_SNAKE_CASE__	):





 """simple docstring"""


 def __init__(       self   ,		*__lowerCamelCase   ,		**__lowerCamelCase    ):



     '''simple docstring'''




     warnings.warn(
         '''The class PoolFormerFeatureExtractor is deprecated and will be removed in version 5 of Transformers.'''
         ''' Please use PoolFormerImageProcessor instead.'''   ,		__lowerCamelCase   ,		)
     super().__init__(*__lowerCamelCase   ,		**__lowerCamelCase    )




