


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


_snake_case					:		Any   =    "hf-internal-testing/tiny-random-bert"
_snake_case					:		Dict   =    os.path.join(TRANSFORMERS_CACHE, "models--hf-internal-testing--tiny-random-bert")
_snake_case					:		Tuple   =    "9b8c223d42b2188cb49d29af482996f9d0f3e5a6"

class     a		(unittest.TestCase				):




							"""simple docstring"""


							def    __snake_case (							self	:  List[Any]    )     ->   List[Any]:
														__snake_case		:      str										=       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:
																					__snake_case		:      Any										=       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.
														__snake_case		:      Any										=       cached_file(lowerCamelCase   ,     lowerCamelCase    )
														self.assertEqual(lowerCamelCase   ,     lowerCamelCase    )

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

							def    __snake_case (							self	:  Tuple    )     ->   Optional[Any]:
														with self.assertRaisesRegex(lowerCamelCase   ,     "is not a valid model identifier"    ):
																					__snake_case		:      str										=       cached_file("tiny-random-bert"   ,     lowerCamelCase    )

														with self.assertRaisesRegex(lowerCamelCase   ,     "is not a valid git identifier"    ):
																					__snake_case		:      Optional[int]										=       cached_file(lowerCamelCase   ,     lowerCamelCase   ,     revision="aaaa"    )

														with self.assertRaisesRegex(lowerCamelCase   ,     "does not appear to have a file named"    ):
																					__snake_case		:      Optional[Any]										=       cached_file(lowerCamelCase   ,     "conf"    )

							def    __snake_case (							self	:  Any    )     ->   Union[str, Any]:
														with self.assertRaisesRegex(lowerCamelCase   ,     "does not appear to have a file named"    ):
																					__snake_case		:      Tuple										=       cached_file(lowerCamelCase   ,     "conf"    )

														with open(os.path.join(lowerCamelCase   ,     "refs"   ,     "main"    )    ) as f:
																					__snake_case		:      Optional[int]										=       f.read()
														self.assertTrue(os.path.isfile(os.path.join(lowerCamelCase   ,     ".no_exist"   ,     lowerCamelCase   ,     "conf"    )    )    )

														__snake_case		:      List[str]										=       cached_file(lowerCamelCase   ,     "conf"   ,     _raise_exceptions_for_missing_entries=lowerCamelCase    )
														self.assertIsNone(lowerCamelCase    )

														__snake_case		:      Dict										=       cached_file(lowerCamelCase   ,     "conf"   ,     local_files_only=lowerCamelCase   ,     _raise_exceptions_for_missing_entries=lowerCamelCase    )
														self.assertIsNone(lowerCamelCase    )

														__snake_case		:      Any										=       mock.Mock()
														__snake_case		:      Any										=       500
														__snake_case		:      Dict										=       {}
														__snake_case		:      Any										=       HTTPError
														__snake_case		:      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:
																					__snake_case		:      int										=       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    __snake_case (							self	:  Dict    )     ->   List[str]:
														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    __snake_case (							self	:  List[str]    )     ->   List[str]:
														# `get_file_from_repo` returns None if the file does not exist
														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"    )

														__snake_case		:      List[str]										=       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.
														__snake_case		:      Dict										=       json.loads(open(lowerCamelCase   ,     "r"    ).read()    )
														self.assertEqual(config["hidden_size"]   ,     768    )






							def    __snake_case (							self	:  int    )     ->   str:
														with tempfile.TemporaryDirectory() as tmp_dir:
																					__snake_case		:      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"    )    )





from __future__ import annotations

from functools import lru_cache
from math import ceil

_snake_case					:		Tuple      =    100

_snake_case					:		int      =    set(range(3, NUM_PRIMES, 2))
primes.add(2)
_snake_case					:		int

for prime in range(3, ceil(NUM_PRIMES**0.5), 2):
			if prime not in primes:
						continue
			primes.difference_update(set(range(prime * prime, NUM_PRIMES, prime)))







@lru_cache(maxsize=1_0_0     )
def     lowerCAmelCase_					( __lowerCamelCase     ):
							if number_to_partition < 0:
														return set()
							elif number_to_partition == 0:
														return {1}

							__snake_case		:      set[int]										=       set()
							__snake_case		:      int
							__snake_case		:      int

							for prime in primes:
														if prime > number_to_partition:
																					continue
														for sub in partition(number_to_partition - prime     ):
																					ret.add(sub * prime     )

							return ret







def     lowerCAmelCase_					( __lowerCamelCase = 5_0_0_0     ):
							for number_to_partition in range(1							,     __lowerCamelCase     ):
														if len(partition(__lowerCamelCase     )     ) > number_unique_partitions:
																					return number_to_partition
							return None


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

