



import os
import sys
import unittest


SCREAMING_SNAKE_CASE__       =      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
SCREAMING_SNAKE_CASE__       =      os.path.join(git_repo_path, '''src''', '''transformers''')

SCREAMING_SNAKE_CASE__       =      '''
{0} = None
'''

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

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


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


class      __lowerCAmelCase     (		unittest.TestCase      ):
					"""simple docstring"""






					def     _a							(     self					:       Union[str, Any]					):






								"""simple docstring"""


								A__       =    find_backend('    _import_structure["models.albert"].append("AlbertTokenizerFast")'					)
								self.assertIsNone(_snake_case					)

								A__       =    find_backend('    if not is_tokenizers_available():'					)
								self.assertEqual(_snake_case				,					'tokenizers'					)

								A__       =    find_backend('    if not is_tensorflow_text_available():'					)
								self.assertEqual(_snake_case				,					'tensorflow_text'					)

								A__       =    find_backend('    if not (is_sentencepiece_available() and is_tokenizers_available()):'					)
								self.assertEqual(_snake_case				,					'sentencepiece_and_tokenizers'					)

								A__       =    find_backend(
								    '    if not (is_sentencepiece_available() and is_tensorflow_text_available()):'					)
								self.assertEqual(_snake_case				,					'sentencepiece_and_tensorflow_text'					)

								A__       =    find_backend(
								    '    if not (is_sentencepiece_available() and is_tokenizers_available() and is_vision_available()):'					)
								self.assertEqual(_snake_case				,					'sentencepiece_and_tokenizers_and_vision'					)



					def     _a							(     self					:       str					):






								"""simple docstring"""


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

								# 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     _a							(     self					:       Union[str, Any]					):






								"""simple docstring"""


								A__       =    create_dummy_object('CONSTANT'				,					'\'torch\''					)
								self.assertEqual(_snake_case				,					'\nCONSTANT = None\n'					)

								A__       =    create_dummy_object('function'				,					'\'torch\''					)
								self.assertEqual(
								    _snake_case				,					'\ndef function(*args, **kwargs):\n    requires_backends(function, \'torch\')\n'					)

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



					def     _a							(     self					:       List[Any]					):






								"""simple docstring"""


								A__       =    '# 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'
								A__       =    create_dummy_files({'torch': ['CONSTANT', 'function', 'FakeClass']}					)
								self.assertEqual(dummy_files['torch']				,					_snake_case					)









import pytest

import datasets


# Import fixture modules as plugins
SCREAMING_SNAKE_CASE__       =      ['''tests.fixtures.files''', '''tests.fixtures.hub''', '''tests.fixtures.fsspec''']


def A						(       __UpperCamelCase ,	__UpperCamelCase					)						->      Optional[int]:
			# Mark tests as "unit" by default if not marked as "integration" (or already marked as "unit")
			for item in items:
						if any(marker in item.keywords for marker in ['integration', 'unit']					):
									continue
						item.add_marker(pytest.mark.unit					)


def A						(       __UpperCamelCase					)						->      str:
			config.addinivalue_line('markers' ,	'torchaudio_latest: mark test to run with torchaudio>=0.12'					)


@pytest.fixture(autouse=__UpperCamelCase					)
def A						(       __UpperCamelCase ,	__UpperCamelCase					)						->      Union[str, Any]:
			# test_hf_cache_home = tmp_path_factory.mktemp("cache")  # TODO: why a cache dir per test function does not work?
			A__       =    tmp_path_factory.getbasetemp() / 'cache'
			A__       =    test_hf_cache_home / 'datasets'
			A__       =    test_hf_cache_home / 'metrics'
			A__       =    test_hf_cache_home / 'modules'
			monkeypatch.setattr('datasets.config.HF_DATASETS_CACHE' ,	str(__UpperCamelCase					)					)
			monkeypatch.setattr('datasets.config.HF_METRICS_CACHE' ,	str(__UpperCamelCase					)					)
			monkeypatch.setattr('datasets.config.HF_MODULES_CACHE' ,	str(__UpperCamelCase					)					)
			A__       =    test_hf_datasets_cache / 'downloads'
			monkeypatch.setattr('datasets.config.DOWNLOADED_DATASETS_PATH' ,	str(__UpperCamelCase					)					)
			A__       =    test_hf_datasets_cache / 'downloads' / 'extracted'
			monkeypatch.setattr('datasets.config.EXTRACTED_DATASETS_PATH' ,	str(__UpperCamelCase					)					)


@pytest.fixture(autouse=__UpperCamelCase ,	scope='session'					)
def A						(       )						->      Union[str, Any]:
			datasets.disable_progress_bar()


@pytest.fixture(autouse=__UpperCamelCase					)
def A						(       __UpperCamelCase					)						->      int:
			# don't take tests into account when counting downloads
			monkeypatch.setattr('datasets.config.HF_UPDATE_DOWNLOAD_COUNTS' ,	__UpperCamelCase					)






@pytest.fixture
def A						(       __UpperCamelCase					)						->      Any:
			# Required to suppress RemovedIn20Warning when feature(s) are not compatible with SQLAlchemy 2.0
			# To be removed once SQLAlchemy 2.0 supported
			monkeypatch.setattr('sqlalchemy.util.deprecations.SILENCE_UBER_WARNING' ,	__UpperCamelCase					)




