
"""simple docstring"""






import os
import sys
import unittest


_lowercase							=				os.path.abspath(os.path.dirname(os.path.dirname(os.path.dirname(__file__))))
sys.path.append(os.path.join(git_repo_path, '''utils'''))

import check_dummies  # noqa: E402
from check_dummies import create_dummy_files, create_dummy_object, find_backend, read_init  # noqa: E402


# Align TRANSFORMERS_PATH in check_dummies with the current path
_lowercase							=				os.path.join(git_repo_path, '''src''', '''transformers''')

_lowercase							=				'''
{0} = None
'''

_lowercase							=				'''
class {0}(metaclass=DummyObject):
    _backends = {1}

    def __init__(self, *args, **kwargs):
        requires_backends(self, {1})
'''


_lowercase							=				'''
def {0}(*args, **kwargs):
    requires_backends({0}, {1})
'''

class 					__a     ( unittest.TestCase       ):



							'''simple docstring'''







							def   SCREAMING_SNAKE_CASE						(     self       )			->							int:




										'''simple docstring'''
										__lowercase       =       find_backend("    _import_structure[\"models.albert\"].append(\"AlbertTokenizerFast\")"       )
										self.assertIsNone(_lowerCamelCase       )

										__lowercase       =       find_backend("    if not is_tokenizers_available():"       )
										self.assertEqual(_lowerCamelCase  ,    "tokenizers"       )

										__lowercase       =       find_backend("    if not is_tensorflow_text_available():"       )
										self.assertEqual(_lowerCamelCase  ,    "tensorflow_text"       )

										__lowercase       =       find_backend("    if not (is_sentencepiece_available() and is_tokenizers_available()):"       )
										self.assertEqual(_lowerCamelCase  ,    "sentencepiece_and_tokenizers"       )

										__lowercase       =       find_backend(
										    "    if not (is_sentencepiece_available() and is_tensorflow_text_available()):"       )
										self.assertEqual(_lowerCamelCase  ,    "sentencepiece_and_tensorflow_text"       )

										__lowercase       =       find_backend(
										    "    if not (is_sentencepiece_available() and is_tokenizers_available() and is_vision_available()):"       )
										self.assertEqual(_lowerCamelCase  ,    "sentencepiece_and_tokenizers_and_vision"       )
							def   SCREAMING_SNAKE_CASE						(     self       )			->							int:




										'''simple docstring'''
										__lowercase       =       read_init()
										# We don't assert on the exact list of keys to allow for smooth grow of backend-specific objects
										self.assertIn("torch"  ,    _lowerCamelCase       )
										self.assertIn("tensorflow_text"  ,    _lowerCamelCase       )
										self.assertIn("sentencepiece_and_tokenizers"  ,    _lowerCamelCase       )

										# Likewise, we can't assert on the exact content of a key
										self.assertIn("BertModel"  ,    objects["torch"]       )
										self.assertIn("TFBertModel"  ,    objects["tf"]       )
										self.assertIn("FlaxBertModel"  ,    objects["flax"]       )
										self.assertIn("BertModel"  ,    objects["torch"]       )
										self.assertIn("TFBertTokenizer"  ,    objects["tensorflow_text"]       )
										self.assertIn("convert_slow_tokenizer"  ,    objects["sentencepiece_and_tokenizers"]       )
							def   SCREAMING_SNAKE_CASE						(     self       )			->							Tuple:




										'''simple docstring'''
										__lowercase       =       create_dummy_object("CONSTANT"  ,    "'torch'"       )
										self.assertEqual(_lowerCamelCase  ,    "\nCONSTANT = None\n"       )

										__lowercase       =       create_dummy_object("function"  ,    "'torch'"       )
										self.assertEqual(
										    _lowerCamelCase  ,    "\ndef function(*args, **kwargs):\n    requires_backends(function, 'torch')\n"       )

										__lowercase       =       "\nclass FakeClass(metaclass=DummyObject):\n    _backends = 'torch'\n\n    def __init__(self, *args, **kwargs):\n        requires_backends(self, 'torch')\n"
										__lowercase       =       create_dummy_object("FakeClass"  ,    "'torch'"       )
										self.assertEqual(_lowerCamelCase  ,    _lowerCamelCase       )





							def   SCREAMING_SNAKE_CASE						(     self       )			->							Any:




										'''simple docstring'''
										__lowercase       =       "# This file is autogenerated by the command `make fix-copies`, do not edit.\nfrom ..utils import DummyObject, requires_backends\n\n\nCONSTANT = None\n\n\ndef function(*args, **kwargs):\n    requires_backends(function, [\"torch\"])\n\n\nclass FakeClass(metaclass=DummyObject):\n    _backends = [\"torch\"]\n\n    def __init__(self, *args, **kwargs):\n        requires_backends(self, [\"torch\"])\n"
										__lowercase       =       create_dummy_files({"torch": ["CONSTANT", "function", "FakeClass"]}       )
										self.assertEqual(dummy_files["torch"]  ,    _lowerCamelCase       )







"""simple docstring"""






import enum
import os
from hashlib import shaaaa
from typing import Optional

from .. import config
from .logging import get_logger


_lowercase							=				get_logger(__name__)

class 					__a     ( enum.Enum       ):



							'''simple docstring'''







							_lowerCamelCase					:			Tuple          =   """all_checks"""
							_lowerCamelCase					:			Optional[int]          =   """basic_checks"""
							_lowerCamelCase					:			str          =   """no_checks"""





class 					__a     ( __a       ):



							'''simple docstring'''












class 					__a     ( __a       ):



							'''simple docstring'''












class 					__a     ( __a       ):



							'''simple docstring'''












class 					__a     ( __a       ):



							'''simple docstring'''












def      lowerCAmelCase__			(		__magic_name__			,   __magic_name__			,   __magic_name__=None      )						->Union[str, Any]:
			if expected_checksums is None:
						logger.info("Unable to verify checksums."      )
						return
			if len(set(__magic_name__      ) - set(__magic_name__      )      ) > 0:
						raise ExpectedMoreDownloadedFiles(str(set(__magic_name__      ) - set(__magic_name__      )      )      )
			if len(set(__magic_name__      ) - set(__magic_name__      )      ) > 0:
						raise UnexpectedDownloadedFile(str(set(__magic_name__      ) - set(__magic_name__      )      )      )
			__lowercase       =       [url for url in expected_checksums if expected_checksums[url] != recorded_checksums[url]]
			__lowercase       =       " for " + verification_name if verification_name is not None else ""
			if len(__magic_name__      ) > 0:
						raise NonMatchingChecksumError(
						    F'''Checksums didn\'t match{for_verification_name}:\n'''
						    F'''{bad_urls}\n'''
						    "Set `verification_mode='no_checks'` to skip checksums verification and ignore this error"      )
			logger.info("All the checksums matched successfully" + for_verification_name      )

class 					__a     ( __a       ):



							'''simple docstring'''












class 					__a     ( __a       ):



							'''simple docstring'''












class 					__a     ( __a       ):



							'''simple docstring'''












class 					__a     ( __a       ):



							'''simple docstring'''












def      lowerCAmelCase__			(		__magic_name__			,   __magic_name__      )						->Any:
			if expected_splits is None:
						logger.info("Unable to verify splits sizes."      )
						return
			if len(set(__magic_name__      ) - set(__magic_name__      )      ) > 0:
						raise ExpectedMoreSplits(str(set(__magic_name__      ) - set(__magic_name__      )      )      )
			if len(set(__magic_name__      ) - set(__magic_name__      )      ) > 0:
						raise UnexpectedSplits(str(set(__magic_name__      ) - set(__magic_name__      )      )      )
			__lowercase       =       [
			    {"expected": expected_splits[name], "recorded": recorded_splits[name]}
			    for name in expected_splits
			    if expected_splits[name].num_examples != recorded_splits[name].num_examples
			]
			if len(__magic_name__      ) > 0:
						raise NonMatchingSplitsSizesError(str(__magic_name__      )      )
			logger.info("All the splits matched successfully."      )



def      lowerCAmelCase__			(		__magic_name__			,   __magic_name__ = True      )						->dict:
			if record_checksum:
						__lowercase       =       shaaaa()
						with open(__magic_name__			,   "rb"      ) as f:
									for chunk in iter(lambda: f.read(1 << 2_0      )			,   b""      ):
												m.update(__magic_name__      )
									__lowercase       =       m.hexdigest()
			else:
						__lowercase       =       None
			return {"num_bytes": os.path.getsize(__magic_name__      ), "checksum": checksum}







def      lowerCAmelCase__			(		__magic_name__      )						->List[str]:
			if dataset_size and config.IN_MEMORY_MAX_SIZE:
						return dataset_size < config.IN_MEMORY_MAX_SIZE
			else:
						return False





