

'''simple docstring'''
import doctest
import logging
import os
import unittest
from pathlib import Path
from typing import List, Union

import transformers
from transformers.testing_utils import require_tf, require_torch, slow


_snake_case         =  logging.getLogger()


@unittest.skip('Temporarily disable the doc tests.'  )
@require_torch
@require_tf
@slow
class        a__  (							unittest.TestCase  ):


   def 						_lowerCamelCase       (			self      ,    _UpperCamelCase      ,    _UpperCamelCase = None      ,    _UpperCamelCase = None      ,    _UpperCamelCase = None      ,    _UpperCamelCase = True      ,    ):





      """simple docstring"""





      _lowercase      :				str      					=       [file for file in os.listdir(_UpperCamelCase  ) if os.path.isfile(os.path.join(_UpperCamelCase      ,    _UpperCamelCase  )  )]

      if identifier is not None:
         _lowercase      :				str      					=       [file for file in files if identifier in file]

      if n_identifier is not None:
         if isinstance(_UpperCamelCase      ,    _UpperCamelCase  ):
            for n_ in n_identifier:
               _lowercase      :				Dict      					=       [file for file in files if n_ not in file]
         else:
            _lowercase      :				Optional[Any]      					=       [file for file in files if n_identifier not in file]

      _lowercase      :				Dict      					=       ignore_files or []
      ignore_files.append("__init__.py"  )
      _lowercase      :				List[str]      					=       [file for file in files if file not in ignore_files]

      for file in files:
         # Open all files
         print("Testing"      ,    _UpperCamelCase  )

         if only_modules:
            _lowercase      :				Optional[Any]      					=       file.split("."  )[0]
            try:
               _lowercase      :				Union[str, Any]      					=       getattr(_UpperCamelCase      ,    _UpperCamelCase  )
               _lowercase      :				Optional[int]      					=       doctest.DocTestSuite(_UpperCamelCase  )
               _lowercase      :				Tuple      					=       unittest.TextTestRunner().run(_UpperCamelCase  )
               self.assertIs(len(result.failures  )      ,    0  )
            except AttributeError:
               logger.info(f'''{module_identifier} is not a module.'''  )
         else:
            _lowercase      :				Optional[Any]      					=       doctest.testfile(str(".." / directory / file  )      ,    optionflags=doctest.ELLIPSIS  )
            self.assertIs(result.failed      ,    0  )


   def 						_lowerCamelCase       (			self  ):





      """simple docstring"""





      _lowercase      :				Tuple      					=       Path("src/transformers"  )
      _lowercase      :				str      					=       "modeling"
      _lowercase      :				Tuple      					=       [
          "modeling_ctrl.py",
          "modeling_tf_ctrl.py",
      ]
      self.analyze_directory(_UpperCamelCase      ,    identifier=_UpperCamelCase      ,    ignore_files=_UpperCamelCase  )


   def 						_lowerCamelCase       (			self  ):





      """simple docstring"""





      _lowercase      :				Optional[int]      					=       Path("src/transformers"  )
      _lowercase      :				Any      					=       "tokenization"
      self.analyze_directory(_UpperCamelCase      ,    identifier=_UpperCamelCase  )


   def 						_lowerCamelCase       (			self  ):





      """simple docstring"""





      _lowercase      :				Tuple      					=       Path("src/transformers"  )
      _lowercase      :				Optional[Any]      					=       "configuration"
      self.analyze_directory(_UpperCamelCase      ,    identifier=_UpperCamelCase  )


   def 						_lowerCamelCase       (			self  ):





      """simple docstring"""





      _lowercase      :				Union[str, Any]      					=       Path("src/transformers"  )
      _lowercase      :				List[Any]      					=       ["configuration", "modeling", "tokenization"]
      self.analyze_directory(_UpperCamelCase      ,    n_identifier=_UpperCamelCase  )






   def 						_lowerCamelCase       (			self  ):





      """simple docstring"""





      _lowercase      :				Dict      					=       Path("docs/source"  )
      _lowercase      :				int      					=       ["favicon.ico"]
      self.analyze_directory(_UpperCamelCase      ,    ignore_files=_UpperCamelCase      ,    only_modules=_UpperCamelCase  )









'''simple docstring'''
import os
import sys
import unittest


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

_snake_case         =  '\n{0} = None\n'

_snake_case         =  '\nclass {0}(metaclass=DummyObject):\n    _backends = {1}\n\n    def __init__(self, *args, **kwargs):\n        requires_backends(self, {1})\n'


_snake_case         =  '\ndef {0}(*args, **kwargs):\n    requires_backends({0}, {1})\n'


class        a__  (							unittest.TestCase  ):


   def 						_lowerCamelCase       (			self  ):





      """simple docstring"""





      _lowercase      :				Optional[int]      					=       find_backend("    _import_structure[\"models.albert\"].append(\"AlbertTokenizerFast\")"  )
      self.assertIsNone(_UpperCamelCase  )

      _lowercase      :				Dict      					=       find_backend("    if not is_tokenizers_available():"  )
      self.assertEqual(_UpperCamelCase      ,    "tokenizers"  )

      _lowercase      :				str      					=       find_backend("    if not is_tensorflow_text_available():"  )
      self.assertEqual(_UpperCamelCase      ,    "tensorflow_text"  )

      _lowercase      :				Optional[Any]      					=       find_backend("    if not (is_sentencepiece_available() and is_tokenizers_available()):"  )
      self.assertEqual(_UpperCamelCase      ,    "sentencepiece_and_tokenizers"  )

      _lowercase      :				List[str]      					=       find_backend(
          "    if not (is_sentencepiece_available() and is_tensorflow_text_available()):"  )
      self.assertEqual(_UpperCamelCase      ,    "sentencepiece_and_tensorflow_text"  )

      _lowercase      :				Optional[Any]      					=       find_backend(
          "    if not (is_sentencepiece_available() and is_tokenizers_available() and is_vision_available()):"  )
      self.assertEqual(_UpperCamelCase      ,    "sentencepiece_and_tokenizers_and_vision"  )


   def 						_lowerCamelCase       (			self  ):





      """simple docstring"""





      _lowercase      :				List[Any]      					=       read_init()
      # We don't assert on the exact list of keys to allow for smooth grow of backend-specific objects
      self.assertIn("torch"      ,    _UpperCamelCase  )
      self.assertIn("tensorflow_text"      ,    _UpperCamelCase  )
      self.assertIn("sentencepiece_and_tokenizers"      ,    _UpperCamelCase  )

      # 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 						_lowerCamelCase       (			self  ):





      """simple docstring"""





      _lowercase      :				int      					=       create_dummy_object("CONSTANT"      ,    "'torch'"  )
      self.assertEqual(_UpperCamelCase      ,    "\nCONSTANT = None\n"  )

      _lowercase      :				Optional[Any]      					=       create_dummy_object("function"      ,    "'torch'"  )
      self.assertEqual(
          _UpperCamelCase      ,    "\ndef function(*args, **kwargs):\n    requires_backends(function, 'torch')\n"  )

      _lowercase      :				Union[str, Any]      					=       "\nclass FakeClass(metaclass=DummyObject):\n    _backends = 'torch'\n\n    def __init__(self, *args, **kwargs):\n        requires_backends(self, 'torch')\n"
      _lowercase      :				List[str]      					=       create_dummy_object("FakeClass"      ,    "'torch'"  )
      self.assertEqual(_UpperCamelCase      ,    _UpperCamelCase  )






   def 						_lowerCamelCase       (			self  ):





      """simple docstring"""





      _lowercase      :				Optional[int]      					=       "# 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      :				str      					=       create_dummy_files({"torch": ["CONSTANT", "function", "FakeClass"]}  )
      self.assertEqual(dummy_files["torch"]      ,    _UpperCamelCase  )






