




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


_SCREAMING_SNAKE_CASE							:   Optional[Any]      		= 'hf-internal-testing/tiny-random-bert'
_SCREAMING_SNAKE_CASE							:   Optional[int]      		= os.path.join(TRANSFORMERS_CACHE, "models--hf-internal-testing--tiny-random-bert")
_SCREAMING_SNAKE_CASE							:   Optional[Any]      		= '9b8c223d42b2188cb49d29af482996f9d0f3e5a6'




class  _snake_case		(	unittest.TestCase							):




			def    lowerCAmelCase__				(					self							)				->				Optional[int]:

										'''simple docstring'''




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

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

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




			def    lowerCAmelCase__				(					self							)				->				Optional[Any]:

										'''simple docstring'''




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

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

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




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

										'''simple docstring'''




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

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

										snake_case_						=      cached_file(a__				,							"conf"				,							_raise_exceptions_for_missing_entries=a__							)
										self.assertIsNone(a__							)

										snake_case_						=      cached_file(a__				,							"conf"				,							local_files_only=a__				,							_raise_exceptions_for_missing_entries=a__							)
										self.assertIsNone(a__							)

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

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




			def    lowerCAmelCase__				(					self							)				->				Dict:

										'''simple docstring'''




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




			def    lowerCAmelCase__				(					self							)				->				Tuple:

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

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

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




			def    lowerCAmelCase__				(					self							)				->				Tuple:

										'''simple docstring'''




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

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








'''simple docstring'''

from __future__ import annotations

def _SCREAMING_SNAKE_CASE      (A  , A       )       ->       list[list[int]]:






       """simple docstring"""







       lowercase__      			= []
       create_all_state(1  , A  , A  , []  , A       )
       return result

def _SCREAMING_SNAKE_CASE      (A  , A  , A  , A  , A  , )       ->       None:






       """simple docstring"""







       if level == 0:
              total_list.append(current_list[:]       )
              return

       for i in range(A  , total_number - level + 2       ):
              current_list.append(A       )
              create_all_state(i + 1  , A  , level - 1  , A  , A       )
              current_list.pop()

def _SCREAMING_SNAKE_CASE      (A       )       ->       None:






       """simple docstring"""







       for i in total_list:
              print(*A       )


if __name__ == "__main__":
 lowerCamelCase							:   Tuple  						=	4
 lowerCamelCase							:   Union[str, Any]  						=	2
 lowerCamelCase							:   Dict  						=	generate_all_combinations(n, k)
 print_all_state(total_list)




