'''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_ : List[Any]						  =      "hf-internal-testing/tiny-random-bert"
lowerCAmelCase_ : List[Any]						  =      os.path.join(TRANSFORMERS_CACHE, "models--hf-internal-testing--tiny-random-bert")
lowerCAmelCase_ : List[str]						  =      "9b8c223d42b2188cb49d29af482996f9d0f3e5a6"





class 							lowercase						(						unittest.TestCase ):


   def lowerCamelCase__       (   self				:	Any)      ->					Union[str, Any]:
         lowercase_     =      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:
               lowercase_     =      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.
         lowercase_     =      cached_file(_UpperCamelCase   ,		_UpperCamelCase)
         self.assertEqual(_UpperCamelCase   ,		_UpperCamelCase)

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


   def lowerCamelCase__       (   self				:	int)      ->					Union[str, Any]:


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

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

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


   def lowerCamelCase__       (   self				:	int)      ->					str:


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

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

         lowercase_     =      cached_file(_UpperCamelCase   ,		"conf"   ,		_raise_exceptions_for_missing_entries=_UpperCamelCase)
         self.assertIsNone(_UpperCamelCase)

         lowercase_     =      cached_file(_UpperCamelCase   ,		"conf"   ,		local_files_only=_UpperCamelCase   ,		_raise_exceptions_for_missing_entries=_UpperCamelCase)
         self.assertIsNone(_UpperCamelCase)

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

         # 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:
               lowercase_     =      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 lowerCamelCase__       (   self				:	Tuple)      ->					Any:
         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 lowerCamelCase__       (   self				:	Dict)      ->					Union[str, Any]:
         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")

         lowercase_     =      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.
         lowercase_     =      json.loads(open(_UpperCamelCase   ,		"r").read())
         self.assertEqual(config["hidden_size"]   ,		768)


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


         with tempfile.TemporaryDirectory() as tmp_dir:
               lowercase_     =      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 __future__ import annotations


def __a (	__lowerCamelCase			:						int				)	->							list[int]:
      '''simple docstring'''


      lowercase_     =      [True] * limit
      lowercase_     =      False
      lowercase_     =      False
      lowercase_     =      True

      for i in range(3 ,		int(limit**0.5 + 1				) ,		2				):
            lowercase_     =      i * 2
            while index < limit:
                  lowercase_     =      False
                  lowercase_     =      index + i

      lowercase_     =      [2]

      for i in range(3 ,		__lowerCamelCase ,		2				):
            if is_prime[i]:
                  primes.append(__lowerCamelCase				)

      return primes


def __a (	__lowerCamelCase			:						int = 1_000_000				)	->							int:
      '''simple docstring'''


      lowercase_     =      prime_sieve(__lowerCamelCase				)
      lowercase_     =      0
      lowercase_     =      0

      for i in range(len(__lowerCamelCase				)				):
            for j in range(i + length ,		len(__lowerCamelCase				)				):
                  lowercase_     =      sum(primes[i:j]				)
                  if sol >= ceiling:
                        break

                  if sol in primes:
                        lowercase_     =      j - i
                        lowercase_     =      sol

      return largest


if __name__ == "__main__":
       print(F'''{solution() = }''')






