



"""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,
)


lowerCamelCase       	=						"""hf-internal-testing/tiny-random-bert"""
lowerCamelCase       	=						os.path.join(TRANSFORMERS_CACHE, """models--hf-internal-testing--tiny-random-bert""")
lowerCamelCase       	=						"""9b8c223d42b2188cb49d29af482996f9d0f3e5a6"""
class 				lowercase__       (   unittest.TestCase				):







     '''simple docstring'''


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


           '''simple docstring'''




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

           # File is cached at the same place the second time.
           UpperCAmelCase_      			=							cached_file(_UpperCAmelCase		,    _UpperCAmelCase   )
           self.assertEqual(_UpperCAmelCase		,    _UpperCAmelCase   )

           # Using a specific revision to test the full commit hash.
           UpperCAmelCase_      			=							cached_file(_UpperCAmelCase		,    _UpperCAmelCase		,    revision="9b8c223"   )
           self.assertEqual(_UpperCAmelCase		,    os.path.join(_UpperCAmelCase		,    "snapshots"		,    _UpperCAmelCase		,    _UpperCAmelCase   )   )



     def 					lowercase__    (							self      :  Optional[int]   )			->						Tuple:


           '''simple docstring'''




           with self.assertRaisesRegex(_UpperCAmelCase		,    "is not a valid model identifier"   ):
                 UpperCAmelCase_      			=							cached_file("tiny-random-bert"		,    _UpperCAmelCase   )

           with self.assertRaisesRegex(_UpperCAmelCase		,    "is not a valid git identifier"   ):
                 UpperCAmelCase_      			=							cached_file(_UpperCAmelCase		,    _UpperCAmelCase		,    revision="aaaa"   )

           with self.assertRaisesRegex(_UpperCAmelCase		,    "does not appear to have a file named"   ):
                 UpperCAmelCase_      			=							cached_file(_UpperCAmelCase		,    "conf"   )



     def 					lowercase__    (							self      :  List[str]   )			->						Optional[int]:


           '''simple docstring'''




           with self.assertRaisesRegex(_UpperCAmelCase		,    "does not appear to have a file named"   ):
                 UpperCAmelCase_      			=							cached_file(_UpperCAmelCase		,    "conf"   )

           with open(os.path.join(_UpperCAmelCase		,    "refs"		,    "main"   )   ) as f:
                 UpperCAmelCase_      			=							f.read()
           self.assertTrue(os.path.isfile(os.path.join(_UpperCAmelCase		,    ".no_exist"		,    _UpperCAmelCase		,    "conf"   )   )   )

           UpperCAmelCase_      			=							cached_file(_UpperCAmelCase		,    "conf"		,    _raise_exceptions_for_missing_entries=_UpperCAmelCase   )
           self.assertIsNone(_UpperCAmelCase   )

           UpperCAmelCase_      			=							cached_file(_UpperCAmelCase		,    "conf"		,    local_files_only=_UpperCAmelCase		,    _raise_exceptions_for_missing_entries=_UpperCAmelCase   )
           self.assertIsNone(_UpperCAmelCase   )

           UpperCAmelCase_      			=							mock.Mock()
           UpperCAmelCase_      			=							500
           UpperCAmelCase_      			=							{}
           UpperCAmelCase_      			=							HTTPError
           UpperCAmelCase_      			=							{}

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



     def 					lowercase__    (							self      :  List[Any]   )			->						List[str]:


           '''simple docstring'''




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



     def 					lowercase__    (							self      :  Optional[int]   )			->						Any:


           '''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(_UpperCAmelCase		,    "is not a valid model identifier"   ):
                 get_file_from_repo("bert-base-case"		,    _UpperCAmelCase   )

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

           UpperCAmelCase_      			=							get_file_from_repo("bert-base-cased"		,    _UpperCAmelCase   )
           # The name is the cached name which is not very easy to test, so instead we load the content.
           UpperCAmelCase_      			=							json.loads(open(_UpperCAmelCase		,    "r"   ).read()   )
           self.assertEqual(config["hidden_size"]		,    768   )







     def 					lowercase__    (							self      :  Optional[Any]   )			->						List[Any]:


           '''simple docstring'''




           with tempfile.TemporaryDirectory() as tmp_dir:
                 UpperCAmelCase_      			=							Path(_UpperCAmelCase   ) / "a.txt"
                 filename.touch()
                 self.assertEqual(get_file_from_repo(_UpperCAmelCase		,    "a.txt"   )		,    str(_UpperCAmelCase   )   )

                 self.assertIsNone(get_file_from_repo(_UpperCAmelCase		,    "b.txt"   )   )









"""simple docstring"""





from maths.prime_check import is_prime
def        a__     (				lowerCAmelCase__				):
      if not isinstance(lowerCAmelCase__     ,      lowerCAmelCase__				):
            UpperCAmelCase_      			=							f"""Input value of [number={number}] must be an integer"""
            raise TypeError(lowerCAmelCase__				)
      if is_prime(lowerCAmelCase__				) and is_prime(number + 2				):
            return number + 2
      else:
            return -1


if __name__ == "__main__":
  import doctest

  doctest.testmod()




