


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


A      = logging.getLogger()


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






  def 			_UpperCAmelCase  (					self      :					int		,						_lowercase      :					Path		,						_lowercase      :					Union[str, None] = None		,						_lowercase      :					Union[List[str], None] = None		,						_lowercase      :					Union[str, List[str], None] = None		,						_lowercase      :					bool = True		,						):




         """simple docstring"""







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

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

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

         UpperCAmelCase__										=     ignore_files or []
         ignore_files.append("__init__.py" )
         UpperCAmelCase__										=     [file for file in files if file not in ignore_files]

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

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






  def 			_UpperCAmelCase  (					self      :					List[Any] ):




         """simple docstring"""







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






  def 			_UpperCAmelCase  (					self      :					Any ):




         """simple docstring"""







         UpperCAmelCase__										=     Path("src/transformers" )
         UpperCAmelCase__										=     "tokenization"
         self.analyze_directory(_lowercase		,						identifier=_lowercase )






  def 			_UpperCAmelCase  (					self      :					int ):




         """simple docstring"""







         UpperCAmelCase__										=     Path("src/transformers" )
         UpperCAmelCase__										=     "configuration"
         self.analyze_directory(_lowercase		,						identifier=_lowercase )






  def 			_UpperCAmelCase  (					self      :					Optional[int] ):




         """simple docstring"""







         UpperCAmelCase__										=     Path("src/transformers" )
         UpperCAmelCase__										=     ["configuration", "modeling", "tokenization"]
         self.analyze_directory(_lowercase		,						n_identifier=_lowercase )






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




         """simple docstring"""







         UpperCAmelCase__										=     Path("docs/source" )
         UpperCAmelCase__										=     ["favicon.ico"]
         self.analyze_directory(_lowercase		,						ignore_files=_lowercase		,						only_modules=_lowercase )









class     lowercase__  :






  def __init__(					self      :					List[str]		,						_lowercase      :					list ):




         """simple docstring"""







         UpperCAmelCase__										=     set_counts
         UpperCAmelCase__										=     max(_lowercase )
         UpperCAmelCase__										=     len(_lowercase )
         UpperCAmelCase__										=     [1] * num_sets
         UpperCAmelCase__										=     list(range(_lowercase ) )






  def 			_UpperCAmelCase  (					self      :					Dict		,						_lowercase      :					int		,						_lowercase      :					int ):




         """simple docstring"""







         UpperCAmelCase__										=     self.get_parent(_lowercase )
         UpperCAmelCase__										=     self.get_parent(_lowercase )

         if src_parent == dst_parent:
                return False

         if self.ranks[dst_parent] >= self.ranks[src_parent]:
                self.set_counts[dst_parent] += self.set_counts[src_parent]
                UpperCAmelCase__										=     0
                UpperCAmelCase__										=     dst_parent
                if self.ranks[dst_parent] == self.ranks[src_parent]:
                       self.ranks[dst_parent] += 1
                UpperCAmelCase__										=     self.set_counts[dst_parent]
         else:
                self.set_counts[src_parent] += self.set_counts[dst_parent]
                UpperCAmelCase__										=     0
                UpperCAmelCase__										=     src_parent
                UpperCAmelCase__										=     self.set_counts[src_parent]

         UpperCAmelCase__										=     max(self.max_set		,						_lowercase )
         return True






  def 			_UpperCAmelCase  (					self      :					Optional[Any]		,						_lowercase      :					int ):




         """simple docstring"""







         if self.parents[disj_set] == disj_set:
                return disj_set
         UpperCAmelCase__										=     self.get_parent(self.parents[disj_set] )
         return self.parents[disj_set]





